This commit is contained in:
Anthony Graca 2025-03-29 21:54:13 +00:00 committed by GitHub
commit ad19c71de9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 38 additions and 1 deletions

View file

@ -301,6 +301,8 @@ void ReportUninterestingCall(CallReaction reaction, const std::string& msg) {
"knowing-when-to-expect-useoncall for details.\n",
stack_frames_to_skip);
break;
case kFail:
[[fallthrough]];
default: // FAIL
Expect(false, nullptr, -1, msg);
}

View file

@ -3274,6 +3274,8 @@ static const char* GetAnsiColorCode(GTestColor color) {
return "2";
case GTestColor::kYellow:
return "3";
case GTestColor::kDefault:
[[fallthrough]];
default:
assert(false);
return "9";
@ -3529,6 +3531,12 @@ void PrettyUnitTestResultPrinter::OnTestPartResult(
// If the test part succeeded, we don't need to do anything.
case TestPartResult::kSuccess:
return;
case TestPartResult::kNonFatalFailure:
[[fallthrough]];
case TestPartResult::kFatalFailure:
[[fallthrough]];
case TestPartResult::kSkip:
[[fallthrough]];
default:
// Print failure message from the assertion
// (e.g. expected this and got that).
@ -3747,6 +3755,12 @@ void BriefUnitTestResultPrinter::OnTestPartResult(
// If the test part succeeded, we don't need to do anything.
case TestPartResult::kSuccess:
return;
case TestPartResult::kNonFatalFailure:
[[fallthrough]];
case TestPartResult::kFatalFailure:
[[fallthrough]];
case TestPartResult::kSkip:
[[fallthrough]];
default:
// Print failure message from the assertion
// (e.g. expected this and got that).

View file

@ -154,7 +154,7 @@ TEST_F(StreamingListenerTest, OnTestEnd) {
EXPECT_EQ("event=TestEnd&passed=1&elapsed_time=0ms\n", *output());
}
TEST_F(StreamingListenerTest, OnTestPartResult) {
TEST_F(StreamingListenerTest, OnTestPartResultWithFatalFailure) {
*output() = "";
streamer_.OnTestPartResult(TestPartResult(TestPartResult::kFatalFailure,
"foo.cc", 42, "failed=\n&%"));
@ -165,6 +165,27 @@ TEST_F(StreamingListenerTest, OnTestPartResult) {
*output());
}
TEST_F(StreamingListenerTest, OnTestPartResultWithNonFatalFailure) {
*output() = "";
streamer_.OnTestPartResult(TestPartResult(
TestPartResult::kNonFatalFailure, "foo.cc", 42, "failed=\n&%"));
// Meta characters in the failure message should be properly escaped.
EXPECT_EQ(
"event=TestPartResult&file=foo.cc&line=42&message=failed%3D%0A%26%25\n",
*output());
}
TEST_F(StreamingListenerTest, OnTestPartResultWithSkip) {
*output() = "";
streamer_.OnTestPartResult(TestPartResult(
TestPartResult::kSkip, "foo.cc", 42, "failed=\n&%"));
// Meta characters in the failure message should be properly escaped.
EXPECT_EQ(
"event=TestPartResult&file=foo.cc&line=42&message=failed%3D%0A%26%25\n",
*output());
}
#endif // GTEST_CAN_STREAM_RESULTS_
// Provides access to otherwise private parts of the TestEventListeners class