I want to test that an app is both exiting with a non-zero code AND outputting a particular string. I set the properties like this:
set_tests_properties(
myapp-test-foobar
PROPERTIES
WILL_FAIL TRUE
FAIL_REGULAR_EXPRESSION "^Usage: myapp"
)
But the test passes even if the app's exit code is 0. Although WILL_FAIL
is necessary, otherwise the test will fail when the FRE is matched, the exit code is ignored. I searched the cmake docs for an answer to no avail.
EDIT: It turns out that ctest (I'm using v3.19.2) does not check the exit code if either PASS_REGULAR_EXPRESSION or FAIL_REGULAR_EXPRESSION is set. The pass or fail condition is met solely by the RE matching.
A nasty bug has escaped into the wild in one of my apps because of this.
EDIT: The answer suggested in comments below is for handling an app that aborts, i.e. crashes, on the error condition being tested and so is different from my case. Please see my comment below for further reasoning and solution.