diff options
author | Jonas Devlieghere <jonas@devlieghere.com> | 2022-06-08 15:57:41 -0700 |
---|---|---|
committer | Jonas Devlieghere <jonas@devlieghere.com> | 2022-06-08 16:16:38 -0700 |
commit | ce825e46743be3e402820484bef639d12deefc2a (patch) | |
tree | 0896b46e420b5ff9ea2d68337da79366e9a82b14 /lldb/packages/Python/lldbsuite/test/lldbtest.py | |
parent | 5ead1f13a2d8ca33e9e93c06acee941a857905c6 (diff) | |
download | llvm-ce825e46743be3e402820484bef639d12deefc2a.zip llvm-ce825e46743be3e402820484bef639d12deefc2a.tar.gz llvm-ce825e46743be3e402820484bef639d12deefc2a.tar.bz2 |
[lldb] Add assertState function to the API test suite
Add a function to make it easier to debug a test failure caused by an
unexpected state.
Currently, tests are using assertEqual which results in a cryptic error
message: "AssertionError: 5 != 10". Even when a test provides a message
to make it clear why a particular state is expected, you still have to
figure out which of the two was the expected state, and what the other
value corresponds to.
We have a function in lldbutil that helps you convert the state number
into a user readable string. This patch adds a wrapper around
assertEqual specifically for comparing states and reporting better error
messages.
The aforementioned error message now looks like this: "AssertionError:
stopped (5) != exited (10)". If the user provided a message, that
continues to get printed as well.
Differential revision: https://reviews.llvm.org/D127355
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/lldbtest.py')
-rw-r--r-- | lldb/packages/Python/lldbsuite/test/lldbtest.py | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py index 5c536f4..c3dc2a9 100644 --- a/lldb/packages/Python/lldbsuite/test/lldbtest.py +++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py @@ -519,9 +519,9 @@ class Base(unittest2.TestCase): # /abs/path/to/packages/group/subdir/mytest.py -> group/subdir lldb_test_src = configuration.test_src_root if not test_file.startswith(lldb_test_src): - raise Exception( - "Test file '%s' must reside within lldb_test_src " - "(which is '%s')." % (test_file, lldb_test_src)) + raise Exception( + "Test file '%s' must reside within lldb_test_src " + "(which is '%s')." % (test_file, lldb_test_src)) return os.path.dirname(os.path.relpath(test_file, start=lldb_test_src)) def TraceOn(self): @@ -2474,6 +2474,14 @@ FileCheck output: self.fail(self._formatMessage(msg, "'{}' is not success".format(error))) + """Assert two states are equal""" + def assertState(self, first, second, msg=None): + if first != second: + error = "{} ({}) != {} ({})".format( + lldbutil.state_type_to_str(first), first, + lldbutil.state_type_to_str(second), second) + self.fail(self._formatMessage(msg, error)) + def createTestTarget(self, file_path=None, msg=None, load_dependent_modules=True): """ |