fake_gtest.cpp 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. const char* 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. const char* typed_suite_names[] = { "typed", "ns.typed" };
  35. for (size_t i = 0; i < ARRAY_SIZE(typed_suite_names); i++) {
  36. std::cout << typed_suite_names[i] << "/0. # TypeParam = short"
  37. << std::endl;
  38. std::cout << " case" << std::endl;
  39. std::cout << typed_suite_names[i] << "/1. # TypeParam = float"
  40. << std::endl;
  41. std::cout << " case" << std::endl;
  42. }
  43. }
  44. if (!is_basic_only && !is_typed_only) {
  45. const char* value_suite_names[] = { "value", "ns.value" };
  46. for (size_t i = 0; i < ARRAY_SIZE(value_suite_names); i++) {
  47. std::cout << value_suite_names[i] << "/test." << std::endl;
  48. std::cout << " case/0 # GetParam() = 1" << std::endl;
  49. std::cout << " case/1 # GetParam() = \"foo\"" << std::endl;
  50. }
  51. const char* param_suite_names[] = { "param", "ns.param" };
  52. for (size_t j = 0; j < ARRAY_SIZE(param_suite_names); j++) {
  53. std::cout << param_suite_names[j] << "/special." << std::endl;
  54. std::cout << " case/0 # GetParam() = \"semicolon;\"" << std::endl;
  55. std::cout << " case/1 # GetParam() = \"backslash\\\"" << std::endl;
  56. std::cout << " case/2 # GetParam() = \"${var}\"" << std::endl;
  57. std::cout << " case/3 # GetParam() = '['" << std::endl;
  58. std::cout << " case/4 # GetParam() = \"]]=]\"" << std::endl;
  59. std::cout << " case/5 # GetParam() = \"__osbtext\"" << std::endl;
  60. std::cout << " case/6 # GetParam() = \"__csb___text\"" << std::endl;
  61. }
  62. }
  63. return 0;
  64. }
  65. if (argc > 5) {
  66. // Simple test of EXTRA_ARGS
  67. if (std::string(argv[3]) == "how" && std::string(argv[4]) == "now" &&
  68. std::string(argv[5]) == "\"brown\" cow") {
  69. return 0;
  70. }
  71. }
  72. // Print arguments for debugging, if we didn't get the expected arguments
  73. for (int i = 1; i < argc; ++i) {
  74. std::cerr << "arg[" << i << "]: '" << argv[i] << "'\n";
  75. }
  76. return 1;
  77. }