diff options
Diffstat (limited to 'tests/cli/llvmtestcase.py')
-rw-r--r-- | tests/cli/llvmtestcase.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tests/cli/llvmtestcase.py b/tests/cli/llvmtestcase.py index 0f29ce6..f895c49 100644 --- a/tests/cli/llvmtestcase.py +++ b/tests/cli/llvmtestcase.py @@ -32,6 +32,30 @@ def debug(test): return wrapper +def require_command_arg(requiredArg): + """ + Decorator that simplifies writing CLI tests that check that 'requiredArg' is + in fact required (i.e. that the command that we're testing will blow up if + we don't pass it the required argument). + + Use this to decorate test functions, e.g: + + @require_command_arg("--my-required-arg") + def test_my_required_arg_is_compulsory(self): + run_command_without_my_required_arg() + """ + def decorate(test): + def wrapper(*args, **kwargs): + self = args[0] + with self.assertRaises(subprocess.CalledProcessError) as context: + test(*args, **kwargs) + + self.assertRegex(str(context.exception.output), + "(.*\n)*the following arguments are required: {}(.*\n)*".format(requiredArg)) + return wrapper + return decorate + + class LLVMTestCase(unittest.TestCase): python = "python3" script = os.path.join("scripts", "llvm.py") |