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