This is an archive of the discontinued LLVM Phabricator instance.

[lldb] Add assertState function
ClosedPublic

Authored by JDevlieghere on Jun 8 2022, 3:12 PM.

Details

Summary

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 numbers was the expected state and what the actual state 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. The aforementioned error message now looks like this: "AssertionError: 5 != 10 : stopped != exited". If the user provided a message, that gets displayed as well.

Diff Detail

Event Timeline

JDevlieghere created this revision.Jun 8 2022, 3:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 8 2022, 3:12 PM
JDevlieghere requested review of this revision.Jun 8 2022, 3:12 PM
mib added a comment.Jun 8 2022, 3:41 PM

Pretty cool but it would be nice to have the following formatting: "AssertionError: stopped (5) != exited (10) : message" ... I feel like it's easier to read this way

Implement Ismail's suggestion:

AssertionError: stopped (5) != exited (10) : Got exit event
mib accepted this revision.Jun 8 2022, 3:57 PM

Awesome! Thanks!

This revision is now accepted and ready to land.Jun 8 2022, 3:57 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJun 8 2022, 4:17 PM

nice, I've wanted this too.