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

Go to the source code of this file.

Classes

class  FailingParamTest
 
class  NonFatalFailureInFixtureConstructorTest
 
class  FatalFailureInFixtureConstructorTest
 
class  NonFatalFailureInSetUpTest
 
class  FatalFailureInSetUpTest
 
class  foo::MixedUpTestCaseTest
 
class  foo::MixedUpTestCaseWithSameTestNameTest
 
class  bar::MixedUpTestCaseTest
 
class  bar::MixedUpTestCaseWithSameTestNameTest
 
class  TEST_F_before_TEST_in_same_test_case
 
class  TEST_before_TEST_F_in_same_test_case
 
class  ExpectFailureTest
 
class  FooEnvironment
 
class  BarEnvironment
 

Namespaces

 foo
 
 bar
 

Macros

#define GTEST_IMPLEMENTATION_   1
 

Functions

void TestEq1 (int x)
 
void TryTestSubroutine ()
 
 TEST (PassingTest, PassingTest1)
 
 TEST (PassingTest, PassingTest2)
 
 TEST_P (FailingParamTest, Fails)
 
 INSTANTIATE_TEST_CASE_P (PrintingFailingParams, FailingParamTest, testing::Values(2))
 
 TEST (NonfatalFailureTest, EscapesStringOperands)
 
 TEST (NonfatalFailureTest, DiffForLongStrings)
 
 TEST (FatalFailureTest, FatalFailureInSubroutine)
 
 TEST (FatalFailureTest, FatalFailureInNestedSubroutine)
 
 TEST (FatalFailureTest, NonfatalFailureInSubroutine)
 
 TEST (LoggingTest, InterleavingLoggingAndAssertions)
 
void SubWithoutTrace (int n)
 
void SubWithTrace (int n)
 
 TEST (SCOPED_TRACETest, ObeysScopes)
 
 TEST (SCOPED_TRACETest, WorksInLoop)
 
 TEST (SCOPED_TRACETest, WorksInSubroutine)
 
 TEST (SCOPED_TRACETest, CanBeNested)
 
 TEST (SCOPED_TRACETest, CanBeRepeated)
 
 TEST (DisabledTestsWarningTest, DISABLED_AlsoRunDisabledTestsFlagSuppressesWarning)
 
void AdHocTest ()
 
int RunAllTests ()
 
 TEST_F (NonFatalFailureInFixtureConstructorTest, FailureInConstructor)
 
 TEST_F (FatalFailureInFixtureConstructorTest, FailureInConstructor)
 
 TEST_F (NonFatalFailureInSetUpTest, FailureInSetUp)
 
 TEST_F (FatalFailureInSetUpTest, FailureInSetUp)
 
 TEST (AddFailureAtTest, MessageContainsSpecifiedFileAndLineNumber)
 
 foo::TEST_F (MixedUpTestCaseTest, FirstTestFromNamespaceFoo)
 
 foo::TEST_F (MixedUpTestCaseTest, SecondTestFromNamespaceFoo)
 
 foo::TEST_F (MixedUpTestCaseWithSameTestNameTest, TheSecondTestWithThisNameShouldFail)
 
 bar::TEST_F (MixedUpTestCaseTest, ThisShouldFail)
 
 bar::TEST_F (MixedUpTestCaseTest, ThisShouldFailToo)
 
 bar::TEST_F (MixedUpTestCaseWithSameTestNameTest, TheSecondTestWithThisNameShouldFail)
 
 TEST_F (TEST_F_before_TEST_in_same_test_case, DefinedUsingTEST_F)
 
 TEST (TEST_F_before_TEST_in_same_test_case, DefinedUsingTESTAndShouldFail)
 
 TEST (TEST_before_TEST_F_in_same_test_case, DefinedUsingTEST)
 
 TEST_F (TEST_before_TEST_F_in_same_test_case, DefinedUsingTEST_FAndShouldFail)
 
 TEST (ExpectNonfatalFailureTest, CanReferenceGlobalVariables)
 
 TEST (ExpectNonfatalFailureTest, CanReferenceLocalVariables)
 
 TEST (ExpectNonfatalFailureTest, SucceedsWhenThereIsOneNonfatalFailure)
 
 TEST (ExpectNonfatalFailureTest, FailsWhenThereIsNoNonfatalFailure)
 
 TEST (ExpectNonfatalFailureTest, FailsWhenThereAreTwoNonfatalFailures)
 
 TEST (ExpectNonfatalFailureTest, FailsWhenThereIsOneFatalFailure)
 
 TEST (ExpectNonfatalFailureTest, FailsWhenStatementReturns)
 
 TEST (ExpectFatalFailureTest, CanReferenceGlobalVariables)
 
 TEST (ExpectFatalFailureTest, CanReferenceLocalStaticVariables)
 
 TEST (ExpectFatalFailureTest, SucceedsWhenThereIsOneFatalFailure)
 
 TEST (ExpectFatalFailureTest, FailsWhenThereIsNoFatalFailure)
 
