diff options
author | Zack Galbreath <zack.galbreath@kitware.com> | 2021-04-22 23:38:43 (GMT) |
---|---|---|
committer | Zack Galbreath <zack.galbreath@kitware.com> | 2021-04-26 12:55:22 (GMT) |
commit | 25bf514447501963a31934b5b03c65aeb53a351f (patch) | |
tree | 9a8392707d6376d588da56100a9ab214abd2ef43 /Tests/RunCMake | |
parent | eeb771e4d6b9a1127a0818a211cafb722a2dc387 (diff) | |
download | CMake-25bf514447501963a31934b5b03c65aeb53a351f.zip CMake-25bf514447501963a31934b5b03c65aeb53a351f.tar.gz CMake-25bf514447501963a31934b5b03c65aeb53a351f.tar.bz2 |
ctest: Add support for writing test results in JUnit XML format
Addresses #18654
Diffstat (limited to 'Tests/RunCMake')
6 files changed, 84 insertions, 0 deletions
diff --git a/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake b/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake index 2f4d731..afec011 100644 --- a/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake +++ b/Tests/RunCMake/CTestCommandLine/RunCMakeTest.cmake @@ -397,3 +397,22 @@ function(run_testDir) run_cmake_command(testDir ${CMAKE_CTEST_COMMAND} --test-dir "${RunCMake_TEST_BINARY_DIR}/sub") endfunction() run_testDir() + +# Test --output-junit +function(run_output_junit) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/output-junit) + set(RunCMake_TEST_NO_CLEAN 1) + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + file(WRITE "${RunCMake_TEST_BINARY_DIR}/CTestTestfile.cmake" " +add_test(test1 \"${CMAKE_COMMAND}\" -E false) +add_test(test2 \"${CMAKE_COMMAND}\" -E echo \"hello world\") +add_test(test3 \"${CMAKE_COMMAND}\" -E true) +set_tests_properties(test3 PROPERTIES DISABLED \"ON\") +add_test(test4 \"${CMAKE_COMMAND}/doesnt_exist\") +add_test(test5 \"${CMAKE_COMMAND}\" -E echo \"please skip\") +set_tests_properties(test5 PROPERTIES SKIP_REGULAR_EXPRESSION \"please skip\") +") + run_cmake_command(output-junit ${CMAKE_CTEST_COMMAND} --output-junit "${RunCMake_TEST_BINARY_DIR}/junit.xml") +endfunction() +run_output_junit() diff --git a/Tests/RunCMake/CTestCommandLine/output-junit-check.cmake b/Tests/RunCMake/CTestCommandLine/output-junit-check.cmake new file mode 100644 index 0000000..b270fdf --- /dev/null +++ b/Tests/RunCMake/CTestCommandLine/output-junit-check.cmake @@ -0,0 +1,36 @@ +file(GLOB junit_xml_file "${RunCMake_TEST_BINARY_DIR}/junit.xml") +if(junit_xml_file) + file(READ "${junit_xml_file}" junit_xml LIMIT 4096) + if(NOT "${junit_xml}" MATCHES "tests=\"5\"") + set(RunCMake_TEST_FAILED "tests=\"5\" not found when expected") + endif() + if(NOT "${junit_xml}" MATCHES "failures=\"1\"") + set(RunCMake_TEST_FAILED "failures=\"1\" not found when expected") + endif() + if(NOT "${junit_xml}" MATCHES "disabled=\"1\"") + set(RunCMake_TEST_FAILED "disabled=\"1\" not found when expected") + endif() + if(NOT "${junit_xml}" MATCHES "skipped=\"2\"") + set(RunCMake_TEST_FAILED "skipped=\"2\" not found when expected") + endif() + if(NOT "${junit_xml}" MATCHES "<system-out>hello world") + set(RunCMake_TEST_FAILED "<system-out>hello world not found when expected") + endif() + if(NOT "${junit_xml}" MATCHES "<system-out>Disabled") + set(RunCMake_TEST_FAILED "<system-out>Disabled not found when expected") + endif() + if(NOT "${junit_xml}" MATCHES "<skipped message=\"Unable to find executable\"/>") + set(RunCMake_TEST_FAILED "<skipped message=\"Unable to find executable\"/> not found when expected") + endif() + if(NOT "${junit_xml}" MATCHES "<system-out>Unable to find executable:") + set(RunCMake_TEST_FAILED "<system-out>Unable to find executable: not found when expected") + endif() + if(NOT "${junit_xml}" MATCHES "<skipped message=\"SKIP_REGULAR_EXPRESSION_MATCHED\"/>") + set(RunCMake_TEST_FAILED "<skipped message=\"SKIP_REGULAR_EXPRESSION_MATCHED\"/> not found when expected") + endif() + if(NOT "${junit_xml}" MATCHES "<system-out>please skip") + set(RunCMake_TEST_FAILED "<system-out>please skip not found when expected") + endif() +else() + set(RunCMake_TEST_FAILED "junit.xml not found") +endif() diff --git a/Tests/RunCMake/CTestCommandLine/output-junit-result.txt b/Tests/RunCMake/CTestCommandLine/output-junit-result.txt new file mode 100644 index 0000000..45a4fb7 --- /dev/null +++ b/Tests/RunCMake/CTestCommandLine/output-junit-result.txt @@ -0,0 +1 @@ +8 diff --git a/Tests/RunCMake/CTestCommandLine/output-junit-stderr.txt b/Tests/RunCMake/CTestCommandLine/output-junit-stderr.txt new file mode 100644 index 0000000..ce30dc8 --- /dev/null +++ b/Tests/RunCMake/CTestCommandLine/output-junit-stderr.txt @@ -0,0 +1 @@ +Unable to find executable: .*doesnt_exist diff --git a/Tests/RunCMake/ctest_test/OutputJUnit-check.cmake b/Tests/RunCMake/ctest_test/OutputJUnit-check.cmake new file mode 100644 index 0000000..00310a4 --- /dev/null +++ b/Tests/RunCMake/ctest_test/OutputJUnit-check.cmake @@ -0,0 +1,24 @@ +file(GLOB junit_xml_file "${RunCMake_TEST_BINARY_DIR}/junit.xml") +if(junit_xml_file) + file(READ "${junit_xml_file}" junit_xml LIMIT 4096) + if(NOT "${junit_xml}" MATCHES "tests=\"1\"") + set(RunCMake_TEST_FAILED "tests=\"1\" not found when expected") + endif() + if(NOT "${junit_xml}" MATCHES "failures=\"0\"") + set(RunCMake_TEST_FAILED "failures=\"0\" not found when expected") + endif() + if(NOT "${junit_xml}" MATCHES "disabled=\"0\"") + set(RunCMake_TEST_FAILED "disabled=\"0\" not found when expected") + endif() + if(NOT "${junit_xml}" MATCHES "skipped=\"0\"") + set(RunCMake_TEST_FAILED "skipped=\"0\" not found when expected") + endif() + if(NOT "${junit_xml}" MATCHES "<testcase name=\"RunCMakeVersion\" classname=\"RunCMakeVersion\"") + set(RunCMake_TEST_FAILED "RunCMakeVersion not found when expected") + endif() + if(NOT "${junit_xml}" MATCHES "<system-out>cmake version") + set(RunCMake_TEST_FAILED "<system-out>cmake version not found when expected") + endif() +else() + set(RunCMake_TEST_FAILED "junit.xml not found") +endif() diff --git a/Tests/RunCMake/ctest_test/RunCMakeTest.cmake b/Tests/RunCMake/ctest_test/RunCMakeTest.cmake index 8cf6a61..901ac11 100644 --- a/Tests/RunCMake/ctest_test/RunCMakeTest.cmake +++ b/Tests/RunCMake/ctest_test/RunCMakeTest.cmake @@ -146,3 +146,6 @@ set_property(TEST RunCMakeVersion PROPERTY ENVIRONMENT "ENV1=env1;ENV2=env2") run_ctest(TestEnvironment) endfunction() run_environment() + +# test for OUTPUT_JUNIT +run_ctest_test(OutputJUnit OUTPUT_JUNIT junit.xml REPEAT UNTIL_FAIL:2) |