Debian Codegraph @

Tests/RunCMake/GoogleTest/configuration_gtest.cpp

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