void FatalFailure ()
 
 TEST (ExpectFatalFailureTest, FailsWhenThereAreTwoFatalFailures)
 
 TEST (ExpectFatalFailureTest, FailsWhenThereIsOneNonfatalFailure)
 
 TEST (ExpectFatalFailureTest, FailsWhenStatementReturns)
 
 TEST_F (ExpectFailureTest, ExpectFatalFailure)
 
 TEST_F (ExpectFailureTest, ExpectNonFatalFailure)
 
 TEST_F (ExpectFailureTest, ExpectFatalFailureOnAllThreads)
 
 TEST_F (ExpectFailureTest, ExpectNonFatalFailureOnAllThreads)
 
int main (int argc, char **argv)
 

Variables

static const char kGoldenString [] = "\"Line\0 1\"\nLine 2"
 
int global_integer = 0
 

Macro Definition Documentation

#define GTEST_IMPLEMENTATION_   1

Definition at line 46 of file gtest_output_test_.cc.

Function Documentation

void AdHocTest ( )

Definition at line 337 of file gtest_output_test_.cc.

References EXPECT_EQ, and EXPECT_TRUE.

Referenced by RunAllTests().

337  {
338  printf("The non-test part of the code is expected to have 2 failures.\n\n");
339  EXPECT_TRUE(false);
340  EXPECT_EQ(2, 3);
341 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
void FatalFailure ( )

Definition at line 710 of file gtest_output_test_.cc.

References FAIL.

Referenced by TEST().

710  {
711  FAIL() << "Expected fatal failure.";
712 }
#define FAIL()
Definition: gtest.h:1822
INSTANTIATE_TEST_CASE_P ( PrintingFailingParams  ,
FailingParamTest  ,
testing::Values(2)   
)

Referenced by TEST(), and TEST_P().

int main ( int  argc,
char **  argv 
)

Definition at line 1024 of file gtest_output_test_.cc.

References testing::AddGlobalTestEnvironment(), count, testing::internal::posix::FReopen(), GTEST_FLAG, testing::InitGoogleTest(), RUN_ALL_TESTS(), RunAllTests(), and string.

1024  {
1025  testing::GTEST_FLAG(print_time) = false;
1026 
1027  // We just run the tests, knowing some of them are intended to fail.
1028  // We will use a separate Python script to compare the output of
1029  // this program with the golden file.
1030 
1031  // It's hard to test InitGoogleTest() directly, as it has many
1032  // global side effects. The following line serves as a sanity test
1033  // for it.
1034  testing::InitGoogleTest(&argc, argv);
1035  bool internal_skip_environment_and_ad_hoc_tests =
1036  std::count(argv, argv + argc,
1037  std::string("internal_skip_environment_and_ad_hoc_tests")) > 0;
1038 
1039 #if GTEST_HAS_DEATH_TEST
1040  if (testing::internal::GTEST_FLAG(internal_run_death_test) != "") {
1041  // Skip the usual output capturing if we're running as the child
1042  // process of an threadsafe-style death test.
1043 # if GTEST_OS_WINDOWS
1044  posix::FReopen("nul:", "w", stdout);
1045 # else
1046  posix::FReopen("/dev/null", "w", stdout);
1047 # endif // GTEST_OS_WINDOWS
1048  return RUN_ALL_TESTS();
1049  }
1050 #endif // GTEST_HAS_DEATH_TEST
1051 
1052  if (internal_skip_environment_and_ad_hoc_tests)
1053  return RUN_ALL_TESTS();
1054 
1055  // Registers two global test environments.
1056  // The golden file verifies that they are set up in the order they
1057  // are registered, and torn down in the reverse order.
1060 
1061  return RunAllTests();
1062 }
#define GTEST_FLAG(name)
Definition: gtest-port.h:2504
Environment * AddGlobalTestEnvironment(Environment *env)
Definition: gtest.h:1350
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: gtest.h:2232
FILE * FReopen(const char *path, const char *mode, FILE *stream)
Definition: gtest-port.h:2371
char ** argv
int * count
const char * string
Definition: Conv.cpp:212
int RunAllTests()
GTEST_API_ void InitGoogleTest(int *argc, char **argv)
Definition: gtest.cc:5370
int RunAllTests ( )

Definition at line 344 of file gtest_output_test_.cc.

References AdHocTest(), and RUN_ALL_TESTS().

Referenced by main(), and testing::internal::UnitTestImpl::set_current_test_info().

344  {
345  AdHocTest();
346  return RUN_ALL_TESTS();
347 }
int RUN_ALL_TESTS() GTEST_MUST_USE_RESULT_
Definition: gtest.h:2232
void AdHocTest()
void SubWithoutTrace ( int  n)

Definition at line 167 of file gtest_output_test_.cc.

References ASSERT_EQ, and EXPECT_EQ.

Referenced by SubWithTrace(), and TEST().

167  {
168  EXPECT_EQ(1, n);
169  ASSERT_EQ(2, n);
170 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void SubWithTrace ( int  n)

Definition at line 173 of file gtest_output_test_.cc.

References SCOPED_TRACE, and SubWithoutTrace().

Referenced by TEST().

173  {
174  SCOPED_TRACE(testing::Message() << "n = " << n);
175 
176  SubWithoutTrace(n);
177 }
#define SCOPED_TRACE(message)
Definition: gtest.h:2115
void SubWithoutTrace(int n)
TEST ( PassingTest  ,
PassingTest1   
)

Definition at line 85 of file gtest_output_test_.cc.

Referenced by TEST().

85  {
86 }
TEST ( PassingTest  ,
PassingTest2   
)

Definition at line 88 of file gtest_output_test_.cc.

88  {
89 }
TEST ( NonfatalFailureTest  ,
EscapesStringOperands   
)

Definition at line 107 of file gtest_output_test_.cc.

References EXPECT_EQ, kGoldenString, and string.

107  {
108  std::string actual = "actual \"string\"";
109  EXPECT_EQ(kGoldenString, actual);
110 
111  const char* golden = kGoldenString;
112  EXPECT_EQ(golden, actual);
113 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const char * string
Definition: Conv.cpp:212
static const char kGoldenString[]
TEST ( NonfatalFailureTest  ,
DiffForLongStrings   
)

Definition at line 115 of file gtest_output_test_.cc.

References EXPECT_EQ, kGoldenString, and string.

115  {
116  std::string golden_str(kGoldenString, sizeof(kGoldenString) - 1);
117  EXPECT_EQ(golden_str, "Line 2");
118 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
const char * string
Definition: Conv.cpp:212
static const char kGoldenString[]
TEST ( FatalFailureTest  ,
FatalFailureInSubroutine   
)

Definition at line 121 of file gtest_output_test_.cc.

References TryTestSubroutine().

121  {
122  printf("(expecting a failure that x should be 1)\n");
123 
125 }
void TryTestSubroutine()
TEST ( FatalFailureTest  ,
FatalFailureInNestedSubroutine   
)

Definition at line 128 of file gtest_output_test_.cc.

References FAIL, and TryTestSubroutine().

128  {
129  printf("(expecting a failure that x should be 1)\n");
130 
131  // Calls a subrountine that yields a fatal failure.
133 
134  // Catches the fatal failure and aborts the test.
135  //
136  // When calling HasFatalFailure() inside a TEST, TEST_F, or test
137  // fixture, the testing::Test:: prefix is not needed.
138  if (HasFatalFailure()) return;
139 
140  // If we get here, something is wrong.
141  FAIL() << "This should never be reached.";
142 }
#define FAIL()
Definition: gtest.h:1822
void TryTestSubroutine()
TEST ( FatalFailureTest  ,
NonfatalFailureInSubroutine   
)

Definition at line 145 of file gtest_output_test_.cc.

References ASSERT_FALSE, and EXPECT_TRUE.

145  {
146  printf("(expecting a failure on false)\n");
147  EXPECT_TRUE(false); // Generates a nonfatal failure
148  ASSERT_FALSE(HasFatalFailure()); // This should succeed.
149 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define ASSERT_FALSE(condition)
Definition: gtest.h:1868
TEST ( LoggingTest  ,
InterleavingLoggingAndAssertions   
)

Definition at line 152 of file gtest_output_test_.cc.

References a, EXPECT_GE, and i.

152  {
153  static const int a[4] = {
154  3, 9, 2, 6
155  };
156 
157  printf("(expecting 2 failures on (3) >= (a[i]))\n");
158  for (int i = 0; i < static_cast<int>(sizeof(a)/sizeof(*a)); i++) {
159  printf("i == %d\n", i);
160  EXPECT_GE(3, a[i]);
161  }
162 }
#define EXPECT_GE(val1, val2)
Definition: gtest.h:1932
char a
TEST ( SCOPED_TRACETest  ,
ObeysScopes   
)

Definition at line 180 of file gtest_output_test_.cc.

References ADD_FAILURE, and SCOPED_TRACE.

180  {
181  printf("(expected to fail)\n");
182 
183  // There should be no trace before SCOPED_TRACE() is invoked.
184  ADD_FAILURE() << "This failure is expected, and shouldn't have a trace.";
185 
186  {
187  SCOPED_TRACE("Expected trace");
188  // After SCOPED_TRACE(), a failure in the current scope should contain
189  // the trace.
190  ADD_FAILURE() << "This failure is expected, and should have a trace.";
191  }
192 
193  // Once the control leaves the scope of the SCOPED_TRACE(), there
194  // should be no trace again.
195  ADD_FAILURE() << "This failure is expected, and shouldn't have a trace.";
196 }
#define SCOPED_TRACE(message)
Definition: gtest.h:2115
#define ADD_FAILURE()
Definition: gtest.h:1808
TEST ( SCOPED_TRACETest  ,
WorksInLoop   
)

Definition at line 199 of file gtest_output_test_.cc.

References i, SCOPED_TRACE, and SubWithoutTrace().

199  {
200  printf("(expected to fail)\n");
201 
202  for (int i = 1; i <= 2; i++) {
203  SCOPED_TRACE(testing::Message() << "i = " << i);
204 
206  }
207 }
#define SCOPED_TRACE(message)
Definition: gtest.h:2115
void SubWithoutTrace(int n)
TEST ( SCOPED_TRACETest  ,
WorksInSubroutine   
)

Definition at line 210 of file gtest_output_test_.cc.

References SubWithTrace().

210  {
211  printf("(expected to fail)\n");
212 
213  SubWithTrace(1);
214  SubWithTrace(2);
215 }
void SubWithTrace(int n)
TEST ( SCOPED_TRACETest  ,
CanBeNested   
)

Definition at line 218 of file gtest_output_test_.cc.

References SCOPED_TRACE, and SubWithTrace().

218  {
219  printf("(expected to fail)\n");
220 
221  SCOPED_TRACE(""); // A trace without a message.
222 
223  SubWithTrace(2);
224 }
#define SCOPED_TRACE(message)
Definition: gtest.h:2115
void SubWithTrace(int n)
TEST ( SCOPED_TRACETest  ,
CanBeRepeated   
)

Definition at line 227 of file gtest_output_test_.cc.

References ADD_FAILURE, SCOPED_TRACE, and TEST().

227  {
228  printf("(expected to fail)\n");
229 
230  SCOPED_TRACE("A");
231  ADD_FAILURE()
232  << "This failure is expected, and should contain trace point A.";
233 
234  SCOPED_TRACE("B");
235  ADD_FAILURE()
236  << "This failure is expected, and should contain trace point A and B.";
237 
238  {
239  SCOPED_TRACE("C");
240  ADD_FAILURE() << "This failure is expected, and should "
241  << "contain trace point A, B, and C.";
242  }
243 
244  SCOPED_TRACE("D");
245  ADD_FAILURE() << "This failure is expected, and should "
246  << "contain trace point A, B, and D.";
247 }
#define SCOPED_TRACE(message)
Definition: gtest.h:2115
#define ADD_FAILURE()
Definition: gtest.h:1808
TEST ( DisabledTestsWarningTest  ,
DISABLED_AlsoRunDisabledTestsFlagSuppressesWarning   
)

Definition at line 326 of file gtest_output_test_.cc.

327  {
328  // This test body is intentionally empty. Its sole purpose is for
329  // verifying that the --gtest_also_run_disabled_tests flag
330  // suppresses the "YOU HAVE 12 DISABLED TESTS" warning at the end of
331  // the test output.
332 }
TEST ( AddFailureAtTest  ,
MessageContainsSpecifiedFileAndLineNumber   
)

Definition at line 461 of file gtest_output_test_.cc.

References ADD_FAILURE_AT, GTEST_CHECK_, and GTEST_DISALLOW_COPY_AND_ASSIGN_.

461  {
462  ADD_FAILURE_AT("foo.cc", 42) << "Expected failure in foo.cc";
463 }
#define ADD_FAILURE_AT(file, line)
Definition: gtest.h:1812
TEST ( TEST_F_before_TEST_in_same_test_case  ,
DefinedUsingTESTAndShouldFail   
)

Definition at line 581 of file gtest_output_test_.cc.

581 {}
TEST ( TEST_before_TEST_F_in_same_test_case  ,
DefinedUsingTEST   
)

Definition at line 586 of file gtest_output_test_.cc.

586 {}
TEST ( ExpectNonfatalFailureTest  ,
CanReferenceGlobalVariables   
)

Definition at line 597 of file gtest_output_test_.cc.

References EXPECT_EQ, EXPECT_NONFATAL_FAILURE, and global_integer.

597  {
598  global_integer = 0;
600  EXPECT_EQ(1, global_integer) << "Expected non-fatal failure.";
601  }, "Expected non-fatal failure.");
602 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
int global_integer
#define EXPECT_NONFATAL_FAILURE(statement, substr)
Definition: gtest-spi.h:204
TEST ( ExpectNonfatalFailureTest  ,
CanReferenceLocalVariables   
)

Definition at line 606 of file gtest_output_test_.cc.

References EXPECT_EQ, EXPECT_NONFATAL_FAILURE, and m.

606  {
607  int m = 0;
608  static int n;
609  n = 1;
611  EXPECT_EQ(m, n) << "Expected non-fatal failure.";
612  }, "Expected non-fatal failure.");
613 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
static map< string, int > m
#define EXPECT_NONFATAL_FAILURE(statement, substr)
Definition: gtest-spi.h:204
TEST ( ExpectNonfatalFailureTest  ,
SucceedsWhenThereIsOneNonfatalFailure   
)

Definition at line 617 of file gtest_output_test_.cc.

References ADD_FAILURE, and EXPECT_NONFATAL_FAILURE.

617  {
619  ADD_FAILURE() << "Expected non-fatal failure.";
620  }, "Expected non-fatal failure.");
621 }
#define EXPECT_NONFATAL_FAILURE(statement, substr)
Definition: gtest-spi.h:204
#define ADD_FAILURE()
Definition: gtest.h:1808
TEST ( ExpectNonfatalFailureTest  ,
FailsWhenThereIsNoNonfatalFailure   
)

Definition at line 625 of file gtest_output_test_.cc.

References EXPECT_NONFATAL_FAILURE.

625  {
626  printf("(expecting a failure)\n");
628  }, "");
629 }
#define EXPECT_NONFATAL_FAILURE(statement, substr)
Definition: gtest-spi.h:204
TEST ( ExpectNonfatalFailureTest  ,
FailsWhenThereAreTwoNonfatalFailures   
)

