summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2017-08-08 13:29:41 (GMT)
committerKitware Robot <kwrobot@kitware.com>2017-08-08 13:29:48 (GMT)
commitdb6ea482f6a9905e643b0c343cc545df936c71dc (patch)
treec6da60e8de7ade9d1b0a7a9f5d2d1b663613c79e /Tests
parent3ce807f3925c1771d21e6ea5b2203208ac0186db (diff)
parentbfcda4013a52e81a1ffc2f10a6006ba75b9b607d (diff)
downloadCMake-db6ea482f6a9905e643b0c343cc545df936c71dc.zip
CMake-db6ea482f6a9905e643b0c343cc545df936c71dc.tar.gz
CMake-db6ea482f6a9905e643b0c343cc545df936c71dc.tar.bz2
Merge topic 'gtest-dynamic-discovery'
bfcda401 Add dynamic test discovery for for Google Test Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !1056
Diffstat (limited to 'Tests')
-rw-r--r--Tests/RunCMake/CMakeLists.txt1
-rw-r--r--Tests/RunCMake/GoogleTest/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/GoogleTest/GoogleTest-test-stdout.txt25
-rw-r--r--Tests/RunCMake/GoogleTest/GoogleTest.cmake15
-rw-r--r--Tests/RunCMake/GoogleTest/RunCMakeTest.cmake26
-rw-r--r--Tests/RunCMake/GoogleTest/fake_gtest.cpp41
6 files changed, 111 insertions, 0 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt
index 347b9d2..13df4a8 100644
--- a/Tests/RunCMake/CMakeLists.txt
+++ b/Tests/RunCMake/CMakeLists.txt
@@ -148,6 +148,7 @@ add_RunCMake_test(GeneratorExpression)
add_RunCMake_test(GeneratorPlatform)
add_RunCMake_test(GeneratorToolset)
add_RunCMake_test(GNUInstallDirs -DSYSTEM_NAME=${CMAKE_SYSTEM_NAME})
+add_RunCMake_test(GoogleTest) # Note: does not actually depend on Google Test
add_RunCMake_test(TargetPropertyGeneratorExpressions)
add_RunCMake_test(Languages)
add_RunCMake_test(LinkStatic)
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-test-stdout.txt b/Tests/RunCMake/GoogleTest/GoogleTest-test-stdout.txt
new file mode 100644
index 0000000..5f7753d
--- /dev/null
+++ b/Tests/RunCMake/GoogleTest/GoogleTest-test-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.cmake b/Tests/RunCMake/GoogleTest/GoogleTest.cmake
new file mode 100644
index 0000000..9a3677f
--- /dev/null
+++ b/Tests/RunCMake/GoogleTest/GoogleTest.cmake
@@ -0,0 +1,15 @@
+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 TEST
+)
diff --git a/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake b/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake
new file mode 100644
index 0000000..aec8568
--- /dev/null
+++ b/Tests/RunCMake/GoogleTest/RunCMakeTest.cmake
@@ -0,0 +1,26 @@
+include(RunCMake)
+
+function(run_GoogleTest)
+ # 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(RunCMake_GENERATOR MATCHES "Make|Ninja")
+ 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(GoogleTest)
+ run_cmake_command(GoogleTest-build
+ ${CMAKE_COMMAND}
+ --build .
+ --config Debug
+ )
+ run_cmake_command(GoogleTest-test
+ ${CMAKE_CTEST_COMMAND}
+ -C Debug
+ -L TEST
+ --no-label-summary
+ )
+endfunction()
+
+run_GoogleTest()
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;
+}