I want to test with ctest, that an executable fails (e.g. with abort()).
How can i specify this in ctest?
How can I set ctestto exlicitly exprect an abort (or SEGV or …)?
:~/cmake_test/Build$ ninja && ctest
[4/4] Linking CXX executable normal
Test project /home/xxx/cmake_test/Build
Start 1: normal
1/2 Test #1: normal ........................... Passed 0.00 sec
Start 2: abort
2/2 Test #2: abort ............................Child aborted***Exception: 0.00 sec
50% tests passed, 1 tests failed out of 2
Total Test time (real) = 0.00 sec
The following tests FAILED:
2 - abort (Child aborted)
Errors while running CTest
Example:
CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(cmake_test)
enable_testing()
add_executable(normal normal.cpp)
add_executable(abort abort.cpp)
add_test(NAME normal COMMAND normal)
add_test(NAME abort COMMAND abort)
set_tests_properties(abort PROPERTIES WILL_FAIL True) # does not work on abort()
normal.cpp
int main()
{
return 0;
}
abort.cpp
#include <cstdlib>
int main()
{
abort();
return 0;
}