Debian Codegraph @

Tests/RunCMake/GoogleTest/test_list_extra_args.cpp

raw
1 #include <fstream>
2 #include <iostream>
3 #include <string>
4
5 int main(int argc, char** argv)
6 {
7 // Note: This test doesn't actually depend on Google Test as such;
8 // it only requires that we produce output in the expected format when
9 // invoked with --gtest_list_tests. Thus, we fake that here. This allows us
10 // to test the module without actually needing Google Test.
11
12 // Simple test of DISCOVERY_EXTRA_ARGS
13 if (argc > 5 && std::string(argv[1]) == "--gtest_list_tests" &&
14 std::string(argv[2]).find("--gtest_output=json:") != std::string::npos &&
15 std::string(argv[3]) == "how now" && std::string(argv[4]) == "" &&
16 std::string(argv[5]) == "\"brown\" cow") {
17 std::cout << "test_list_test/test.\n";
18 std::cout << " case/0 # GetParam() = 'one'\n";
19 std::cout << " case/1 # GetParam() = 'two'\n";
20 std::cout << " case/2 # GetParam() = 'three'\n";
21 std::cout << " case/3 # GetParam() = 'four'\n";
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\": 4,\n"
34 " \"name\": \"AllTests\",\n"
35 " \"testsuites\": [\n"
36 " {\n"
37 " \"name\": \"test_list_test/test\",\n"
38 " \"tests\": 4,\n"
39 " \"testsuite\": [\n"
40 " { \"name\": \"case/0\", \"file\": \"file.cpp\", "
41 "\"line\": 42 },\n"
42 " { \"name\": \"case/1\", \"file\": \"file.cpp\", "
43 "\"line\": 42 },\n"
44 " { \"name\": \"case/2\", \"file\": \"file.cpp\", "
45 "\"line\": 42 },\n"
46 " { \"name\": \"case/3\", \"file\": \"file.cpp\", "
47 "\"line\": 42 }\n"
48 " ]\n"
49 " }\n"
50 " ]\n"
51 "}";
52 }
53 return 0;
54 }