proxygen
gtest_environment_test.cc File Reference
#include <stdlib.h>
#include <stdio.h>
#include "gtest/gtest.h"
#include "src/gtest-internal-inl.h"

Go to the source code of this file.

Namespaces

 testing
 

Macros

#define GTEST_IMPLEMENTATION_   1
 

Enumerations

enum  FailureType
 

Functions

 testing::GTEST_DECLARE_string_ (filter)
 
int main (int argc, char **argv)
 

Macro Definition Documentation

#define GTEST_IMPLEMENTATION_   1

Definition at line 38 of file gtest_environment_test.cc.

Enumeration Type Documentation

Definition at line 48 of file gtest_environment_test.cc.

48  {
49  NO_FAILURE, NON_FATAL_FAILURE, FATAL_FAILURE
50 };

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 137 of file gtest_environment_test.cc.

References testing::AddGlobalTestEnvironment(), folly::pushmi::operators::filter, GTEST_FLAG, testing::InitGoogleTest(), and RunAllTests().

137  {
139 
140  // Registers a global test environment, and verifies that the
141  // registration function returns its argument.
142  MyEnvironment* const env = new MyEnvironment;
143  Check(testing::AddGlobalTestEnvironment(env) == env,
144  "AddGlobalTestEnvironment() should return its argument.");
145 
146  // Verifies that RUN_ALL_TESTS() runs the tests when the global
147  // set-up is successful.
148  Check(RunAllTests(env, NO_FAILURE) != 0,
149  "RUN_ALL_TESTS() should return non-zero, as the global tear-down "
150  "should generate a failure.");
151  Check(test_was_run,
152  "The tests should run, as the global set-up should generate no "
153  "failure");
154  Check(env->tear_down_was_run(),
155  "The global tear-down should run, as the global set-up was run.");
156 
157  // Verifies that RUN_ALL_TESTS() runs the tests when the global
158  // set-up generates no fatal failure.
159  Check(RunAllTests(env, NON_FATAL_FAILURE) != 0,
160  "RUN_ALL_TESTS() should return non-zero, as both the global set-up "
161  "and the global tear-down should generate a non-fatal failure.");
162  Check(test_was_run,
163  "The tests should run, as the global set-up should generate no "
164  "fatal failure.");
165  Check(env->tear_down_was_run(),
166  "The global tear-down should run, as the global set-up was run.");
167 
168  // Verifies that RUN_ALL_TESTS() runs no test when the global set-up
169  // generates a fatal failure.
170  Check(RunAllTests(env, FATAL_FAILURE) != 0,
171  "RUN_ALL_TESTS() should return non-zero, as the global set-up "
172  "should generate a fatal failure.");
173  Check(!test_was_run,
174  "The tests should not run, as the global set-up should generate "
175  "a fatal failure.");
176  Check(env->tear_down_was_run(),
177  "The global tear-down should run, as the global set-up was run.");
178 
179  // Verifies that RUN_ALL_TESTS() doesn't do global set-up or
180  // tear-down when there is no test to run.
181  testing::GTEST_FLAG(filter) = "-*";
182  Check(RunAllTests(env, NO_FAILURE) == 0,
183  "RUN_ALL_TESTS() should return zero, as there is no test to run.");
184  Check(!env->set_up_was_run(),
185  "The global set-up should not run, as there is no test to run.");
186  Check(!env->tear_down_was_run(),
187  "The global tear-down should not run, "
188  "as the global set-up was not run.");
189 
190  printf("PASS\n");
191  return 0;
192 }
#define GTEST_FLAG(name)
Definition: gtest-port.h:2504
PUSHMI_INLINE_VAR constexpr detail::filter_fn filter
Definition: filter.h:75
Environment * AddGlobalTestEnvironment(Environment *env)
Definition: gtest.h:1350
char ** argv
int RunAllTests()
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: gtest.cc:5370