Page MenuHomePhabricator

[RFC] Make substrs argument to self.expect ordered by default.
ClosedPublic

Authored by JDevlieghere on Jan 30 2020, 10:34 PM.

Details

Summary

This patch is more of an RFC to change the default behavior of the substrs argument to self.expect. Currently, the elements of substrs are unordered and as long as the string appears in the output, the assertion passes. I think we can be more precise by requiring that the substrings be ordered in the way they appear. My hope is that this will make it harder to accidentally pass a check because a string appears out of order.

A possible alternative is to keep the option but have it off by default. Currently there's about 50 tests failing because of this. If we like to move forward with making this the default I plan to incrementally update tests before flipping the switch.

Diff Detail

Event Timeline

JDevlieghere created this revision.Jan 30 2020, 10:34 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 30 2020, 10:34 PM

Remove debug print

I'm very much in favor of making this more strict by default. My only problem is that the current error message is really cryptic:

AssertionError: False is not True : 'expr --show-types -- *(StgClosure*)$r14' returns expected result, got '(StgClosure) $3 = {
  (StgClosure *) &$3 = 0x0000000000215eb0
  (int) addr = 2186928
  (int) load_address = 2186928
}'

I originally did something like this for expect_expr and having something like self.assertIn(subsets, output[:start], "Untruncated output: " + output) in there helped a lot with debugging.

labath added a subscriber: labath.Jan 31 2020, 12:59 AM

I think this is great, but do we really need the extra ordered argument for this? If you just fix the order of everything beforehand, then the switch to an ordered mode can be a no-op.

FWIW I'm currently going over the failing tests and fixing them, so unless I find a test that actually needs unordered subsets I don't think having the parameter makes sense.

FWIW I'm currently going over the failing tests and fixing them, so unless I find a test that actually needs unordered subsets I don't think having the parameter makes sense.

Yep, that was my reasoning as well, if everything can be converted without falling back to the old behavior there's no need to keep the parameter.

The current behavior does make tests less dependent on the exact details of lldb's command output. If there were two independent pieces of data in a command output that you wanted to compare against, you would have to fix some tests if you ever changed the ordering in the result. It was the case that the gdb test suite hampered the evolution of the command output because it was just too much of a pain to go change the tests. For instance, you really couldn't muck with breakpoint reporting output or stop notifications; the pain of fixing up the testsuite was way too high. But in this case, the fix would just be reordering the substrings in the Python array. So though this sort of thing makes me a little uneasy, in this case I think it's fine.

Note, if there is a test that depends on the substring output not coming out in a fixed order, then I think giving that test the stink-eye is more appropriate than keeping an "ordered" flag around.

This revision was not accepted when it landed; it landed in state Needs Review.Jan 31 2020, 1:39 PM
This revision was automatically updated to reflect the committed changes.