SKIP_RETURN_CODE — CMake 4.2.6 Documentation

# SKIP_RETURN_CODE

Return code to mark a test as skipped.

Sometimes only a test itself can determine if all requirements for the test are met. If such a situation should not be considered a hard failure a return code of the process can be specified that will mark the test as `Not Run` if it is encountered. Valid values are in the range of 0 to 255, inclusive.

Tests that exceed the timeout specified by `TIMEOUT` still fail regardless of `SKIP_RETURN_CODE`. System-level test failures including segmentation faults, signal abort, or heap errors may fail the test even if the return code matches.

    # cmake (1) defines this to return code 1
    add_test(NAME r1 COMMAND ${CMAKE_COMMAND} -E false)

    set_tests_properties(r1 PROPERTIES SKIP_RETURN_CODE 1)

To run a test that may have a system-level failure, but still skip if `SKIP_RETURN_CODE` matches, use a CMake command to wrap the executable run. Note that this will prevent automatic handling of the `CROSSCOMPILING_EMULATOR` and `TEST_LAUNCHER` target property.

    add_executable(main main.c)

    # cmake -E env <command> returns 1 if the command fails in any way
    add_test(NAME sigabrt COMMAND ${CMAKE_COMMAND} -E env $<TARGET_FILE:main>)

    set_property(TEST sigabrt PROPERTY SKIP_RETURN_CODE 1)

    #include <signal.h>

    int main(void){ raise(SIGABRT); return 0; }

To handle multiple types of cases that may need to be skipped, consider the `SKIP_REGULAR_EXPRESSION` property.