Definition at line 633 of file gtest_output_test_.cc.

References ADD_FAILURE, and EXPECT_NONFATAL_FAILURE.

633  {
634  printf("(expecting a failure)\n");
636  ADD_FAILURE() << "Expected non-fatal failure 1.";
637  ADD_FAILURE() << "Expected non-fatal failure 2.";
638  }, "");
639 }
#define EXPECT_NONFATAL_FAILURE(statement, substr)
Definition: gtest-spi.h:204
#define ADD_FAILURE()
Definition: gtest.h:1808
TEST ( ExpectNonfatalFailureTest  ,
FailsWhenThereIsOneFatalFailure   
)

Definition at line 643 of file gtest_output_test_.cc.

References EXPECT_NONFATAL_FAILURE, and FAIL.

643  {
644  printf("(expecting a failure)\n");
646  FAIL() << "Expected fatal failure.";
647  }, "");
648 }
#define FAIL()
Definition: gtest.h:1822
#define EXPECT_NONFATAL_FAILURE(statement, substr)
Definition: gtest-spi.h:204
TEST ( ExpectNonfatalFailureTest  ,
FailsWhenStatementReturns   
)

Definition at line 652 of file gtest_output_test_.cc.

References EXPECT_NONFATAL_FAILURE, and TEST().

