fake_gtest.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <iostream>
  2. #include <string>
  3. int main(int argc, char** argv)
  4. {
  5. // Note: GoogleTest.cmake doesn't actually depend on Google Test as such;
  6. // it only requires that we produces output in the expected format when
  7. // invoked with --gtest_list_tests. Thus, we fake that here. This allows us
  8. // to test the module without actually needing Google Test.
  9. bool is_filtered =
  10. argc > 2 && std::string(argv[2]).find("--gtest_filter=") == 0;
  11. bool is_basic_only =
  12. is_filtered && std::string(argv[2]).find("basic*") != std::string::npos;
  13. bool is_typed_only =
  14. is_filtered && std::string(argv[2]).find("typed*") != std::string::npos;
  15. if (argc > 1 && std::string(argv[1]) == "--gtest_list_tests") {
  16. if (!is_typed_only) {
  17. std::cout << "basic." << std::endl;
  18. std::cout << " case_foo" << std::endl;
  19. std::cout << " case_bar" << std::endl;
  20. std::cout << " DISABLED_disabled_case" << std::endl;
  21. std::cout << " DISABLEDnot_really_case" << std::endl;
  22. }
  23. if (!is_basic_only && !is_typed_only) {
  24. std::cout << "DISABLED_disabled." << std::endl;
  25. std::cout << " case" << std::endl;
  26. std::cout << "DISABLEDnotreally." << std::endl;
  27. std::cout << " case" << std::endl;
  28. }
  29. if (!is_basic_only) {
  30. std::cout << "typed/0. # TypeParam = short" << std::endl;
  31. std::cout << " case" << std::endl;
  32. std::cout << "typed/1. # TypeParam = float" << std::endl;
  33. std::cout << " case" << std::endl;
  34. }
  35. if (!is_basic_only && !is_typed_only) {
  36. std::cout << "value/test." << std::endl;
  37. std::cout << " case/0 # GetParam() = 1" << std::endl;
  38. std::cout << " case/1 # GetParam() = \"foo\"" << std::endl;
  39. std::cout << "param/special." << std::endl;
  40. std::cout << " case/0 # GetParam() = \"semicolon;\"" << std::endl;
  41. std::cout << " case/1 # GetParam() = \"backslash\\\"" << std::endl;
  42. std::cout << " case/2 # GetParam() = \"${var}\"" << std::endl;
  43. }
  44. return 0;
  45. }
  46. if (argc > 5) {
  47. // Simple test of EXTRA_ARGS
  48. if (std::string(argv[3]) == "how" && std::string(argv[4]) == "now" &&
  49. std::string(argv[5]) == "\"brown\" cow") {
  50. return 0;
  51. }
  52. }
  53. // Print arguments for debugging, if we didn't get the expected arguments
  54. for (int i = 1; i < argc; ++i) {
  55. std::cerr << "arg[" << i << "]: '" << argv[i] << "'\n";
  56. }
  57. return 1;
  58. }