From f54963e60f3718bfb3d526097252dcf64fa2f34f Mon Sep 17 00:00:00 2001 From: DavidPerretSN Date: Fri, 4 Nov 2022 03:13:20 -0400 Subject: GoogleTest: Reports skipped test with gtest_add_tests Skipped GTests were reported as success when tests where added with gtest_add_tests. This fixes this behaviour. Fixes: #24130 --- Modules/GoogleTest.cmake | 6 ++++++ Tests/RunCMake/GoogleTest/GoogleTest-skip-test-stdout.txt | 5 ++++- Tests/RunCMake/GoogleTest/GoogleTest.cmake | 4 ++++ Tests/RunCMake/GoogleTest/skip_test.cpp | 7 +++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Modules/GoogleTest.cmake b/Modules/GoogleTest.cmake index b8dc482..79e9437 100644 --- a/Modules/GoogleTest.cmake +++ b/Modules/GoogleTest.cmake @@ -405,6 +405,12 @@ function(gtest_add_tests) --gtest_filter=${gtest_test_name} ${ARGS_EXTRA_ARGS} ) + # Makes sure a skipped GTest is reported as so by CTest + set_tests_properties( + ${ctest_test_name} + PROPERTIES + SKIP_REGULAR_EXPRESSION "\\[ SKIPPED \\]" + ) list(APPEND testList ${ctest_test_name}) endif() endforeach() diff --git a/Tests/RunCMake/GoogleTest/GoogleTest-skip-test-stdout.txt b/Tests/RunCMake/GoogleTest/GoogleTest-skip-test-stdout.txt index 8d7527c..18f133a 100644 --- a/Tests/RunCMake/GoogleTest/GoogleTest-skip-test-stdout.txt +++ b/Tests/RunCMake/GoogleTest/GoogleTest-skip-test-stdout.txt @@ -1,10 +1,13 @@ Test project .* *Start +[0-9]+: skip_test\.test1 *[0-9]+/[0-9]+ +Test +#[0-9]+: skip_test\.test1 \.+\*\*\*Skipped +[0-9.]+ sec + *Start +[0-9]+: skip_test\.test1 + *[0-9]+/[0-9]+ +Test +#[0-9]+: skip_test\.test1 \.+\*\*\*Skipped +[0-9.]+ sec -100% tests passed, 0 tests failed out of 1 +100% tests passed, 0 tests failed out of 2 Total Test time \(real\) = +[0-9.]+ sec The following tests did not run: [ 0-9]+- skip_test\.test1 \(Skipped\) +[ 0-9]+- skip_test\.test1 \(Skipped\) diff --git a/Tests/RunCMake/GoogleTest/GoogleTest.cmake b/Tests/RunCMake/GoogleTest/GoogleTest.cmake index 221d6ad..2ed43fc 100644 --- a/Tests/RunCMake/GoogleTest/GoogleTest.cmake +++ b/Tests/RunCMake/GoogleTest/GoogleTest.cmake @@ -78,3 +78,7 @@ xcode_sign_adhoc(skip_test) gtest_discover_tests( skip_test ) + +gtest_add_tests( + TARGET skip_test +) diff --git a/Tests/RunCMake/GoogleTest/skip_test.cpp b/Tests/RunCMake/GoogleTest/skip_test.cpp index 2bc9fe1..919b1b3 100644 --- a/Tests/RunCMake/GoogleTest/skip_test.cpp +++ b/Tests/RunCMake/GoogleTest/skip_test.cpp @@ -1,6 +1,13 @@ #include #include +/* Having this as comment lets gtest_add_tests recognizes the test we fake + here without requiring googletest +TEST_F( skip_test, test1 ) +{ +} +*/ + int main(int argc, char** argv) { // Note: GoogleTest.cmake doesn't actually depend on Google Test as such; -- cgit v0.12