652  {
653  printf("(expecting a failure)\n");
655  return;
656  }, "");
657 }
#define EXPECT_NONFATAL_FAILURE(statement, substr)
Definition: gtest-spi.h:204
TEST ( ExpectFatalFailureTest  ,
CanReferenceGlobalVariables   
)

Definition at line 676 of file gtest_output_test_.cc.

References ASSERT_EQ, EXPECT_FATAL_FAILURE, and global_integer.

676  {
677  global_integer = 0;
679  ASSERT_EQ(1, global_integer) << "Expected fatal failure.";
680  }, "Expected fatal failure.");
681 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
int global_integer
#define EXPECT_FATAL_FAILURE(statement, substr)
Definition: gtest-spi.h:138
TEST ( ExpectFatalFailureTest  ,
CanReferenceLocalStaticVariables   
)

Definition at line 685 of file gtest_output_test_.cc.

References ASSERT_EQ, and EXPECT_FATAL_FAILURE.

685  {
686  static int n;
687  n = 1;
689  ASSERT_EQ(0, n) << "Expected fatal failure.";
690  }, "Expected fatal failure.");
691 }
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
#define EXPECT_FATAL_FAILURE(statement, substr)
Definition: gtest-spi.h:138
TEST ( ExpectFatalFailureTest  ,
SucceedsWhenThereIsOneFatalFailure   
)

