diff options
author | Ryan Thornton <ThorntonRyan@JohnDeere.com> | 2020-03-16 20:16:38 (GMT) |
---|---|---|
committer | Ryan Thornton <ThorntonRyan@JohnDeere.com> | 2020-03-27 14:40:40 (GMT) |
commit | 3b4838b57fc70bd64b29044ccbdf582f14a0574d (patch) | |
tree | 906b8b9696ac95ca640044458abeceb358726c70 /Tests/RunCMake/GoogleTest | |
parent | 1ba4cb565eb0bf16a717863ed4945e93468cb146 (diff) | |
download | CMake-3b4838b57fc70bd64b29044ccbdf582f14a0574d.zip CMake-3b4838b57fc70bd64b29044ccbdf582f14a0574d.tar.gz CMake-3b4838b57fc70bd64b29044ccbdf582f14a0574d.tar.bz2 |
GoogleTest: Add tests for MultiConfig discovery in PRE_TEST mode
PRE_TEST makes it possible to properly distinguish between test cases
that exist only in certain configurations.
In the new test scenario, debug tests are disabled in release builds,
and release tests are disabled in debug builds
when a multi config generator is used.
Note, this is a bit of a hack and *only* works for PRE_TEST mode.
POST_BUILD makes no attempt to get this right. It preserves the status quo
and you obtain the tests that were last discovered.
See further discussion in !4078
Ideally, the POST_BUILD behavior could be fixed
by using generator expressions in OUTPUT and BYPRODUCT expressions.
Then you could do something like:
set(ctest_include_file "${ctest_file_base}_include-$<CONFIG>.cmake")
set(ctest_tests_file "${ctest_file_base}_tests-$<CONFIG>.cmake")
Once #12877 lands, maybe this can be revisited.
Co-authored-by: Ryan Thornton <ThorntonRyan@JohnDeere.com>
Co-authored-by: Kevin Puetz <PuetzKevinA@JohnDeere.com>
Diffstat (limited to 'Tests/RunCMake/GoogleTest')
5 files changed, 88 insertions, 0 deletions
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/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/RunCMakeTest.cmake b/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake index 97a777b..6b9d458 100644 --- a/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake +++ b/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake @@ -118,6 +118,42 @@ function(run_GoogleTest_discovery_timeout DISCOVERY_MODE) ) 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}) @@ -125,3 +161,8 @@ foreach(DISCOVERY_MODE POST_BUILD PRE_TEST) 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; +} |