From 1edbcbad73e0c711d5aa0f165bad5e9518894375 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Tue, 12 Mar 2013 21:17:22 +0000 Subject: Prints a useful message when GetParam() is called in a non-parameterized test. --- include/gtest/gtest.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'include/gtest') diff --git a/include/gtest/gtest.h b/include/gtest/gtest.h index 6d13ff65..e2f9a991 100644 --- a/include/gtest/gtest.h +++ b/include/gtest/gtest.h @@ -1755,7 +1755,12 @@ class WithParamInterface { // references static data, to reduce the opportunity for incorrect uses // like writing 'WithParamInterface::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 -- cgit v1.2.3