Definition at line 695 of file gtest_output_test_.cc.

References EXPECT_FATAL_FAILURE, and FAIL.

695  {
697  FAIL() << "Expected fatal failure.";
698  }, "Expected fatal failure.");
699 }
#define FAIL()
Definition: gtest.h:1822
#define EXPECT_FATAL_FAILURE(statement, substr)
Definition: gtest-spi.h:138
TEST ( ExpectFatalFailureTest  ,
FailsWhenThereIsNoFatalFailure   
)

Definition at line 703 of file gtest_output_test_.cc.

References EXPECT_FATAL_FAILURE.

703  {
704  printf("(expecting a failure)\n");
706  }, "");
707 }
#define EXPECT_FATAL_FAILURE(statement, substr)
Definition: gtest-spi.h:138
TEST ( ExpectFatalFailureTest  ,
FailsWhenThereAreTwoFatalFailures   
)

Definition at line 716 of file gtest_output_test_.cc.

References EXPECT_FATAL_FAILURE, and FatalFailure().

716  {
717  printf("(expecting a failure)\n");
719  FatalFailure();
720  FatalFailure();
721  }, "");
722 }
#define EXPECT_FATAL_FAILURE(statement, substr)
Definition: gtest-spi.h:138
void FatalFailure()
TEST ( ExpectFatalFailureTest  ,
FailsWhenThereIsOneNonfatalFailure   
)

