-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add should_error kwarg to test() #13559
base: master
Are you sure you want to change the base?
Conversation
f13224d
to
d63ea45
Compare
should_fail is equivalent to TAP's "todo" status. How does should_error map to TAP? |
If should_fail maps to "todo", then I guess I've been abusing how should_fail works. I think should_error would map to an expected 'Bail out!', which is a test ended due to a fatal error. I guess it can be interpreted as "todo" as well. My use case is that I have tests I intentionally inject with failures/errors and I expect the test to fail to see if the failure is caught. In which case, "failing" actually means pass, in the sense that Meson returns 0, not failing the CI job. should_fail does this for failures, so Meson returns 0, but there is no way to do this currently for errors. Example CI run with this PR's content: |
Semantically, a should_fail results in meson logging the test result as an "Expected Fail:" instead of an "Ok:", and if the test starts passing it is logged as an "Unexpected Pass:", again instead of an actual "Ok:". The reason there are 3 different statuses for this is because the "Expected Fail" list is a list of things you should be reminded to take care of at some point and "Unexpected Pass:" is stuff you have fixed and need to remove the todo note so that you start checking it again. ... On a practical level, "Expected Fail" doesn't result in a test results failure and "Unexpected Pass" does, which means setting I am discontented with the confusion this causes. I would like to see Also, probably, |
6b62894
to
93a175b
Compare
@eli-schwartz Is the current commit what you had in mind? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The general thrust of this commit is indeed matching the high-level vision I imagined.
Some implementation notes below.
if kwargs['should_fail'] is not None and kwargs['expected_fail'] is not None: | ||
raise InvalidArguments('Tried to use both \'should_fail\' and \'expected_fail\'') | ||
elif kwargs['should_fail'] is not None: | ||
mlog.deprecation('Use expected_fail instead of should_fail.', location=node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use FeatureDeprecated.single_use
here, so we can gate the deprecation warning based on the project's minimum supported meson_version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually hold on, this is already covered in the KwargInfo handling via
deprecated='1.6.0', deprecated_message='Use expected_fail instead of should_fail'),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed it, I thought KwargInfo handling didn't give exact location at first
kwargs['expected_fail'] = kwargs['should_fail'] | ||
elif kwargs['expected_fail'] is None: | ||
kwargs['expected_fail'] = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would set a new expected_fail = kwargs['should_fail']
variable here to avoid mutating the inputs of the current function.
/cc @dcbaker
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's probably a good idea, done :)
mesonbuild/mtest.py
Outdated
@@ -1038,6 +1039,8 @@ class TestRunExitCode(TestRun): | |||
def complete(self) -> None: | |||
if self.res != TestResult.RUNNING: | |||
pass | |||
elif self.returncode == self.success_returncode: | |||
self.res = TestResult.OK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given below we handle the else
case as such:
else:
self.res = TestResult.FAIL if bool(self.returncode) else TestResult.OK
Seems like a TestResult.OK is emitted for either a returncode of 0, or a returncode of an overridden success_returncode. Is this intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's an oversight on my part, corrected it and I added a test for this
884c54f
to
0ede368
Compare
39082ff
to
b591ad3
Compare
@@ -0,0 +1,3 @@ | |||
## Deprecate `should_fail` and rename it to `expected_error`, also introduce `success_returncode` | |||
|
|||
In 1.8.0 `should_fail` has been renamed to `expected_error`. Before 1.8.0, there was no way to positively test a command/binary returning error/non-zero return code, `success_returncode` has been introduced to achieve this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected_error should be expected_fail here. Also success_exitcode might be more consistent with protocol: 'exitcode'
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe expected_exitcode?
Fixes #10479 |
32a5db7
to
eed858b
Compare
…itcode for exitcode tests
eed858b
to
103f5e3
Compare
This PR adds a new kwarg named 'should_error' to the test call that is similar to should_fail. It behaves the same, the only difference is that it expects error instead of fail.
The use case is that I am running some some tests where I purposefully inject failures that end up as 'Bail out!' with TAP, so the test result is expected to be error.