diff options
| author | Martin Stump | 2020-09-12 11:12:30 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2020-10-08 11:35:42 +0200 |
| commit | c522e88afa04d66004e8d36e3a729fef90e36aaa (patch) | |
| tree | 1534432d12b7569253e11fab29fdf756aceff181 /extras/CatchAddTests.cmake | |
| parent | b1df96e7e491ab56473f869a9f4860a11fccab36 (diff) | |
| download | catch3-c522e88afa04d66004e8d36e3a729fef90e36aaa.tar.gz | |
Add REPORTER and OUTPUT_* args
Diffstat (limited to 'extras/CatchAddTests.cmake')
| -rw-r--r-- | extras/CatchAddTests.cmake | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/extras/CatchAddTests.cmake b/extras/CatchAddTests.cmake index 01c01386..82c986df 100644 --- a/extras/CatchAddTests.cmake +++ b/extras/CatchAddTests.cmake @@ -6,6 +6,10 @@ set(suffix "${TEST_SUFFIX}") set(spec ${TEST_SPEC}) set(extra_args ${TEST_EXTRA_ARGS}) set(properties ${TEST_PROPERTIES}) +set(reporter ${TEST_REPORTER}) +set(output_dir ${TEST_OUTPUT_DIR}) +set(output_prefix ${TEST_OUTPUT_PREFIX}) +set(output_suffix ${TEST_OUTPUT_SUFFIX}) set(script) set(suite) set(tests) @@ -43,6 +47,43 @@ endif() string(REPLACE "\n" ";" output "${output}") +# Run test executable to get list of available reporters +execute_process( + COMMAND ${TEST_EXECUTOR} "${TEST_EXECUTABLE}" ${spec} --list-reporters + OUTPUT_VARIABLE reporters_output + RESULT_VARIABLE reporters_result +) +if(${reporters_result} EQUAL 0) + message(WARNING + "Test executable '${TEST_EXECUTABLE}' contains no reporters!\n" + ) +elseif(${reporters_result} LESS 0) + message(FATAL_ERROR + "Error running test executable '${TEST_EXECUTABLE}':\n" + " Result: ${reporters_result}\n" + " Output: ${reporters_output}\n" + ) +endif() +string(FIND "${reporters_output}" "${reporter}" reporter_is_valid) +if(reporter AND ${reporter_is_valid} EQUAL -1) + message(FATAL_ERROR + "\"${reporter}\" is not a valid reporter!\n" + ) +endif() + +# Prepare reporter +if(reporter) + set(reporter_arg "--reporter ${reporter}") +endif() + +# Prepare output dir +if(output_dir AND NOT IS_ABSOLUTE ${output_dir}) + set(output_dir "${TEST_WORKING_DIR}/${output_dir}") + if(NOT EXISTS ${output_dir}) + file(MAKE_DIRECTORY ${output_dir}) + endif() +endif() + # Parse output foreach(line ${output}) set(test ${line}) @@ -51,6 +92,12 @@ foreach(line ${output}) foreach(char , [ ]) string(REPLACE ${char} "\\${char}" test_name ${test_name}) endforeach(char) + # ...add output dir + if(output_dir) + string(REGEX REPLACE "[^A-Za-z0-9_]" "_" test_name_clean ${test_name}) + set(output_dir_arg "--out ${output_dir}/${output_prefix}${test_name_clean}${output_suffix}") + endif() + # ...and add to script add_command(add_test "${prefix}${test}${suffix}" @@ -58,6 +105,8 @@ foreach(line ${output}) "${TEST_EXECUTABLE}" "${test_name}" ${extra_args} + "${reporter_arg}" + "${output_dir_arg}" ) add_command(set_tests_properties "${prefix}${test}${suffix}" |