summaryrefslogtreecommitdiff
path: root/test/gtest-param-test_test.cc
diff options
context:
space:
mode:
authorvladlosev <vladlosev@861a406c-534a-0410-8894-cb66d6ee9925>2010-05-18 21:13:48 +0000
committervladlosev <vladlosev@861a406c-534a-0410-8894-cb66d6ee9925>2010-05-18 21:13:48 +0000
commit3a6fc976eaf7f79a3e8212595ccf49d72d37335b (patch)
treef05da91adcf46a58df848555809eb74929096bab /test/gtest-param-test_test.cc
parent3232e6797752028fabe8daddd212e52f0ea76ee6 (diff)
downloadgoogletest-3a6fc976eaf7f79a3e8212595ccf49d72d37335b.tar.gz
Implements printing parameters of failed parameterized tests (issue 71).
git-svn-id: http://googletest.googlecode.com/svn/trunk@435 861a406c-534a-0410-8894-cb66d6ee9925
Diffstat (limited to 'test/gtest-param-test_test.cc')
-rw-r--r--test/gtest-param-test_test.cc39
1 files changed, 35 insertions, 4 deletions
diff --git a/test/gtest-param-test_test.cc b/test/gtest-param-test_test.cc
index d0a0e73..26acce4 100644
--- a/test/gtest-param-test_test.cc
+++ b/test/gtest-param-test_test.cc
@@ -792,19 +792,50 @@ INSTANTIATE_TEST_CASE_P(FourElemSequence, SeparateInstanceTest, Range(1, 4));
// sequence element used to instantiate the test.
class NamingTest : public TestWithParam<int> {};
-TEST_P(NamingTest, TestsAreNamedAppropriately) {
+TEST_P(NamingTest, TestsAreNamedAndCommentedCorrectly) {
const ::testing::TestInfo* const test_info =
::testing::UnitTest::GetInstance()->current_test_info();
EXPECT_STREQ("ZeroToFiveSequence/NamingTest", test_info->test_case_name());
- Message msg;
- msg << "TestsAreNamedAppropriately/" << GetParam();
- EXPECT_STREQ(msg.GetString().c_str(), test_info->name());
+ Message index_stream;
+ index_stream << "TestsAreNamedAndCommentedCorrectly/" << GetParam();
+ EXPECT_STREQ(index_stream.GetString().c_str(), test_info->name());
+
+ const ::std::string comment =
+ "GetParam() = " + ::testing::PrintToString(GetParam());
+ EXPECT_EQ(comment, test_info->comment());
}
INSTANTIATE_TEST_CASE_P(ZeroToFiveSequence, NamingTest, Range(0, 5));
+// Class that cannot be streamed into an ostream. It needs to be copyable
+// (and, in case of MSVC, also assignable) in order to be a test parameter
+// type. Its default copy constructor and assignment operator do exactly
+// what we need.
+class Unstreamable {
+ public:
+ explicit Unstreamable(int value) : value_(value) {}
+
+ private:
+ int value_;
+};
+
+class CommentTest : public TestWithParam<Unstreamable> {};
+
+TEST_P(CommentTest, TestsWithUnstreamableParamsCommentedCorrectly) {
+ const ::testing::TestInfo* const test_info =
+ ::testing::UnitTest::GetInstance()->current_test_info();
+
+ const ::std::string comment =
+ "GetParam() = " + ::testing::PrintToString(GetParam());
+ EXPECT_EQ(comment, test_info->comment());
+}
+
+INSTANTIATE_TEST_CASE_P(InstantiationWithComments,
+ CommentTest,
+ Values(Unstreamable(1)));
+
#endif // GTEST_HAS_PARAM_TEST
TEST(CompileTest, CombineIsDefinedOnlyWhenGtestHasParamTestIsDefined) {