From 70f9f62da86d43c61435ea2d58782ba470d8d282 Mon Sep 17 00:00:00 2001 From: Matthew Woehlke Date: Mon, 20 Nov 2017 12:53:25 -0500 Subject: GoogleTest: Fix multiple discovery on same target According to the documentation, tests can be discovered for a target multiple times by using a different prefix and/or suffix to ensure name uniqueness. However, while this worked for gtest_add_tests, it did not work with gtest_discover_tests because the generated file that sets up the tests was named based only on the target name, and so subsequent discovery from the same target would clobber earlier discovery. Fix this by introducing a counter that records how many times discovery has been used on a target, and use this to generate unique names of the generated test list files. --- Modules/GoogleTest.cmake | 27 ++++++++++++++++++++-- .../RunCMake/GoogleTest/GoogleTest-test-stdout.txt | 25 -------------------- .../GoogleTest/GoogleTest-test1-stdout.txt | 25 ++++++++++++++++++++ .../GoogleTest/GoogleTest-test2-stdout.txt | 25 ++++++++++++++++++++ Tests/RunCMake/GoogleTest/GoogleTest.cmake | 10 +++++++- Tests/RunCMake/GoogleTest/RunCMakeTest.cmake | 10 ++++++-- 6 files changed, 92 insertions(+), 30 deletions(-) delete mode 100644 Tests/RunCMake/GoogleTest/GoogleTest-test-stdout.txt create mode 100644 Tests/RunCMake/GoogleTest/GoogleTest-test1-stdout.txt create mode 100644 Tests/RunCMake/GoogleTest/GoogleTest-test2-stdout.txt diff --git a/Modules/GoogleTest.cmake b/Modules/GoogleTest.cmake index 41bd1dc..3d47367 100644 --- a/Modules/GoogleTest.cmake +++ b/Modules/GoogleTest.cmake @@ -361,9 +361,32 @@ function(gtest_discover_tests TARGET) set(_TEST_LIST ${TARGET}_TESTS) endif() + get_property( + has_counter + TARGET ${TARGET} + PROPERTY CTEST_DISCOVERED_TEST_COUNTER + SET + ) + if(has_counter) + get_property( + counter + TARGET ${TARGET} + PROPERTY CTEST_DISCOVERED_TEST_COUNTER + ) + math(EXPR counter "${counter} + 1") + else() + set(counter 1) + endif() + set_property( + TARGET ${TARGET} + PROPERTY CTEST_DISCOVERED_TEST_COUNTER + ${counter} + ) + # Define rule to generate test list for aforementioned test executable - set(ctest_include_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_include.cmake") - set(ctest_tests_file "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}_tests.cmake") + set(ctest_file_base "${CMAKE_CURRENT_BINARY_DIR}/${TARGET}[${counter}]") + set(ctest_include_file "${ctest_file_base}_include.cmake") + set(ctest_tests_file "${ctest_file_base}_tests.cmake") get_property(crosscompiling_emulator TARGET ${TARGET} PROPERTY CROSSCOMPILING_EMULATOR diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-test-stdout.txt b/Tests/RunCMake/GoogleTest/GoogleTest-test-stdout.txt deleted file mode 100644 index 5f7753d..0000000 --- a/Tests/RunCMake/GoogleTest/GoogleTest-test-stdout.txt +++ /dev/null @@ -1,25 +0,0 @@ -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-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 index 9a3677f..58f4196 100644 --- a/Tests/RunCMake/GoogleTest/GoogleTest.cmake +++ b/Tests/RunCMake/GoogleTest/GoogleTest.cmake @@ -11,5 +11,13 @@ gtest_discover_tests( TEST_PREFIX TEST: TEST_SUFFIX !1 EXTRA_ARGS how now "\"brown\" cow" - PROPERTIES LABELS TEST + PROPERTIES LABELS TEST1 +) + +gtest_discover_tests( + fake_gtest + TEST_PREFIX TEST: + TEST_SUFFIX !2 + EXTRA_ARGS how now "\"brown\" cow" + PROPERTIES LABELS TEST2 ) diff --git a/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake b/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake index aec8568..b79af26 100644 --- a/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake +++ b/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake @@ -15,10 +15,16 @@ function(run_GoogleTest) --build . --config Debug ) - run_cmake_command(GoogleTest-test + run_cmake_command(GoogleTest-test1 ${CMAKE_CTEST_COMMAND} -C Debug - -L TEST + -L TEST1 + --no-label-summary + ) + run_cmake_command(GoogleTest-test2 + ${CMAKE_CTEST_COMMAND} + -C Debug + -L TEST2 --no-label-summary ) endfunction() -- cgit v0.12