Definition at line 726 of file gtest_output_test_.cc.

References ADD_FAILURE, and EXPECT_FATAL_FAILURE.

726  {
727  printf("(expecting a failure)\n");
729  ADD_FAILURE() << "Expected non-fatal failure.";
730  }, "");
731 }
#define EXPECT_FATAL_FAILURE(statement, substr)
Definition: gtest-spi.h:138
#define ADD_FAILURE()
Definition: gtest.h:1808
TEST ( ExpectFatalFailureTest  ,
FailsWhenStatementReturns   
)

Definition at line 735 of file gtest_output_test_.cc.

References EXPECT_EQ, EXPECT_FATAL_FAILURE, deadlock::info(), INSTANTIATE_TEST_CASE_P(), INSTANTIATE_TYPED_TEST_CASE_P(), REGISTER_TYPED_TEST_CASE_P(), string, TEST(), TEST_P(), TYPED_TEST(), TYPED_TEST_CASE(), TYPED_TEST_CASE_P(), and TYPED_TEST_P().

735  {
736  printf("(expecting a failure)\n");
738  return;
739  }, "");
740 }
#define EXPECT_FATAL_FAILURE(statement, substr)
Definition: gtest-spi.h:138
TEST_F ( NonFatalFailureInFixtureConstructorTest  ,
FailureInConstructor   
)

