Yashas
Yashas

Reputation: 1234

test for non-zero exit status using ctest/cmake

The application of interest is a compiler which returns a non-zero exit code when it encounters an error in the source. The unit tests for the compiler are composed of small snippets which intentionally triggers errors.

The function used to add a test is:

function(add_compiler_test test_name options)
  add_test(NAME ${test_name}
    COMMAND $<TARGET_FILE:pawncc> ${DEFAULT_COMPILER_OPTIONS} ${options})
  set_tests_properties(${test_name} PROPERTIES
    ENVIRONMENT PATH=$<TARGET_FILE_DIR:pawnc>)
endfunction()

This causes the test to fail when the program returns a non-zero exit code despite that being the correct behaviour.

How can the exit status of the program be tested?

Upvotes: 5

Views: 2360

Answers (1)

Tsyvarev
Tsyvarev

Reputation: 66061

If you want the test(s) to be reported as SUCCESS when it returns non-zero exit status and FAILED otherwise, set WILL_FAIL property for the test(s):

set_tests_properties(<test1> <test2> ... PROPERTIES WILL_FAIL TRUE)

Upvotes: 6

Related Questions