launcher_test.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <stdio.h>
  2. #include <string.h>
  3. /* Having this as comment lets gtest_add_tests recognizes the test we fake
  4. here without requiring googletest
  5. TEST_F( launcher_test, test1 )
  6. {
  7. }
  8. */
  9. char const gtest_output_json_flag_prefix[] = "--gtest_output=json:";
  10. char const json_output[] = "{\n"
  11. " \"tests\": 1,\n"
  12. " \"name\": \"AllTests\",\n"
  13. " \"testsuites\": [\n"
  14. " {\n"
  15. " \"name\": \"launcher_test\",\n"
  16. " \"tests\": 1,\n"
  17. " \"testsuite\": [\n"
  18. " { \"name\": \"test1\", \"file\": "
  19. "\"file.cpp\", \"line\": 42 }\n"
  20. " ]\n"
  21. " }\n"
  22. " ]\n"
  23. "}";
  24. int main(int argc, char** argv)
  25. {
  26. /* Note: Launcher.cmake doesn't actually depend on Google Test as such;
  27. * it only requires that we produces output in the expected format when
  28. * invoked with --gtest_list_tests. Thus, we fake that here. This allows us
  29. * to test the module without actually needing Google Test. */
  30. char* filepath;
  31. FILE* ofile;
  32. if (argc > 2 && strcmp(argv[1], "--gtest_list_tests") == 0 &&
  33. strncmp(argv[2], gtest_output_json_flag_prefix,
  34. strlen(gtest_output_json_flag_prefix)) == 0) {
  35. printf("launcher_test.\n");
  36. printf(" test1\n");
  37. filepath = strchr(argv[2], ':') + 1;
  38. /* The full file path is passed */
  39. ofile = fopen(filepath, "wb");
  40. if (!ofile) {
  41. fprintf(stderr, "Failed to create file: %s\n", filepath);
  42. return 1;
  43. }
  44. fprintf(ofile, "%s", json_output);
  45. fclose(ofile);
  46. }
  47. printf("launcher_test.test1\n");
  48. return 0;
  49. }