Debian Codegraph @

Tests/RunCMake/GoogleTest/skip_test.cpp

raw
1 #include <fstream>
2 #include <iostream>
3 #include <string>
4
5 /* Having this as comment lets gtest_add_tests recognizes the test we fake
6 here without requiring googletest
7 TEST_F( skip_test, test1 )
8 {
9 }
10 */
11
12 int main(int argc, char** argv)
13 {
14 // Note: GoogleTest.cmake doesn't actually depend on Google Test as such;
15 // it only requires that we produces output in the expected format when
16 // invoked with --gtest_list_tests. Thus, we fake that here. This allows us
17 // to test the module without actually needing Google Test.
18 if (argc > 2 && std::string(argv[1]) == "--gtest_list_tests" &&
19 std::string(argv[2]).find("--gtest_output=json:") != std::string::npos) {
20 std::cout << "skip_test." << std::endl;
21 std::cout << " test1" << std::endl;
22
23 std::string output_param(argv[2]);
24 std::string::size_type split = output_param.find(":");
25 std::string filepath = output_param.substr(split + 1);
26 // The full file path is passed
27 std::ofstream ostrm(filepath.c_str(), std::ios::binary);
28 if (!ostrm) {
29 std::cerr << "Failed to create file: " << filepath.c_str() << std::endl;
30 return 1;
31 }
32 ostrm << "{\n"
33 " \"tests\": 1,\n"
34 " \"name\": \"AllTests\",\n"
35 " \"testsuites\": [\n"
36 " {\n"
37 " \"name\": \"skip_test\",\n"
38 " \"tests\": 1,\n"
39 " \"testsuite\": [\n"
40 " { \"name\": \"test1\", \"file\": \"file.cpp\", "
41 "\"line\": 42 }\n"
42 " ]\n"
43 " }\n"
44 " ]\n"
45 "}";
46
47 return 0;
48 }
49
50 std::cout << "[ SKIPPED ] skip_test.test1" << std::endl;
51 return 0;
52 }