Debian Codegraph @

Tests/RunCMake/GoogleTest/test_workdir.cpp

raw
1 #include <fstream>
2 #include <iostream>
3 #include <string>
4
5 /* Having this as a comment lets gtest_add_tests() recognize the tests we fake
6 here without requiring googletest
7 TEST_F( WorkDirWithSpaces, test1 )
8 {
9 }
10 TEST_F( WorkDirWithSpaces, test2 )
11 {
12 }
13 */
14
15 int main(int argc, char** argv)
16 {
17 // Fake gtest behavior so we don't actually require gtest.
18 // Both listing tests and test execution try to read a file from
19 // the current directory. If we are not handling spaces in the
20 // working directory correctly, the files we expect won't exist.
21
22 if (argc > 2 && std::string(argv[1]) == "--gtest_list_tests" &&
23 std::string(argv[2]).find("--gtest_output=json:") != std::string::npos) {
24 std::ifstream inTestListFile("test_list_output.txt");
25 if (!inTestListFile) {
26 std::cout << "ERROR: Failed to open test_list_output.txt" << std::endl;
27 return 1;
28 }
29 std::cout << inTestListFile.rdbuf();
30
31 std::ifstream inJsonFile("test_list_output.json");
32 if (!inJsonFile) {
33 std::cout << "ERROR: Failed to open test_list_output.json" << std::endl;
34 return 1;
35 }
36 std::string output_param(argv[2]);
37 std::string::size_type split = output_param.find(":");
38 std::string filepath = output_param.substr(split + 1);
39 // The full file path is passed
40 std::ofstream ostrm(filepath.c_str(), std::ios::binary);
41 if (!ostrm) {
42 std::cerr << "Failed to create file: " << filepath.c_str() << std::endl;
43 return 1;
44 }
45 ostrm << inJsonFile.rdbuf();
46 return 0;
47 }
48
49 std::ifstream inFile("test_output.txt");
50 if (!inFile) {
51 std::cout << "ERROR: Failed to open test_output.txt" << std::endl;
52 return 1;
53 }
54 std::cout << "Test output read from file to follow:" << std::endl;
55 std::cout << inFile.rdbuf();
56 return 0;
57 }