mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-07 14:20:06 -06:00
Add a new gtest_discover_tests function to GoogleTest.cmake, implementing dynamic test discovery (i.e. tests are discovered by actually running the test executable and asking for the list of available tests, which is used to dynamically declare the tests) rather than the source-parsing approach used by gtest_add_tests. Compared to the source-parsing approach, this has the advantage of being robust against users declaring tests in unusual ways, and much better support for advanced features such as parameterized tests. A unit test, modeled after the TEST_INCLUDE_DIR[S] test, is also included. Note that the unit test does not actually require that Google Test is available. The new functionality does not actually depend on Google Test as such; it only requires that the test executable lists tests in the expected format when invoked with --gtest_list_tests, which the unit test can fake readily.
42 lines
1.5 KiB
C++
42 lines
1.5 KiB
C++
#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;
|
|
}
|