mirror of
https://github.com/google/googletest.git
synced 2025-12-21 19:14:55 +08:00
Applied C++ Core Guidelines Enum.2 Rule. Problem: switch statements should cover all cases. Solution: Added missing enumerations in switch statements and added [[fallthrough]] attribute to denote that the default case is the desired case for these missing enumerations.
This commit is contained in:
parent
16f637fbf4
commit
5864e885eb
@ -300,6 +300,8 @@ void ReportUninterestingCall(CallReaction reaction, const std::string& msg) {
|
|||||||
"knowing-when-to-expect for details.\n",
|
"knowing-when-to-expect for details.\n",
|
||||||
stack_frames_to_skip);
|
stack_frames_to_skip);
|
||||||
break;
|
break;
|
||||||
|
case kFail:
|
||||||
|
[[fallthrough]];
|
||||||
default: // FAIL
|
default: // FAIL
|
||||||
Expect(false, nullptr, -1, msg);
|
Expect(false, nullptr, -1, msg);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3254,6 +3254,8 @@ static const char* GetAnsiColorCode(GTestColor color) {
|
|||||||
return "2";
|
return "2";
|
||||||
case GTestColor::kYellow:
|
case GTestColor::kYellow:
|
||||||
return "3";
|
return "3";
|
||||||
|
case GTestColor::kDefault:
|
||||||
|
[[fallthrough]];
|
||||||
default:
|
default:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -3502,6 +3504,12 @@ void PrettyUnitTestResultPrinter::OnTestPartResult(
|
|||||||
// If the test part succeeded, we don't need to do anything.
|
// If the test part succeeded, we don't need to do anything.
|
||||||
case TestPartResult::kSuccess:
|
case TestPartResult::kSuccess:
|
||||||
return;
|
return;
|
||||||
|
case TestPartResult::kNonFatalFailure:
|
||||||
|
[[fallthrough]];
|
||||||
|
case TestPartResult::kFatalFailure:
|
||||||
|
[[fallthrough]];
|
||||||
|
case TestPartResult::kSkip:
|
||||||
|
[[fallthrough]];
|
||||||
default:
|
default:
|
||||||
// Print failure message from the assertion
|
// Print failure message from the assertion
|
||||||
// (e.g. expected this and got that).
|
// (e.g. expected this and got that).
|
||||||
@ -3719,6 +3727,12 @@ void BriefUnitTestResultPrinter::OnTestPartResult(
|
|||||||
// If the test part succeeded, we don't need to do anything.
|
// If the test part succeeded, we don't need to do anything.
|
||||||
case TestPartResult::kSuccess:
|
case TestPartResult::kSuccess:
|
||||||
return;
|
return;
|
||||||
|
case TestPartResult::kNonFatalFailure:
|
||||||
|
[[fallthrough]];
|
||||||
|
case TestPartResult::kFatalFailure:
|
||||||
|
[[fallthrough]];
|
||||||
|
case TestPartResult::kSkip:
|
||||||
|
[[fallthrough]];
|
||||||
default:
|
default:
|
||||||
// Print failure message from the assertion
|
// Print failure message from the assertion
|
||||||
// (e.g. expected this and got that).
|
// (e.g. expected this and got that).
|
||||||
|
|||||||
@ -146,6 +146,38 @@ TEST_F(StreamingListenerTest, OnTestPartResult) {
|
|||||||
*output());
|
*output());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(StreamingListenerTest, OnTestPartResult) {
|
||||||
|
*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, OnTestPartResult) {
|
||||||
|
*output() = "";
|
||||||
|
streamer_.OnTestPartResult(TestPartResult(
|
||||||
|
TestPartResult::kFatalFailure, "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, OnTestPartResult) {
|
||||||
|
*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_
|
#endif // GTEST_CAN_STREAM_RESULTS_
|
||||||
|
|
||||||
// Provides access to otherwise private parts of the TestEventListeners class
|
// Provides access to otherwise private parts of the TestEventListeners class
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user