Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
1edbcbad
Commit
1edbcbad
authored
Mar 12, 2013
by
zhanyong.wan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Prints a useful message when GetParam() is called in a non-parameterized test.
parent
6b7a167d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
1 deletion
+13
-1
gtest.h
include/gtest/gtest.h
+6
-1
gtest-param-test_test.cc
test/gtest-param-test_test.cc
+7
-0
No files found.
include/gtest/gtest.h
View file @
1edbcbad
...
@@ -1755,7 +1755,12 @@ class WithParamInterface {
...
@@ -1755,7 +1755,12 @@ class WithParamInterface {
// references static data, to reduce the opportunity for incorrect uses
// references static data, to reduce the opportunity for incorrect uses
// like writing 'WithParamInterface<bool>::GetParam()' for a test that
// like writing 'WithParamInterface<bool>::GetParam()' for a test that
// uses a fixture whose parameter type is int.
// 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
:
private
:
// Sets parameter value. The caller is responsible for making sure the value
// Sets parameter value. The caller is responsible for making sure the value
...
...
test/gtest-param-test_test.cc
View file @
1edbcbad
...
@@ -865,6 +865,13 @@ TEST_P(ParameterizedDerivedTest, SeesSequence) {
...
@@ -865,6 +865,13 @@ TEST_P(ParameterizedDerivedTest, SeesSequence) {
EXPECT_EQ
(
GetParam
(),
global_count_
++
);
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
));
INSTANTIATE_TEST_CASE_P
(
RangeZeroToFive
,
ParameterizedDerivedTest
,
Range
(
0
,
5
));
#endif // GTEST_HAS_PARAM_TEST
#endif // GTEST_HAS_PARAM_TEST
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment