test_list_extra_args.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include <fstream>
  2. #include <iostream>
  3. #include <string>
  4. int main(int argc, char** argv)
  5. {
  6. // Note: This test doesn't actually depend on Google Test as such;
  7. // it only requires that we produce output in the expected format when
  8. // invoked with --gtest_list_tests. Thus, we fake that here. This allows us
  9. // to test the module without actually needing Google Test.
  10. // Simple test of DISCOVERY_EXTRA_ARGS
  11. if (argc > 5 && std::string(argv[1]) == "--gtest_list_tests" &&
  12. std::string(argv[2]).find("--gtest_output=json:") != std::string::npos &&
  13. std::string(argv[3]) == "how now" && std::string(argv[4]) == "" &&
  14. std::string(argv[5]) == "\"brown\" cow") {
  15. std::cout << "test_list_test/test.\n";
  16. std::cout << " case/0 # GetParam() = 'one'\n";
  17. std::cout << " case/1 # GetParam() = 'two'\n";
  18. std::cout << " case/2 # GetParam() = 'three'\n";
  19. std::cout << " case/3 # GetParam() = 'four'\n";
  20. std::string output_param(argv[2]);
  21. std::string::size_type split = output_param.find(":");
  22. std::string filepath = output_param.substr(split + 1);
  23. // The full file path is passed
  24. std::ofstream ostrm(filepath.c_str(), std::ios::binary);
  25. if (!ostrm) {
  26. std::cerr << "Failed to create file: " << filepath.c_str() << std::endl;
  27. return 1;
  28. }
  29. ostrm << "{\n"
  30. " \"tests\": 4,\n"
  31. " \"name\": \"AllTests\",\n"
  32. " \"testsuites\": [\n"
  33. " {\n"
  34. " \"name\": \"test_list_test/test\",\n"
  35. " \"tests\": 4,\n"
  36. " \"testsuite\": [\n"
  37. " { \"name\": \"case/0\", \"file\": \"file.cpp\", "
  38. "\"line\": 42 },\n"
  39. " { \"name\": \"case/1\", \"file\": \"file.cpp\", "
  40. "\"line\": 42 },\n"
  41. " { \"name\": \"case/2\", \"file\": \"file.cpp\", "
  42. "\"line\": 42 },\n"
  43. " { \"name\": \"case/3\", \"file\": \"file.cpp\", "
  44. "\"line\": 42 }\n"
  45. " ]\n"
  46. " }\n"
  47. " ]\n"
  48. "}";
  49. }
  50. return 0;
  51. }