mirror of
https://git.mirrors.martin98.com/https://github.com/google/googletest.git
synced 2025-06-03 19:04:24 +08:00
Add [[nodiscard]] to GetParam() to prevent accidental misuse.
This helps avoid a situation where someone sets up a parameterized test but forgets to actually use the parameter. PiperOrigin-RevId: 758455362 Change-Id: Ie4db03e82b6a4e1787be96f154b3fbb25657ae64
This commit is contained in:
parent
8b8ef3ff0d
commit
9f79a9597a
@ -1693,7 +1693,7 @@ class WithParamInterface {
|
||||
|
||||
// The current parameter value. Is also available in the test fixture's
|
||||
// constructor.
|
||||
static const ParamType& GetParam() {
|
||||
[[nodiscard]] static const ParamType& GetParam() {
|
||||
GTEST_CHECK_(parameter_ != nullptr)
|
||||
<< "GetParam() can only be called inside a value-parameterized test "
|
||||
<< "-- did you intend to write TEST_P instead of TEST_F?";
|
||||
|
@ -1174,7 +1174,7 @@ TEST_P(ParameterizedDerivedTest, SeesSequence) {
|
||||
class ParameterizedDeathTest : public ::testing::TestWithParam<int> {};
|
||||
|
||||
TEST_F(ParameterizedDeathTest, GetParamDiesFromTestF) {
|
||||
EXPECT_DEATH_IF_SUPPORTED(GetParam(), ".* value-parameterized test .*");
|
||||
EXPECT_DEATH_IF_SUPPORTED((void)GetParam(), ".* value-parameterized test .*");
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(RangeZeroToFive, ParameterizedDerivedTest,
|
||||
|
Loading…
x
Reference in New Issue
Block a user