Skip to content

Commit

Permalink
gtest_unittest: Call FAIL() in lambda, fix incorrect fatality expecta…
Browse files Browse the repository at this point in the history
…tion

FAIL() evaluates into a return statement: https://github.com/google/googletest/blob/5b909beeec178f338be997830b6c31a80cda7a93/googletest/include/gtest/internal/gtest-internal.h#L1347
Calling it from the body of the test case turns all subsequent expectations into no-ops.

Fixes #3941

PiperOrigin-RevId: 466104977
Change-Id: Ic15f43acb734295a5c9690a2b5eec6f65e8c0814
  • Loading branch information
dinord authored and copybara-github committed Aug 8, 2022
1 parent 5b909be commit 4c9a3bb
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions googletest/test/gtest_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3454,10 +3454,10 @@ TEST_F(NoFatalFailureTest, MessageIsStreamable) {
TestPartResultArray gtest_failures;
{
ScopedFakeTestPartResultReporter gtest_reporter(&gtest_failures);
EXPECT_NO_FATAL_FAILURE(FAIL() << "foo") << "my message";
EXPECT_NO_FATAL_FAILURE([] { FAIL() << "foo"; }()) << "my message";
}
ASSERT_EQ(2, gtest_failures.size());
EXPECT_EQ(TestPartResult::kNonFatalFailure,
EXPECT_EQ(TestPartResult::kFatalFailure,
gtest_failures.GetTestPartResult(0).type());
EXPECT_EQ(TestPartResult::kNonFatalFailure,
gtest_failures.GetTestPartResult(1).type());
Expand Down

0 comments on commit 4c9a3bb

Please sign in to comment.