| 3 | #include <string> |
| 4 | |
| 5 | int main(int argc, char** argv) |
| 6 | { |
| 7 | // Note: GoogleTest.cmake doesn't actually depend on Google Test as such; |
| 8 | // it only requires that we produces 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 | if (argc > 2 && std::string(argv[1]) == "--gtest_list_tests" && |
| 12 | std::string(argv[2]).find("--gtest_output=json:") != std::string::npos) { |
| 13 | std::cout << "flush_script_test.\n"; |
| 14 | |
| 15 | std::string output_param(argv[2]); |
| 16 | std::string::size_type split = output_param.find(":"); |
| 17 | std::string filepath = output_param.substr(split + 1); |
| 18 | // The full file path is passed |
| 19 | std::ofstream ostrm(filepath.c_str(), std::ios::binary); |
| 20 | if (!ostrm) { |
| 21 | std::cerr << "Failed to create file: " << filepath.c_str() << std::endl; |
| 22 | return 1; |
| 23 | } |
| 24 | |
| 25 | size_t const flushThreshold = 50000; |
| 26 | size_t const flushAfter = 4; |
| 27 | size_t const testCaseNum = 3 * flushAfter; |
| 28 | ostrm << "{\n" |
| 29 | " \"tests\": 4,\n" |
| 30 | " \"name\": \"AllTests\",\n" |
| 31 | " \"testsuites\": [\n" |
| 32 | " {\n" |
| 33 | " \"name\": \"flush_script_test\",\n" |
| 34 | " \"tests\": 12,\n" |
| 35 | " \"testsuite\": ["; |
| 36 | |
| 37 | std::string testName(flushThreshold / flushAfter, 'T'); |
| 38 | for (size_t i = 1; i <= testCaseNum; ++i) { |
| 39 | std::cout << " t" << i << testName.c_str() << "\n"; |
| 40 | if (i != 1) |
| 41 | ostrm << ","; |
| 42 | ostrm << "\n" |
| 43 | " {\n" |
| 44 | " \"name\": \"t" |
| 45 | << i << testName.c_str() |
| 46 | << "\",\n" |
| 47 | " \"file\": \"file2.cpp\",\n" |
| 48 | " \"line\": 47\n" |
| 49 | " }"; |
| 50 | } |
| 51 | ostrm << "\n" |
| 52 | " ]\n" |
| 53 | " }\n" |
| 54 | " ]\n" |
| 55 | "}"; |
| 56 | } |
| 57 | |
| 58 | return 0; |
| 59 | } |