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