Definition at line 370 of file gtest_output_test_.cc.

References ADD_FAILURE.

Referenced by TEST(), and TEST_F().

370  {
371  ADD_FAILURE() << "Expected failure #3, in the test body.";
372 }
#define ADD_FAILURE()
Definition: gtest.h:1808
TEST_F ( FatalFailureInFixtureConstructorTest  ,
FailureInConstructor   
)

Definition at line 404 of file gtest_output_test_.cc.

References ADD_FAILURE.

404  {
405  ADD_FAILURE() << "UNEXPECTED failure in the test body. "
406  << "We should never get here, as the test fixture c'tor "
407  << "had a fatal failure.";
408 }
#define ADD_FAILURE()
Definition: gtest.h:1808
TEST_F ( NonFatalFailureInSetUpTest  ,
FailureInSetUp   
)

Definition at line 431 of file gtest_output_test_.cc.

References FAIL.

431  {
432  FAIL() << "Expected failure #2, in the test function.";
433 }
#define FAIL()
Definition: gtest.h:1822
TEST_F ( FatalFailureInSetUpTest  ,
FailureInSetUp   
)

Definition at line 456 of file gtest_output_test_.cc.

References FAIL.

456  {
457  FAIL() << "UNEXPECTED failure in the test function. "
458  << "We should never get here, as SetUp() failed.";
459 }
#define FAIL()
Definition: gtest.h:1822
TEST_F ( TEST_F_before_TEST_in_same_test_case  ,
DefinedUsingTEST_F   
)

Definition at line 577 of file gtest_output_test_.cc.

577 {}
TEST_F ( TEST_before_TEST_F_in_same_test_case  ,
DefinedUsingTEST_FAndShouldFail   
)

Definition at line 590 of file gtest_output_test_.cc.

590  {
591 }
TEST_F ( ExpectFailureTest  ,
ExpectFatalFailure   
)

Definition at line 892 of file gtest_output_test_.cc.

References EXPECT_FATAL_FAILURE, and SUCCEED.

892  {
893  // Expected fatal failure, but succeeds.
894  printf("(expecting 1 failure)\n");
895  EXPECT_FATAL_FAILURE(SUCCEED(), "Expected fatal failure.");
896  // Expected fatal failure, but got a non-fatal failure.
897  printf("(expecting 1 failure)\n");
898  EXPECT_FATAL_FAILURE(AddFailure(NONFATAL_FAILURE), "Expected non-fatal "
899  "failure.");
900  // Wrong message.
901  printf("(expecting 1 failure)\n");
902  EXPECT_FATAL_FAILURE(AddFailure(FATAL_FAILURE), "Some other fatal failure "
903  "expected.");
904 }
#define SUCCEED()
Definition: gtest.h:1831
#define EXPECT_FATAL_FAILURE(statement, substr)
Definition: gtest-spi.h:138
TEST_F ( ExpectFailureTest  ,
ExpectNonFatalFailure   
)

Definition at line 906 of file gtest_output_test_.cc.

References EXPECT_EQ, EXPECT_FATAL_FAILURE, EXPECT_NONFATAL_FAILURE, SUCCEED, and TEST_F().

906  {
907  // Expected non-fatal failure, but succeeds.
908  printf("(expecting 1 failure)\n");
909  EXPECT_NONFATAL_FAILURE(SUCCEED(), "Expected non-fatal failure.");
910  // Expected non-fatal failure, but got a fatal failure.
911  printf("(expecting 1 failure)\n");
912  EXPECT_NONFATAL_FAILURE(AddFailure(FATAL_FAILURE), "Expected fatal failure.");
913  // Wrong message.
914  printf("(expecting 1 failure)\n");
915  EXPECT_NONFATAL_FAILURE(AddFailure(NONFATAL_FAILURE), "Some other non-fatal "
916  "failure.");
917 }
#define SUCCEED()
Definition: gtest.h:1831
#define EXPECT_NONFATAL_FAILURE(statement, substr)
Definition: gtest-spi.h:204
TEST_F ( ExpectFailureTest  ,
ExpectFatalFailureOnAllThreads   
)

