Reputation: 20768
I'm adding tests to my project and all the tests have some prerequisites so I add a precheck test which all other tests depend on. If the precheck fails then I'd like the other tests to stop immediately.
add_test(
NAME precheck
COMMAND false
)
add_test(
NAME test-1
COMMAND true
)
add_test(
NAME test-2
COMMAND true
)
set_tests_properties(
test-1 test-2
PROPERTIES
DEPENDS precheck
)
But seems like the DEPENDS
property only impact the order of tests:
$ make test
Running tests...
Test project /root/ibvq/frkcrpg/b
Start 1: precheck
1/3 Test #1: precheck .........................***Failed 0.00 sec
Start 2: test-1
2/3 Test #2: test-1 ........................... Passed 0.00 sec
Start 3: test-2
3/3 Test #3: test-2 ........................... Passed 0.00 sec
67% tests passed, 1 tests failed out of 3
Total Test time (real) = 0.02 sec
The following tests FAILED:
1 - precheck (Failed)
Errors while running CTest
Makefile:83: recipe for target 'test' failed
make: *** [test] Error 8
So how can I make the failed precheck stop other tests?
Upvotes: 1
Views: 693
Reputation: 65891
If you are using CMake version 3.7 or later, you can use the test fixture related properties.
For earlier versions of CMake, have your precheck
test create a dummy file on success that your other tests depend on by setting the REQUIRED_FILES property.
Upvotes: 3