googletest-env-var-test_.cc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. }
  41. void PrintFlag(const char* flag) {
  42. if (strcmp(flag, "break_on_failure") == 0) {
  43. cout << GTEST_FLAG(break_on_failure);
  44. return;
  45. }
  46. if (strcmp(flag, "catch_exceptions") == 0) {
  47. cout << GTEST_FLAG(catch_exceptions);
  48. return;
  49. }
  50. if (strcmp(flag, "color") == 0) {
  51. cout << GTEST_FLAG(color);
  52. return;
  53. }
  54. if (strcmp(flag, "death_test_style") == 0) {
  55. cout << GTEST_FLAG(death_test_style);
  56. return;
  57. }
  58. if (strcmp(flag, "death_test_use_fork") == 0) {
  59. cout << GTEST_FLAG(death_test_use_fork);
  60. return;
  61. }
  62. if (strcmp(flag, "fail_fast") == 0) {
  63. cout << GTEST_FLAG(fail_fast);
  64. return;
  65. }
  66. if (strcmp(flag, "filter") == 0) {
  67. cout << GTEST_FLAG(filter);
  68. return;
  69. }
  70. if (strcmp(flag, "output") == 0) {
  71. cout << GTEST_FLAG(output);
  72. return;
  73. }
  74. if (strcmp(flag, "brief") == 0) {
  75. cout << GTEST_FLAG(brief);
  76. return;
  77. }
  78. if (strcmp(flag, "print_time") == 0) {
  79. cout << GTEST_FLAG(print_time);
  80. return;
  81. }
  82. if (strcmp(flag, "repeat") == 0) {
  83. cout << GTEST_FLAG(repeat);
  84. return;
  85. }
  86. if (strcmp(flag, "stack_trace_depth") == 0) {
  87. cout << GTEST_FLAG(stack_trace_depth);
  88. return;
  89. }
  90. if (strcmp(flag, "throw_on_failure") == 0) {
  91. cout << GTEST_FLAG(throw_on_failure);
  92. return;
  93. }
  94. cout << "Invalid flag name " << flag
  95. << ". Valid names are break_on_failure, color, filter, etc.\n";
  96. exit(1);
  97. }
  98. } // namespace testing
  99. int main(int argc, char** argv) {
  100. testing::InitGoogleTest(&argc, argv);
  101. if (argc != 2) {
  102. cout << "Usage: googletest-env-var-test_ NAME_OF_FLAG\n";
  103. return 1;
  104. }
  105. testing::PrintFlag(argv[1]);
  106. return 0;
  107. }