diff options
Diffstat (limited to 'Tests/RunCMake/GoogleTest')
31 files changed, 524 insertions, 0 deletions
diff --git a/Tests/RunCMake/GoogleTest/CMakeLists.txt b/Tests/RunCMake/GoogleTest/CMakeLists.txt new file mode 100644 index 0000000..dc92486 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.6) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-configuration-debug-stdout.txt b/Tests/RunCMake/GoogleTest/GoogleTest-configuration-debug-stdout.txt new file mode 100644 index 0000000..1f5d1a5 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-configuration-debug-stdout.txt @@ -0,0 +1,5 @@ +Test project .*GoogleTest-discovery-multi-config +[ \t]*Test #[0-9]+: configuration\.case_release \(Disabled\) +[ \t]*Test #[0-9]+: configuration\.case_debug ++ +Total Tests: 2 diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-configuration-release-stdout.txt b/Tests/RunCMake/GoogleTest/GoogleTest-configuration-release-stdout.txt new file mode 100644 index 0000000..4f91664 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-configuration-release-stdout.txt @@ -0,0 +1,5 @@ +Test project .*GoogleTest-discovery-multi-config +[ \t]*Test #[0-9]+: configuration\.case_release +[ \t]*Test #[0-9]+: configuration\.case_debug \(Disabled\) ++ +Total Tests: 2 diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-discovery-POST_BUILD-timeout-build-result.txt b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-POST_BUILD-timeout-build-result.txt new file mode 100644 index 0000000..d197c91 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-POST_BUILD-timeout-build-result.txt @@ -0,0 +1 @@ +[^0] diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-discovery-POST_BUILD-timeout-build-stdout.txt b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-POST_BUILD-timeout-build-stdout.txt new file mode 100644 index 0000000..3a6572c --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-POST_BUILD-timeout-build-stdout.txt @@ -0,0 +1,7 @@ +( *|[0-9]+>)CMake Error at .*GoogleTestAddTests.cmake:[0-9]+ \(message\): +( *|[0-9]+>) Error running test executable. +?( *|[0-9]+>) +( *|[0-9]+>) Path: '.*discovery_timeout_test(\.exe)?' +( *|[0-9]+>) Result: Process terminated due to timeout +( *|[0-9]+>) Output: +( *|[0-9]+>) + diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-discovery-POST_BUILD-timeout-test-result.txt b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-POST_BUILD-timeout-test-result.txt new file mode 100644 index 0000000..d197c91 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-POST_BUILD-timeout-test-result.txt @@ -0,0 +1 @@ +[^0] diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-discovery-POST_BUILD-timeout-test-stderr.txt b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-POST_BUILD-timeout-test-stderr.txt new file mode 100644 index 0000000..f6be939 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-POST_BUILD-timeout-test-stderr.txt @@ -0,0 +1,2 @@ +Unable to find executable: discovery_timeout_test_NOT_BUILT +Errors while running CTest diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-discovery-POST_BUILD-timeout-test-stdout.txt b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-POST_BUILD-timeout-test-stdout.txt new file mode 100644 index 0000000..d9de3f8 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-POST_BUILD-timeout-test-stdout.txt @@ -0,0 +1,18 @@ +Test project .*GoogleTest-discovery-timeout +[ \t]*Start [0-9]+: discovery_timeout_test_NOT_BUILT +Could not find executable discovery_timeout_test_NOT_BUILT +Looked in the following places: +discovery_timeout_test_NOT_BUILT +discovery_timeout_test_NOT_BUILT(\.exe)? +Debug/discovery_timeout_test_NOT_BUILT +Debug/discovery_timeout_test_NOT_BUILT(\.exe)? +Debug/discovery_timeout_test_NOT_BUILT +Debug/discovery_timeout_test_NOT_BUILT(\.exe)? +[^\n]+discovery_timeout_test_NOT_BUILT +\.+\*\*\*Not Run +[0-9.]+ sec ++ +0% tests passed, 1 tests failed out of 1 ++ +Total Test time \(real\) = +[0-9.]+ sec ++ +The following tests FAILED: +[^\n]+discovery_timeout_test_NOT_BUILT \(Not Run\) diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-discovery-PRE_TEST-timeout-test-stderr.txt b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-PRE_TEST-timeout-test-stderr.txt new file mode 100644 index 0000000..75afe4a --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-PRE_TEST-timeout-test-stderr.txt @@ -0,0 +1,8 @@ +CMake Error at .*GoogleTestAddTests.cmake:[0-9]+ \(message\): +[ \t]*Error running test executable. ++ +[ \t]*Path: '.*discovery_timeout_test(\.exe)?' +[ \t]*Result: Process terminated due to timeout +[ \t]*Output: +[ \t]*timeout. +[ \t]*case diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-discovery-PRE_TEST-timeout-test-stdout.txt b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-PRE_TEST-timeout-test-stdout.txt new file mode 100644 index 0000000..d65061f --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-discovery-PRE_TEST-timeout-test-stdout.txt @@ -0,0 +1 @@ +Test project .*GoogleTest-discovery-timeout diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-property-timeout1-result.txt b/Tests/RunCMake/GoogleTest/GoogleTest-property-timeout1-result.txt new file mode 100644 index 0000000..d197c91 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-property-timeout1-result.txt @@ -0,0 +1 @@ +[^0] diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-property-timeout1-stderr.txt b/Tests/RunCMake/GoogleTest/GoogleTest-property-timeout1-stderr.txt new file mode 100644 index 0000000..ba4235d --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-property-timeout1-stderr.txt @@ -0,0 +1 @@ +Errors while running CTest diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-property-timeout1-stdout.txt b/Tests/RunCMake/GoogleTest/GoogleTest-property-timeout1-stdout.txt new file mode 100644 index 0000000..0dda49d --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-property-timeout1-stdout.txt @@ -0,0 +1,10 @@ +Test project .*GoogleTest-build +[ \t]*Start [0-9]+: property_timeout.case_no_discovery +[^\n]+property_timeout.case_no_discovery +\.+\*\*\*Timeout +[0-9.]+ sec ++ +0% tests passed, 1 tests failed out of 1 ++ +Total Test time \(real\) = +[0-9.]+ sec ++ +The following tests FAILED: +[^\n]*property_timeout.case_no_discovery \(Timeout\) diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-property-timeout2-result.txt b/Tests/RunCMake/GoogleTest/GoogleTest-property-timeout2-result.txt new file mode 100644 index 0000000..d197c91 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-property-timeout2-result.txt @@ -0,0 +1 @@ +[^0] diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-property-timeout2-stderr.txt b/Tests/RunCMake/GoogleTest/GoogleTest-property-timeout2-stderr.txt new file mode 100644 index 0000000..ba4235d --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-property-timeout2-stderr.txt @@ -0,0 +1 @@ +Errors while running CTest diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-property-timeout2-stdout.txt b/Tests/RunCMake/GoogleTest/GoogleTest-property-timeout2-stdout.txt new file mode 100644 index 0000000..72cea55 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-property-timeout2-stdout.txt @@ -0,0 +1,10 @@ +Test project .*GoogleTest-build +[ \t]*Start [0-9]+: property_timeout.case_with_discovery +[^\n]+property_timeout.case_with_discovery +\.+\*\*\*Timeout +[0-9.]+ sec ++ +0% tests passed, 1 tests failed out of 1 ++ +Total Test time \(real\) = +[0-9.]+ sec ++ +The following tests FAILED: +[^\n]*property_timeout.case_with_discovery \(Timeout\) diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-test-missing-result.txt b/Tests/RunCMake/GoogleTest/GoogleTest-test-missing-result.txt new file mode 100644 index 0000000..d197c91 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-test-missing-result.txt @@ -0,0 +1 @@ +[^0] diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-test-missing-stderr.txt b/Tests/RunCMake/GoogleTest/GoogleTest-test-missing-stderr.txt new file mode 100644 index 0000000..a4cc971 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-test-missing-stderr.txt @@ -0,0 +1,2 @@ +Unable to find executable: no_tests_defined_NOT_BUILT +Errors while running CTest diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-test1-stdout.txt b/Tests/RunCMake/GoogleTest/GoogleTest-test1-stdout.txt new file mode 100644 index 0000000..5f7753d --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-test1-stdout.txt @@ -0,0 +1,25 @@ +Test project .* + Start 1: TEST:basic\.case_foo!1 +1/8 Test #1: TEST:basic\.case_foo!1 \.+ +Passed +[0-9.]+ sec + Start 2: TEST:basic\.case_bar!1 +2/8 Test #2: TEST:basic\.case_bar!1 \.+ +Passed +[0-9.]+ sec + Start 3: TEST:basic\.disabled_case!1 +3/8 Test #3: TEST:basic\.disabled_case!1 \.+\*+Not Run \(Disabled\) +[0-9.]+ sec + Start 4: TEST:disabled\.case!1 +4/8 Test #4: TEST:disabled\.case!1 \.+\*+Not Run \(Disabled\) +[0-9.]+ sec + Start 5: TEST:typed/short\.case!1 +5/8 Test #5: TEST:typed/short\.case!1 \.+ +Passed +[0-9.]+ sec + Start 6: TEST:typed/float\.case!1 +6/8 Test #6: TEST:typed/float\.case!1 \.+ +Passed +[0-9.]+ sec + Start 7: TEST:value/test\.case/1!1 +7/8 Test #7: TEST:value/test\.case/1!1 \.+ +Passed +[0-9.]+ sec + Start 8: TEST:value/test\.case/"foo"!1 +8/8 Test #8: TEST:value/test\.case/"foo"!1 \.+ +Passed +[0-9.]+ sec + +100% tests passed, 0 tests failed out of 6 + +Total Test time \(real\) = +[0-9.]+ sec + +The following tests did not run: +.*3 - TEST:basic\.disabled_case!1 \(Disabled\) +.*4 - TEST:disabled\.case!1 \(Disabled\) diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-test2-stdout.txt b/Tests/RunCMake/GoogleTest/GoogleTest-test2-stdout.txt new file mode 100644 index 0000000..960c0b9 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest-test2-stdout.txt @@ -0,0 +1,25 @@ +Test project .* + Start 9: TEST:basic\.case_foo!2 +1/8 Test #9: TEST:basic\.case_foo!2 \.+ +Passed +[0-9.]+ sec + Start 10: TEST:basic\.case_bar!2 +2/8 Test #10: TEST:basic\.case_bar!2 \.+ +Passed +[0-9.]+ sec + Start 11: TEST:basic\.disabled_case!2 +3/8 Test #11: TEST:basic\.disabled_case!2 \.+\*+Not Run \(Disabled\) +[0-9.]+ sec + Start 12: TEST:disabled\.case!2 +4/8 Test #12: TEST:disabled\.case!2 \.+\*+Not Run \(Disabled\) +[0-9.]+ sec + Start 13: TEST:typed/short\.case!2 +5/8 Test #13: TEST:typed/short\.case!2 \.+ +Passed +[0-9.]+ sec + Start 14: TEST:typed/float\.case!2 +6/8 Test #14: TEST:typed/float\.case!2 \.+ +Passed +[0-9.]+ sec + Start 15: TEST:value/test\.case/1!2 +7/8 Test #15: TEST:value/test\.case/1!2 \.+ +Passed +[0-9.]+ sec + Start 16: TEST:value/test\.case/"foo"!2 +8/8 Test #16: TEST:value/test\.case/"foo"!2 \.+ +Passed +[0-9.]+ sec + +100% tests passed, 0 tests failed out of 6 + +Total Test time \(real\) = +[0-9.]+ sec + +The following tests did not run: +.*11 - TEST:basic\.disabled_case!2 \(Disabled\) +.*12 - TEST:disabled\.case!2 \(Disabled\) diff --git a/Tests/RunCMake/GoogleTest/GoogleTest.cmake b/Tests/RunCMake/GoogleTest/GoogleTest.cmake new file mode 100644 index 0000000..4bc6b9d --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTest.cmake @@ -0,0 +1,51 @@ +project(test_include_dirs) +include(CTest) +include(GoogleTest) + +enable_testing() + +add_executable(fake_gtest fake_gtest.cpp) + +gtest_discover_tests( + fake_gtest + TEST_PREFIX TEST: + TEST_SUFFIX !1 + EXTRA_ARGS how now "\"brown\" cow" + PROPERTIES LABELS TEST1 +) + +gtest_discover_tests( + fake_gtest + TEST_PREFIX TEST: + TEST_SUFFIX !2 + EXTRA_ARGS how now "\"brown\" cow" + PROPERTIES LABELS TEST2 +) + +add_executable(no_tests_defined no_tests_defined.cpp) + +gtest_discover_tests( + no_tests_defined +) + +# Note change in behavior of TIMEOUT keyword in 3.10.3 +# where it was renamed to DISCOVERY_TIMEOUT to prevent it +# from shadowing the TIMEOUT test property. Verify the +# 3.10.3 and later behavior, old behavior added in 3.10.1 +# is not supported. +add_executable(property_timeout_test timeout_test.cpp) +target_compile_definitions(property_timeout_test PRIVATE sleepSec=10) + +gtest_discover_tests( + property_timeout_test + TEST_PREFIX property_ + TEST_SUFFIX _no_discovery + PROPERTIES TIMEOUT 2 +) +gtest_discover_tests( + property_timeout_test + TEST_PREFIX property_ + TEST_SUFFIX _with_discovery + DISCOVERY_TIMEOUT 20 + PROPERTIES TIMEOUT 2 +) diff --git a/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryMultiConfig.cmake b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryMultiConfig.cmake new file mode 100644 index 0000000..1919dc1 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryMultiConfig.cmake @@ -0,0 +1,14 @@ +project(test_include_dirs) +include(CTest) +include(GoogleTest) + +enable_testing() + +add_executable(configuration_gtest configuration_gtest.cpp) +target_compile_definitions(configuration_gtest PRIVATE $<$<CONFIG:Debug>:DEBUG=1>) + +gtest_discover_tests( + configuration_gtest + PROPERTIES LABELS CONFIG + DISCOVERY_MODE PRE_TEST +) diff --git a/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTimeout.cmake b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTimeout.cmake new file mode 100644 index 0000000..7398faf --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTestDiscoveryTimeout.cmake @@ -0,0 +1,14 @@ +project(test_include_dirs) +include(CTest) +include(GoogleTest) + +enable_testing() + +add_executable(discovery_timeout_test timeout_test.cpp) +target_compile_definitions(discovery_timeout_test PRIVATE discoverySleepSec=10) +gtest_discover_tests( + discovery_timeout_test + TEST_PREFIX discovery_ + DISCOVERY_TIMEOUT 2 + DISCOVERY_MODE ${DISCOVERY_MODE} +) diff --git a/Tests/RunCMake/GoogleTest/GoogleTestXML-result-check.cmake b/Tests/RunCMake/GoogleTest/GoogleTestXML-result-check.cmake new file mode 100644 index 0000000..3bfdac3 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTestXML-result-check.cmake @@ -0,0 +1,4 @@ +set(RESULT_FILE "${RunCMake_TEST_BINARY_DIR}/GoogleTestXML.Foo.xml") +if(NOT EXISTS ${RESULT_FILE}) + set(RunCMake_TEST_FAILED "Result XML file ${RESULT_FILE} was not created") +endif() diff --git a/Tests/RunCMake/GoogleTest/GoogleTestXML.cmake b/Tests/RunCMake/GoogleTest/GoogleTestXML.cmake new file mode 100644 index 0000000..c86de63 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/GoogleTestXML.cmake @@ -0,0 +1,11 @@ +project(test_include_dirs) +include(CTest) +include(GoogleTest) + +enable_testing() + +add_executable(xml_output xml_output.cpp) +gtest_discover_tests( + xml_output + XML_OUTPUT_DIR ${CMAKE_BINARY_DIR} +) diff --git a/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake b/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake new file mode 100644 index 0000000..6b9d458 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake @@ -0,0 +1,168 @@ +include(RunCMake) + +function(run_GoogleTest DISCOVERY_MODE) + # Use a single build tree for a few tests without cleaning. + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-build) + set(RunCMake_TEST_NO_CLEAN 1) + if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG) + set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug) + endif() + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + + run_cmake_with_options(GoogleTest -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE}) + + run_cmake_command(GoogleTest-build + ${CMAKE_COMMAND} + --build . + --config Debug + --target fake_gtest + ) + + run_cmake_command(GoogleTest-property-timeout-exe + ${CMAKE_COMMAND} + --build . + --config Debug + --target property_timeout_test + ) + + run_cmake_command(GoogleTest-test1 + ${CMAKE_CTEST_COMMAND} + -C Debug + -L TEST1 + --no-label-summary + ) + + run_cmake_command(GoogleTest-test2 + ${CMAKE_CTEST_COMMAND} + -C Debug + -L TEST2 + --no-label-summary + ) + + run_cmake_command(GoogleTest-test-missing + ${CMAKE_CTEST_COMMAND} + -C Debug + -R no_tests_defined + --no-label-summary + ) + + run_cmake_command(GoogleTest-property-timeout1 + ${CMAKE_CTEST_COMMAND} + -C Debug + -R property_timeout\\.case_no_discovery + --no-label-summary + ) + + run_cmake_command(GoogleTest-property-timeout2 + ${CMAKE_CTEST_COMMAND} + -C Debug + -R property_timeout\\.case_with_discovery + --no-label-summary + ) +endfunction() + +function(run_GoogleTestXML DISCOVERY_MODE) + # Use a single build tree for a few tests without cleaning. + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTestXML-build) + set(RunCMake_TEST_NO_CLEAN 1) + if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG) + set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug) + endif() + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + + run_cmake_with_options(GoogleTestXML -DCMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE=${DISCOVERY_MODE}) + + run_cmake_command(GoogleTestXML-discovery + ${CMAKE_COMMAND} + --build . + --config Debug + --target xml_output + ) + + run_cmake_command(GoogleTestXML-result + ${CMAKE_CTEST_COMMAND} + -C Debug + -R GoogleTestXML + --no-label-summary + ) +endfunction() + +function(run_GoogleTest_discovery_timeout DISCOVERY_MODE) + # Use a single build tree for a few tests without cleaning. + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-timeout) + set(RunCMake_TEST_NO_CLEAN 1) + if(NOT RunCMake_GENERATOR_IS_MULTI_CONFIG) + set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug) + endif() + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + + run_cmake_with_options(GoogleTestDiscoveryTimeout -DDISCOVERY_MODE=${DISCOVERY_MODE}) + + set(RunCMake_TEST_OUTPUT_MERGE 1) + run_cmake_command(GoogleTest-discovery-${DISCOVERY_MODE}-timeout-build + ${CMAKE_COMMAND} + --build . + --config Debug + --target discovery_timeout_test + ) + set(RunCMake_TEST_OUTPUT_MERGE 0) + + run_cmake_command(GoogleTest-discovery-${DISCOVERY_MODE}-timeout-test + ${CMAKE_CTEST_COMMAND} + -C Debug + -R discovery_timeout_test + --no-label-sumary + ) +endfunction() + +function(run_GoogleTest_discovery_multi_config) + # Use a single build tree for a few tests without cleaning. + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/GoogleTest-discovery-multi-config) + set(RunCMake_TEST_NO_CLEAN 1) + file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}") + file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}") + + run_cmake(GoogleTestDiscoveryMultiConfig) + + run_cmake_command(GoogleTest-build-release + ${CMAKE_COMMAND} + --build . + --config Release + --target configuration_gtest + ) + run_cmake_command(GoogleTest-build-debug + ${CMAKE_COMMAND} + --build . + --config Debug + --target configuration_gtest + ) + run_cmake_command(GoogleTest-configuration-release + ${CMAKE_CTEST_COMMAND} + -C Release + -L CONFIG + -N + ) + run_cmake_command(GoogleTest-configuration-debug + ${CMAKE_CTEST_COMMAND} + -C Debug + -L CONFIG + -N + ) + +endfunction() + +foreach(DISCOVERY_MODE POST_BUILD PRE_TEST) + message("Testing ${DISCOVERY_MODE} discovery mode via CMAKE_GTEST_DISCOVER_TESTS_DISCOVERY_MODE global override...") + run_GoogleTest(${DISCOVERY_MODE}) + run_GoogleTestXML(${DISCOVERY_MODE}) + message("Testing ${DISCOVERY_MODE} discovery mode via DISCOVERY_MODE option...") + run_GoogleTest_discovery_timeout(${DISCOVERY_MODE}) +endforeach() + +if(RunCMake_GENERATOR_IS_MULTI_CONFIG) + message("Testing PRE_TEST discovery multi configuration...") + run_GoogleTest_discovery_multi_config() +endif() diff --git a/Tests/RunCMake/GoogleTest/configuration_gtest.cpp b/Tests/RunCMake/GoogleTest/configuration_gtest.cpp new file mode 100644 index 0000000..3cbb134 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/configuration_gtest.cpp @@ -0,0 +1,23 @@ +#include <iostream> +#include <string> + +int main(int argc, char** argv) +{ + // Note: GoogleTest.cmake doesn't actually depend on Google Test as such; + // it only requires that we produces output in the expected format when + // invoked with --gtest_list_tests. Thus, we fake that here. This allows us + // to test the module without actually needing Google Test. + if (argc > 1 && std::string(argv[1]) == "--gtest_list_tests") { + std::cout << "configuration." << std::endl; +#ifdef DEBUG + std::cout << " DISABLED_case_release" << std::endl; + std::cout << " case_debug" << std::endl; +#else + std::cout << " case_release" << std::endl; + std::cout << " DISABLED_case_debug" << std::endl; +#endif + return 0; + } + + return 1; +} diff --git a/Tests/RunCMake/GoogleTest/fake_gtest.cpp b/Tests/RunCMake/GoogleTest/fake_gtest.cpp new file mode 100644 index 0000000..f1bd7ef --- /dev/null +++ b/Tests/RunCMake/GoogleTest/fake_gtest.cpp @@ -0,0 +1,41 @@ +#include <iostream> +#include <string> + +int main(int argc, char** argv) +{ + // Note: GoogleTest.cmake doesn't actually depend on Google Test as such; + // it only requires that we produces output in the expected format when + // invoked with --gtest_list_tests. Thus, we fake that here. This allows us + // to test the module without actually needing Google Test. + if (argc > 1 && std::string(argv[1]) == "--gtest_list_tests") { + std::cout << "basic." << std::endl; + std::cout << " case_foo" << std::endl; + std::cout << " case_bar" << std::endl; + std::cout << " DISABLED_disabled_case" << std::endl; + std::cout << "DISABLED_disabled." << std::endl; + std::cout << " case" << std::endl; + std::cout << "typed/0. # TypeParam = short" << std::endl; + std::cout << " case" << std::endl; + std::cout << "typed/1. # TypeParam = float" << std::endl; + std::cout << " case" << std::endl; + std::cout << "value/test." << std::endl; + std::cout << " case/0 # GetParam() = 1" << std::endl; + std::cout << " case/1 # GetParam() = \"foo\"" << std::endl; + return 0; + } + + if (argc > 5) { + // Simple test of EXTRA_ARGS + if (std::string(argv[3]) == "how" && std::string(argv[4]) == "now" && + std::string(argv[5]) == "\"brown\" cow") { + return 0; + } + } + + // Print arguments for debugging, if we didn't get the expected arguments + for (int i = 1; i < argc; ++i) { + std::cerr << "arg[" << i << "]: '" << argv[i] << "'\n"; + } + + return 1; +} diff --git a/Tests/RunCMake/GoogleTest/no_tests_defined.cpp b/Tests/RunCMake/GoogleTest/no_tests_defined.cpp new file mode 100644 index 0000000..f8b643a --- /dev/null +++ b/Tests/RunCMake/GoogleTest/no_tests_defined.cpp @@ -0,0 +1,4 @@ +int main() +{ + return 0; +} diff --git a/Tests/RunCMake/GoogleTest/timeout_test.cpp b/Tests/RunCMake/GoogleTest/timeout_test.cpp new file mode 100644 index 0000000..5506269 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/timeout_test.cpp @@ -0,0 +1,40 @@ +#if defined(_WIN32) +# include <windows.h> +#else +# include <unistd.h> +#endif + +#include <string> + +#include <stdio.h> + +void sleepFor(unsigned seconds) +{ +#if defined(_WIN32) + Sleep(seconds * 1000); +#else + sleep(seconds); +#endif +} + +int main(int argc, char** argv) +{ + // Note: GoogleTest.cmake doesn't actually depend on Google Test as such; + // it only requires that we produce output in the expected format when + // invoked with --gtest_list_tests. Thus, we fake that here. This allows us + // to test the module without actually needing Google Test. + if (argc > 1 && std::string(argv[1]) == "--gtest_list_tests") { + printf("timeout.\n case\n"); + fflush(stdout); +#ifdef discoverySleepSec + sleepFor(discoverySleepSec); +#endif + return 0; + } + +#ifdef sleepSec + sleepFor(sleepSec); +#endif + + return 0; +} diff --git a/Tests/RunCMake/GoogleTest/xml_output.cpp b/Tests/RunCMake/GoogleTest/xml_output.cpp new file mode 100644 index 0000000..e130231 --- /dev/null +++ b/Tests/RunCMake/GoogleTest/xml_output.cpp @@ -0,0 +1,26 @@ +#include <fstream> +#include <iostream> +#include <string> + +int main(int argc, char** argv) +{ + // Note: GoogleTestXML.cmake doesn't actually depend on Google Test as such; + // it only mimicks the output file creation using the path passed to this + // test without any content + for (int i = 0; i < argc; i++) { + std::string param(argv[i]); + if (param.find("--gtest_list_tests") != std::string::npos) { + // This actually defines the name of the file passed in the 2nd run + std::cout << "GoogleTestXML." << std::endl; + std::cout << " Foo" << std::endl; + } else if (param.find("--gtest_output=xml:") != std::string::npos) { + std::string::size_type split = param.find(":"); + std::string filepath = param.substr(split + 1); + // The full file path is passed + std::ofstream ostrm(filepath.c_str(), std::ios::binary); + ostrm << "--gtest_output=xml: mockup file\n"; + } + } + + return 0; +} |