| 1 |
#include <fstream> |
| 2 |
#include <iostream> |
| 3 |
#include <string> |
| 4 |
|
| 5 |
int main(int argc, char** argv) |
| 6 |
{ |
| 7 |
// Note: GoogleTestXML.cmake doesn't actually depend on Google Test as such; |
| 8 |
// it only mimics the output file creation using the path passed to this |
| 9 |
// test without any content |
| 10 |
for (int i = 0; i < argc; i++) { |
| 11 |
std::string param(argv[i]); |
| 12 |
if (param.find("--gtest_list_tests") != std::string::npos) { |
| 13 |
// This actually defines the name of the file passed in the 2nd run |
| 14 |
std::cout << "GoogleTestXML." << std::endl; |
| 15 |
std::cout << " Foo" << std::endl; |
| 16 |
// When changing these names, make sure to adapt the folder creation |
| 17 |
// in GoogleTestXML.cmake |
| 18 |
std::cout << "GoogleTestXMLSpecial/cases." << std::endl; |
| 19 |
std::cout << " case/0 # GetParam() = 42" << std::endl; |
| 20 |
std::cout << " case/1 # GetParam() = \"string\"" << std::endl; |
| 21 |
std::cout << " case/2 # GetParam() = \"path/like\"" << std::endl; |
| 22 |
} else if (param.find("--gtest_output=json:") != std::string::npos) { |
| 23 |
std::string::size_type split = param.find(":"); |
| 24 |
std::string filepath = param.substr(split + 1); |
| 25 |
// The full file path is passed |
| 26 |
std::ofstream ostrm(filepath.c_str(), std::ios::binary); |
| 27 |
if (!ostrm) { |
| 28 |
std::cerr << "Failed to create file: " << filepath.c_str() |
| 29 |
<< std::endl; |
| 30 |
return 1; |
| 31 |
} |
| 32 |
ostrm |
| 33 |
<< "{\n" |
| 34 |
" \"tests\": 4,\n" |
| 35 |
" \"name\": \"AllTests\",\n" |
| 36 |
" \"testsuites\": [\n" |
| 37 |
" {\n" |
| 38 |
" \"name\": \"GoogleTestXML\",\n" |
| 39 |
" \"tests\": 1,\n" |
| 40 |
" \"testsuite\": [\n" |
| 41 |
" { \"name\": \"Foo\", \"file\": \"file.cpp\", " |
| 42 |
"\"line\": 42 }\n" |
| 43 |
" ]\n" |
| 44 |
" },\n" |
| 45 |
" {\n" |
| 46 |
" \"name\": \"GoogleTestXMLSpecial\\/cases\",\n" |
| 47 |
" \"tests\": 3,\n" |
| 48 |
" \"testsuite\": [\n" |
| 49 |
" { \"name\": \"case\\/0\", \"value_param\": " |
| 50 |
"\"42\", \"file\": \"file2.cpp\", \"line\": 47 },\n" |
| 51 |
" { \"name\": \"case\\/1\", \"value_param\": " |
| 52 |
"\"\\\"string\\\"\", \"file\": \"file2.cpp\", \"line\": 47 },\n" |
| 53 |
" { \"name\": \"case\\/2\", \"value_param\": " |
| 54 |
"\"\\\"path/like\\\"\", \"file\": \"file2.cpp\", \"line\": 47 }\n" |
| 55 |
" ]\n" |
| 56 |
" }\n" |
| 57 |
" ]\n" |
| 58 |
"}"; |
| 59 |
} else if (param.find("--gtest_output=xml:") != std::string::npos) { |
| 60 |
std::string::size_type split = param.find(":"); |
| 61 |
std::string filepath = param.substr(split + 1); |
| 62 |
// The full file path is passed |
| 63 |
std::ofstream ostrm(filepath.c_str(), std::ios::binary); |
| 64 |
if (!ostrm) { |
| 65 |
std::cerr << "Failed to create file: " << filepath.c_str() |
| 66 |
<< std::endl; |
| 67 |
return 1; |
| 68 |
} |
| 69 |
ostrm << "--gtest_output=xml: mockup file\n"; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
return 0; |
| 74 |
} |