googletest-env-var-test_.cc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // Copyright 2008, Google Inc.
  2. // All rights reserved.
  3. //
  4. // Redistribution and use in source and binary forms, with or without
  5. // modification, are permitted provided that the following conditions are
  6. // met:
  7. //
  8. // * Redistributions of source code must retain the above copyright
  9. // notice, this list of conditions and the following disclaimer.
  10. // * Redistributions in binary form must reproduce the above
  11. // copyright notice, this list of conditions and the following disclaimer
  12. // in the documentation and/or other materials provided with the
  13. // distribution.
  14. // * Neither the name of Google Inc. nor the names of its
  15. // contributors may be used to endorse or promote products derived from
  16. // this software without specific prior written permission.
  17. //
  18. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. // A helper program for testing that Google Test parses the environment
  30. // variables correctly.
  31. #include <iostream>
  32. #include "gtest/gtest.h"
  33. #include "src/gtest-internal-inl.h"
  34. using ::std::cout;
  35. namespace testing {
  36. // The purpose of this is to make the test more realistic by ensuring
  37. // that the UnitTest singleton is created before main() is entered.
  38. // We don't actual run the TEST itself.
  39. TEST(GTestEnvVarTest, Dummy) {}
  40. void PrintFlag(const char* flag) {
  41. if (strcmp(flag, "break_on_failure") == 0) {
  42. cout << GTEST_FLAG_GET(break_on_failure);
  43. return;
  44. }
  45. if (strcmp(flag, "catch_exceptions") == 0) {
  46. cout << GTEST_FLAG_GET(catch_exceptions);
  47. return;
  48. }
  49. if (strcmp(flag, "color") == 0) {
  50. cout << GTEST_FLAG_GET(color);
  51. return;
  52. }
  53. if (strcmp(flag, "death_test_style") == 0) {
  54. cout << GTEST_FLAG_GET(death_test_style);
  55. return;
  56. }
  57. if (strcmp(flag, "death_test_use_fork") == 0) {
  58. cout << GTEST_FLAG_GET(death_test_use_fork);
  59. return;
  60. }
  61. if (strcmp(flag, "fail_fast") == 0) {
  62. cout << GTEST_FLAG_GET(fail_fast);
  63. return;
  64. }
  65. if (strcmp(flag, "filter") == 0) {
  66. cout << GTEST_FLAG_GET(filter);
  67. return;
  68. }
  69. if (strcmp(flag, "output") == 0) {
  70. cout << GTEST_FLAG_GET(output);
  71. return;
  72. }
  73. if (strcmp(flag, "brief") == 0) {
  74. cout << GTEST_FLAG_GET(brief);
  75. return;
  76. }
  77. if (strcmp(flag, "print_time") == 0) {
  78. cout << GTEST_FLAG_GET(print_time);
  79. return;
  80. }
  81. if (strcmp(flag, "repeat") == 0) {
  82. cout << GTEST_FLAG_GET(repeat);
  83. return;
  84. }
  85. if (strcmp(flag, "stack_trace_depth") == 0) {
  86. cout << GTEST_FLAG_GET(stack_trace_depth);
  87. return;
  88. }
  89. if (strcmp(flag, "throw_on_failure") == 0) {
  90. cout << GTEST_FLAG_GET(throw_on_failure);
  91. return;
  92. }
  93. cout << "Invalid flag name " << flag
  94. << ". Valid names are break_on_failure, color, filter, etc.\n";
  95. exit(1);
  96. }
  97. } // namespace testing
  98. int main(int argc, char** argv) {
  99. testing::InitGoogleTest(&argc, argv);
  100. if (argc != 2) {
  101. cout << "Usage: googletest-env-var-test_ NAME_OF_FLAG\n";
  102. return 1;
  103. }
  104. testing::PrintFlag(argv[1]);
  105. return 0;
  106. }