diff options
author | vladlosev <vladlosev@861a406c-534a-0410-8894-cb66d6ee9925> | 2010-05-18 21:13:48 +0000 |
---|---|---|
committer | vladlosev <vladlosev@861a406c-534a-0410-8894-cb66d6ee9925> | 2010-05-18 21:13:48 +0000 |
commit | 1097b54dcf1cd393e64ec0adf54301a575bbbc1c (patch) | |
tree | f05da91adcf46a58df848555809eb74929096bab /test/gtest-param-test_test.cc | |
parent | c828e171752e67ebba33197ba758a4f24188efcf (diff) | |
download | googletest-1097b54dcf1cd393e64ec0adf54301a575bbbc1c.tar.gz googletest-1097b54dcf1cd393e64ec0adf54301a575bbbc1c.tar.bz2 googletest-1097b54dcf1cd393e64ec0adf54301a575bbbc1c.zip |
Implements printing parameters of failed parameterized tests (issue 71).
Diffstat (limited to 'test/gtest-param-test_test.cc')
-rw-r--r-- | test/gtest-param-test_test.cc | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/test/gtest-param-test_test.cc b/test/gtest-param-test_test.cc index d0a0e735..26acce4c 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) { |