diff options
author | Vedant Kumar <vsk@apple.com> | 2018-09-18 19:31:47 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2018-09-18 19:31:47 +0000 |
commit | 9b13bea61a576a41eda7c88d1628f9914bfc02b4 (patch) | |
tree | e3664f582263814503176f9237fa2a3b02b0f469 /lldb/packages/Python/lldbsuite/test/lldbtest.py | |
parent | ee679e10bbd2f9d66ecc04cac0678ffe7082f83a (diff) | |
download | bcm5719-llvm-9b13bea61a576a41eda7c88d1628f9914bfc02b4.tar.gz bcm5719-llvm-9b13bea61a576a41eda7c88d1628f9914bfc02b4.zip |
Allow use of self.filecheck in LLDB tests (c.f self.expect)
Add a "filecheck" method to the LLDB test base. This allows test authors
to pattern match command output using FileCheck, making it possible to
write stricter tests than what `self.expect` allows.
For context (motivation, examples of stricter checking, etc), see the
lldb-dev thread: "Using FileCheck in lldb inline tests".
Differential Revision: https://reviews.llvm.org/D50751
llvm-svn: 342508
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/lldbtest.py')
-rw-r--r-- | lldb/packages/Python/lldbsuite/test/lldbtest.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py index 7af97285a92..96ce825f217 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbtest.py +++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py @@ -2214,6 +2214,54 @@ class TestBase(Base): compare_string, msg=COMPLETION_MSG( str_input, p, match_strings), exe=False, patterns=[p]) + def filecheck( + self, + command, + check_file, + filecheck_options = ''): + # Run the command. + self.runCmd( + command, + msg="FileCheck'ing result of `{0}`".format(command)) + + # Get the error text if there was an error, and the regular text if not. + output = self.res.GetOutput() if self.res.Succeeded() \ + else self.res.GetError() + + # Assemble the absolute path to the check file. As a convenience for + # LLDB inline tests, assume that the check file is a relative path to + # a file within the inline test directory. + if check_file.endswith('.pyc'): + check_file = check_file[:-1] + if hasattr(self, 'test_filename'): + check_file_abs = os.path.join(os.path.dirname(self.test_filename), + check_file) + else: + check_file_abs = os.path.abspath(check_file) + + # Run FileCheck. + filecheck_bin = configuration.get_filecheck_path() + filecheck_args = [filecheck_bin, check_file_abs] + if filecheck_options: + filecheck_args.append(filecheck_options) + subproc = Popen(filecheck_args, stdin=PIPE, stdout=PIPE, stderr=PIPE) + cmd_stdout, cmd_stderr = subproc.communicate(input=output) + cmd_status = subproc.returncode + + if cmd_status != 0: + filecheck_cmd = " ".join(filecheck_args) + self.assertTrue(cmd_status == 0, """ +--- FileCheck failed (code={0}) --- +{1} + +FileCheck input: +{2} + +FileCheck output: +{3} +{4} +""".format(cmd_status, filecheck_cmd, output, cmd_stdout, cmd_stderr)) + def expect( self, str, |