skip_test.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include <fstream>
  2. #include <iostream>
  3. #include <string>
  4. /* Having this as comment lets gtest_add_tests recognizes the test we fake
  5. here without requiring googletest
  6. TEST_F( skip_test, test1 )
  7. {
  8. }
  9. */
  10. int main(int argc, char** argv)
  11. {
  12. // Note: GoogleTest.cmake doesn't actually depend on Google Test as such;
  13. // it only requires that we produces output in the expected format when
  14. // invoked with --gtest_list_tests. Thus, we fake that here. This allows us
  15. // to test the module without actually needing Google Test.
  16. if (argc > 2 && std::string(argv[1]) == "--gtest_list_tests" &&
  17. std::string(argv[2]).find("--gtest_output=json:") != std::string::npos) {
  18. std::cout << "skip_test." << std::endl;
  19. std::cout << " test1" << std::endl;
  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\": 1,\n"
  31. " \"name\": \"AllTests\",\n"
  32. " \"testsuites\": [\n"
  33. " {\n"
  34. " \"name\": \"skip_test\",\n"
  35. " \"tests\": 1,\n"
  36. " \"testsuite\": [\n"
  37. " { \"name\": \"test1\", \"file\": \"file.cpp\", "
  38. "\"line\": 42 }\n"
  39. " ]\n"
  40. " }\n"
  41. " ]\n"
  42. "}";
  43. return 0;
  44. }
  45. std::cout << "[ SKIPPED ] skip_test.test1" << std::endl;
  46. return 0;
  47. }