fake_gtest.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include <iostream>
  2. #include <string>
  3. #define ARRAY_SIZE(a) sizeof(a) / sizeof(*a)
  4. int main(int argc, char** argv)
  5. {
  6. // Note: GoogleTest.cmake doesn't actually depend on Google Test as such;
  7. // it only requires that we produces 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. bool is_filtered =
  11. argc > 2 && std::string(argv[2]).find("--gtest_filter=") == 0;
  12. bool is_basic_only =
  13. is_filtered && std::string(argv[2]).find("basic*") != std::string::npos;
  14. bool is_typed_only =
  15. is_filtered && std::string(argv[2]).find("typed*") != std::string::npos;
  16. if (argc > 1 && std::string(argv[1]) == "--gtest_list_tests") {
  17. if (!is_typed_only) {
  18. char const* basic_suite_names[] = { "basic.", "ns.basic." };
  19. for (size_t i = 0; i < ARRAY_SIZE(basic_suite_names); i++) {
  20. std::cout << basic_suite_names[i] << std::endl;
  21. std::cout << " case_foo" << std::endl;
  22. std::cout << " case_bar" << std::endl;
  23. std::cout << " DISABLED_disabled_case" << std::endl;
  24. std::cout << " DISABLEDnot_really_case" << std::endl;
  25. }
  26. }
  27. if (!is_basic_only && !is_typed_only) {
  28. std::cout << "DISABLED_disabled." << std::endl;
  29. std::cout << " case" << std::endl;
  30. std::cout << "DISABLEDnotreally." << std::endl;
  31. std::cout << " case" << std::endl;
  32. }
  33. if (!is_basic_only) {
  34. char const* typed_suite_names[] = { "typed", "ns.typed",
  35. "prefix/typed" };
  36. for (size_t i = 0; i < ARRAY_SIZE(typed_suite_names); i++) {
  37. std::cout << typed_suite_names[i] << "/0. # TypeParam = short\n";
  38. std::cout << " case" << std::endl;
  39. std::cout << typed_suite_names[i] << "/1. # TypeParam = float\n";
  40. std::cout << " case" << std::endl;
  41. std::cout << typed_suite_names[i] << "/42. # TypeParam = char\n";
  42. std::cout << " case" << std::endl;
  43. std::cout << typed_suite_names[i] << "/named. # TypeParam = int\n";
  44. std::cout << " case" << std::endl;
  45. }
  46. }
  47. if (!is_basic_only && !is_typed_only) {
  48. char const* value_suite_names[] = { "value", "ns.value",
  49. "prefix/value" };
  50. for (size_t i = 0; i < ARRAY_SIZE(value_suite_names); i++) {
  51. std::cout << value_suite_names[i] << "/test." << std::endl;
  52. std::cout << " case/0 # GetParam() = 1" << std::endl;
  53. std::cout << " case/1 # GetParam() = \"foo\"" << std::endl;
  54. std::cout << " case/named # GetParam() = 'c'" << std::endl;
  55. }
  56. char const* param_suite_names[] = { "param", "ns.param",
  57. "prefix/param" };
  58. for (size_t j = 0; j < ARRAY_SIZE(param_suite_names); j++) {
  59. std::cout << param_suite_names[j] << "/special." << std::endl;
  60. std::cout << " case/0 # GetParam() = \"semicolon;\"" << std::endl;
  61. std::cout << " case/1 # GetParam() = \"backslash\\\"" << std::endl;
  62. std::cout << " case/2 # GetParam() = \"${var}\"" << std::endl;
  63. std::cout << " case/3 # GetParam() = '['" << std::endl;
  64. std::cout << " case/4 # GetParam() = \"]]=]\"" << std::endl;
  65. std::cout << " case/5 # GetParam() = \"__osbtext\"" << std::endl;
  66. std::cout << " case/6 # GetParam() = \"__csb___text\"" << std::endl;
  67. std::cout << " case/7 # GetParam() = \"S o m e \"" << std::endl;
  68. }
  69. char const* both_suite_names[] = { "both_suite", "both/suite",
  70. "ns.both/suite",
  71. "prefix/both/suite" };
  72. for (size_t k = 0; k < ARRAY_SIZE(both_suite_names); k++) {
  73. std::cout << both_suite_names[k] << ". # TypeParam = TYPE"
  74. << std::endl;
  75. std::cout << " test # GetParam() = VALUE" << std::endl;
  76. std::cout << " case/test # GetParam() = VALUE" << std::endl;
  77. }
  78. }
  79. return 0;
  80. }
  81. if (argc > 5) {
  82. // Simple test of EXTRA_ARGS
  83. if (std::string(argv[3]) == "how" && std::string(argv[4]) == "now" &&
  84. std::string(argv[5]) == "\"brown\" cow") {
  85. return 0;
  86. }
  87. }
  88. // Print arguments for debugging, if we didn't get the expected arguments
  89. for (int i = 1; i < argc; ++i) {
  90. std::cerr << "arg[" << i << "]: '" << argv[i] << "'\n";
  91. }
  92. return 1;
  93. }