Debian Codegraph @

Tests/RunCMake/GoogleTest/launcher_test.c

raw
1 #include <stdio.h>
2 #include <string.h>
3
4 /* Having this as comment lets gtest_add_tests recognizes the test we fake
5 here without requiring googletest
6 TEST_F( launcher_test, test1 )
7 {
8 }
9 */
10
11 char const gtest_output_json_flag_prefix[] = "--gtest_output=json:";
12 char const json_output[] = "{\n"
13 " \"tests\": 1,\n"
14 " \"name\": \"AllTests\",\n"
15 " \"testsuites\": [\n"
16 " {\n"
17 " \"name\": \"launcher_test\",\n"
18 " \"tests\": 1,\n"
19 " \"testsuite\": [\n"
20 " { \"name\": \"test1\", \"file\": "
21 "\"file.cpp\", \"line\": 42 }\n"
22 " ]\n"
23 " }\n"
24 " ]\n"
25 "}";
26
27 int main(int argc, char** argv)
28 {
29 /* Note: Launcher.cmake doesn't actually depend on Google Test as such;
30 * it only requires that we produces output in the expected format when
31 * invoked with --gtest_list_tests. Thus, we fake that here. This allows us
32 * to test the module without actually needing Google Test. */
33 char* filepath;
34 FILE* ofile;
35
36 if (argc > 2 && strcmp(argv[1], "--gtest_list_tests") == 0 &&
37 strncmp(argv[2], gtest_output_json_flag_prefix,
38 strlen(gtest_output_json_flag_prefix)) == 0) {
39 printf("launcher_test.\n");
40 printf(" test1\n");
41 filepath = strchr(argv[2], ':') + 1;
42 /* The full file path is passed */
43 ofile = fopen(filepath, "wb");
44
45 if (!ofile) {
46 fprintf(stderr, "Failed to create file: %s\n", filepath);
47 return 1;
48 }
49 fprintf(ofile, "%s", json_output);
50 fclose(ofile);
51 }
52
53 printf("launcher_test.test1\n");
54 return 0;
55 }