Definition at line 963 of file gtest_output_test_.cc.

References EXPECT_FATAL_FAILURE_ON_ALL_THREADS, and SUCCEED.

963  {
964  // Expected fatal failure, but succeeds.
965  printf("(expecting 1 failure)\n");
966  EXPECT_FATAL_FAILURE_ON_ALL_THREADS(SUCCEED(), "Expected fatal failure.");
967  // Expected fatal failure, but got a non-fatal failure.
968  printf("(expecting 1 failure)\n");
969  EXPECT_FATAL_FAILURE_ON_ALL_THREADS(AddFailure(NONFATAL_FAILURE),
970  "Expected non-fatal failure.");
971  // Wrong message.
972  printf("(expecting 1 failure)\n");
973  EXPECT_FATAL_FAILURE_ON_ALL_THREADS(AddFailure(FATAL_FAILURE),
974  "Some other fatal failure expected.");
975 }
#define EXPECT_FATAL_FAILURE_ON_ALL_THREADS(statement, substr)
Definition: gtest-spi.h:155
#define SUCCEED()
Definition: gtest.h:1831
TEST_F ( ExpectFailureTest  ,
ExpectNonFatalFailureOnAllThreads   
)

Definition at line 977 of file gtest_output_test_.cc.

References EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS, and SUCCEED.

977  {
978  // Expected non-fatal failure, but succeeds.
979  printf("(expecting 1 failure)\n");
980  EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(SUCCEED(), "Expected non-fatal "
981  "failure.");
982  // Expected non-fatal failure, but got a fatal failure.
983  printf("(expecting 1 failure)\n");
984  EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(AddFailure(FATAL_FAILURE),
985  "Expected fatal failure.");
986  // Wrong message.
987  printf("(expecting 1 failure)\n");
988  EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(AddFailure(NONFATAL_FAILURE),
989  "Some other non-fatal failure.");
990 }
#define SUCCEED()
Definition: gtest.h:1831
#define EXPECT_NONFATAL_FAILURE_ON_ALL_THREADS(statement, substr)
Definition: gtest-spi.h:218
TEST_P ( FailingParamTest  ,
Fails   
)

Definition at line 95 of file gtest_output_test_.cc.

References EXPECT_EQ, and INSTANTIATE_TEST_CASE_P().

Referenced by TEST().

95  {
96  EXPECT_EQ(1, GetParam());
97 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void TestEq1 ( int  x)

Definition at line 65 of file gtest_output_test_.cc.

References ASSERT_EQ.

Referenced by TryTestSubroutine().

65  {
66  ASSERT_EQ(1, x);
67 }
Definition: InvokeTest.cpp:58
#define ASSERT_EQ(val1, val2)
Definition: gtest.h:1956
void TryTestSubroutine ( )

Definition at line 71 of file gtest_output_test_.cc.

References FAIL, testing::Test::HasFatalFailure(), and TestEq1().

Referenced by TEST().

71  {
72  // Calls a subrountine that yields a fatal failure.
73  TestEq1(2);
74 
75  // Catches the fatal failure and aborts the test.
76  //
77  // The testing::Test:: prefix is necessary when calling
78  // HasFatalFailure() outside of a TEST, TEST_F, or test fixture.
79  if (testing::Test::HasFatalFailure()) return;
80 
81  // If we get here, something is wrong.
82  FAIL() << "This should never be reached.";
83 }
static bool HasFatalFailure()
Definition: gtest.cc:2487
#define FAIL()
Definition: gtest.h:1822
void TestEq1(int x)

Variable Documentation

int global_integer = 0

Definition at line 594 of file gtest_output_test_.cc.

Referenced by TEST().

const char kGoldenString[] = "\"Line\0 1\"\nLine 2"
static

Definition at line 105 of file gtest_output_test_.cc.

Referenced by TEST().