configuration_gtest.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include <cstdlib>
  2. #include <fstream>
  3. #include <iostream>
  4. #include <string>
  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 << "configuration." << std::endl;
  14. #ifdef DEBUG
  15. std::cout << " DISABLED_case_release" << std::endl;
  16. std::cout << " case_debug" << std::endl;
  17. std::string release_name("DISABLED_case_release");
  18. std::string debug_name("case_debug");
  19. #else
  20. std::cout << " case_release" << std::endl;
  21. std::cout << " DISABLED_case_debug" << std::endl;
  22. std::string release_name("case_release");
  23. std::string debug_name("DISABLED_case_debug");
  24. #endif
  25. std::string output_param(argv[2]);
  26. std::string::size_type split = output_param.find(":");
  27. std::string filepath = output_param.substr(split + 1);
  28. // The full file path is passed
  29. std::ofstream ostrm(filepath.c_str(), std::ios::binary);
  30. if (!ostrm) {
  31. std::cerr << "Failed to create file: " << filepath.c_str() << std::endl;
  32. return 1;
  33. }
  34. ostrm << "{\n"
  35. " \"tests\": 2,\n"
  36. " \"name\": \"AllTests\",\n"
  37. " \"testsuites\": [\n"
  38. " {\n"
  39. " \"name\": \"configuration\",\n"
  40. " \"tests\": 2,\n"
  41. " \"testsuite\": [\n"
  42. " { \"name\": \""
  43. << release_name
  44. << "\", \"file\": \"file.cpp\", \"line\": 42 },\n"
  45. " { \"name\": \""
  46. << debug_name
  47. << "\", \"file\": \"file.cpp\", \"line\": 43 }\n"
  48. " ]\n"
  49. " }\n"
  50. " ]\n"
  51. "}";
  52. return 0;
  53. }
  54. return 1;
  55. }