Prints a useful message when GetParam() is called in a non-parameterized test.
This commit is contained in:
parent
6b7a167dca
commit
1edbcbad73
@ -1755,7 +1755,12 @@ class WithParamInterface {
|
||||
// references static data, to reduce the opportunity for incorrect uses
|
||||
// like writing 'WithParamInterface<bool>::GetParam()' for a test that
|
||||
// uses a fixture whose parameter type is int.
|
||||
const ParamType& GetParam() const { return *parameter_; }
|
||||
const ParamType& GetParam() const {
|
||||
GTEST_CHECK_(parameter_ != NULL)
|
||||
<< "GetParam() can only be called inside a value-parameterized test "
|
||||
<< "-- did you intend to write TEST_P instead of TEST_F?";
|
||||
return *parameter_;
|
||||
}
|
||||
|
||||
private:
|
||||
// Sets parameter value. The caller is responsible for making sure the value
|
||||
|
@ -865,6 +865,13 @@ TEST_P(ParameterizedDerivedTest, SeesSequence) {
|
||||
EXPECT_EQ(GetParam(), global_count_++);
|
||||
}
|
||||
|
||||
class ParameterizedDeathTest : public ::testing::TestWithParam<int> { };
|
||||
|
||||
TEST_F(ParameterizedDeathTest, GetParamDiesFromTestF) {
|
||||
EXPECT_DEATH_IF_SUPPORTED(GetParam(),
|
||||
".* value-parameterized test .*");
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(RangeZeroToFive, ParameterizedDerivedTest, Range(0, 5));
|
||||
|
||||
#endif // GTEST_HAS_PARAM_TEST
|
||||
|
Loading…
Reference in New Issue
Block a user