From 9bcf4d0a654b27732e2fa901fe98c09aba71773a Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 2 Feb 2011 00:49:33 +0000 Subject: Adds type_param and value_param as attributes to the XML report; also removes the comment() and test_case_comment() fields of TestInfo. Proposed and initally implemented by Joey Oravec. Re-implemented by Vlad Losev. --- include/gtest/gtest.h | 50 +++++++++++++++------ include/gtest/internal/gtest-internal.h | 17 +++---- include/gtest/internal/gtest-param-util.h | 5 +-- src/gtest-internal-inl.h | 8 ++-- src/gtest.cc | 73 ++++++++++++++++++++----------- test/gtest-param-test_test.cc | 14 +++--- test/gtest-unittest-api_test.cc | 69 ++++++++++++++--------------- test/gtest_xml_output_unittest.py | 20 ++++++++- test/gtest_xml_output_unittest_.cc | 37 ++++++++++++++-- test/gtest_xml_test_utils.py | 11 ++++- 10 files changed, 200 insertions(+), 104 deletions(-) diff --git a/include/gtest/gtest.h b/include/gtest/gtest.h index 79e604c..741a360 100644 --- a/include/gtest/gtest.h +++ b/include/gtest/gtest.h @@ -634,11 +634,21 @@ class GTEST_API_ TestInfo { // Returns the test name. const char* name() const { return name_.c_str(); } - // Returns the test case comment. - const char* test_case_comment() const { return test_case_comment_.c_str(); } + // Returns the name of the parameter type, or NULL if this is not a typed + // or a type-parameterized test. + const char* type_param() const { + if (type_param_.get() != NULL) + return type_param_->c_str(); + return NULL; + } - // Returns the test comment. - const char* comment() const { return comment_.c_str(); } + // Returns the text representation of the value parameter, or NULL if this + // is not a value-parameterized test. + const char* value_param() const { + if (value_param_.get() != NULL) + return value_param_->c_str(); + return NULL; + } // Returns true if this test should run, that is if the test is not disabled // (or it is disabled but the also_run_disabled_tests flag has been specified) @@ -670,7 +680,8 @@ class GTEST_API_ TestInfo { friend class internal::UnitTestImpl; friend TestInfo* internal::MakeAndRegisterTestInfo( const char* test_case_name, const char* name, - const char* test_case_comment, const char* comment, + const char* type_param, + const char* value_param, internal::TypeId fixture_class_id, Test::SetUpTestCaseFunc set_up_tc, Test::TearDownTestCaseFunc tear_down_tc, @@ -679,7 +690,8 @@ class GTEST_API_ TestInfo { // Constructs a TestInfo object. The newly constructed instance assumes // ownership of the factory object. TestInfo(const char* test_case_name, const char* name, - const char* test_case_comment, const char* comment, + const char* a_type_param, + const char* a_value_param, internal::TypeId fixture_class_id, internal::TestFactoryBase* factory); @@ -700,8 +712,12 @@ class GTEST_API_ TestInfo { // These fields are immutable properties of the test. const std::string test_case_name_; // Test case name const std::string name_; // Test name - const std::string test_case_comment_; // Test case comment - const std::string comment_; // Test comment + // Name of the parameter type, or NULL if this is not a typed or a + // type-parameterized test. + const internal::scoped_ptr type_param_; + // Text representation of the value parameter, or NULL if this is not a + // value-parameterized test. + const internal::scoped_ptr value_param_; const internal::TypeId fixture_class_id_; // ID of the test fixture class bool should_run_; // True iff this test should run bool is_disabled_; // True iff this test is disabled @@ -730,9 +746,11 @@ class GTEST_API_ TestCase { // Arguments: // // name: name of the test case + // a_type_param: the name of the test's type parameter, or NULL if + // this is not a type-parameterized test. // set_up_tc: pointer to the function that sets up the test case // tear_down_tc: pointer to the function that tears down the test case - TestCase(const char* name, const char* comment, + TestCase(const char* name, const char* a_type_param, Test::SetUpTestCaseFunc set_up_tc, Test::TearDownTestCaseFunc tear_down_tc); @@ -742,8 +760,13 @@ class GTEST_API_ TestCase { // Gets the name of the TestCase. const char* name() const { return name_.c_str(); } - // Returns the test case comment. - const char* comment() const { return comment_.c_str(); } + // Returns the name of the parameter type, or NULL if this is not a + // type-parameterized test case. + const char* type_param() const { + if (type_param_.get() != NULL) + return type_param_->c_str(); + return NULL; + } // Returns true if any test in this test case should run. bool should_run() const { return should_run_; } @@ -846,8 +869,9 @@ class GTEST_API_ TestCase { // Name of the test case. internal::String name_; - // Comment on the test case. - internal::String comment_; + // Name of the parameter type, or NULL if this is not a typed or a + // type-parameterized test. + const internal::scoped_ptr type_param_; // The vector of TestInfos in their original order. It owns the // elements in the vector. std::vector test_info_list_; diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 2c08238..23fcef7 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -561,10 +561,10 @@ typedef void (*TearDownTestCaseFunc)(); // // test_case_name: name of the test case // name: name of the test -// test_case_comment: a comment on the test case that will be included in -// the test output -// comment: a comment on the test that will be included in the -// test output +// type_param the name of the test's type parameter, or NULL if +// this is not a typed or a type-parameterized test. +// value_param text representation of the test's value parameter, +// or NULL if this is not a type-parameterized test. // fixture_class_id: ID of the test fixture class // set_up_tc: pointer to the function that sets up the test case // tear_down_tc: pointer to the function that tears down the test case @@ -573,7 +573,8 @@ typedef void (*TearDownTestCaseFunc)(); // ownership of the factory object. GTEST_API_ TestInfo* MakeAndRegisterTestInfo( const char* test_case_name, const char* name, - const char* test_case_comment, const char* comment, + const char* type_param, + const char* value_param, TypeId fixture_class_id, SetUpTestCaseFunc set_up_tc, TearDownTestCaseFunc tear_down_tc, @@ -662,8 +663,8 @@ class TypeParameterizedTest { String::Format("%s%s%s/%d", prefix, prefix[0] == '\0' ? "" : "/", case_name, index).c_str(), GetPrefixUntilComma(test_names).c_str(), - String::Format("TypeParam = %s", GetTypeName().c_str()).c_str(), - "", + GetTypeName().c_str(), + NULL, // No value parameter. GetTypeId(), TestClass::SetUpTestCase, TestClass::TearDownTestCase, @@ -1197,7 +1198,7 @@ class GTEST_TEST_CLASS_NAME_(test_case_name, test_name) : public parent_class {\ ::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_case_name, test_name)\ ::test_info_ =\ ::testing::internal::MakeAndRegisterTestInfo(\ - #test_case_name, #test_name, "", "", \ + #test_case_name, #test_name, NULL, NULL, \ (parent_id), \ parent_class::SetUpTestCase, \ parent_class::TearDownTestCase, \ diff --git a/include/gtest/internal/gtest-param-util.h b/include/gtest/internal/gtest-param-util.h index d923b7d..61c3e37 100644 --- a/include/gtest/internal/gtest-param-util.h +++ b/include/gtest/internal/gtest-param-util.h @@ -505,12 +505,11 @@ class ParameterizedTestCaseInfo : public ParameterizedTestCaseInfoBase { param_it != generator.end(); ++param_it, ++i) { Message test_name_stream; test_name_stream << test_info->test_base_name.c_str() << "/" << i; - std::string comment = "GetParam() = " + PrintToString(*param_it); MakeAndRegisterTestInfo( test_case_name_stream.GetString().c_str(), test_name_stream.GetString().c_str(), - "", // test_case_comment - comment.c_str(), + NULL, // No type parameter. + PrintToString(*param_it).c_str(), GetTestCaseTypeId(), TestCase::SetUpTestCase, TestCase::TearDownTestCase, diff --git a/src/gtest-internal-inl.h b/src/gtest-internal-inl.h index e0f4af5..8629c6f 100644 --- a/src/gtest-internal-inl.h +++ b/src/gtest-internal-inl.h @@ -607,10 +607,12 @@ class GTEST_API_ UnitTestImpl { // Arguments: // // test_case_name: name of the test case + // type_param: the name of the test's type parameter, or NULL if + // this is not a typed or a type-parameterized test. // set_up_tc: pointer to the function that sets up the test case // tear_down_tc: pointer to the function that tears down the test case TestCase* GetTestCase(const char* test_case_name, - const char* comment, + const char* type_param, Test::SetUpTestCaseFunc set_up_tc, Test::TearDownTestCaseFunc tear_down_tc); @@ -623,7 +625,7 @@ class GTEST_API_ UnitTestImpl { // test_info: the TestInfo object void AddTestInfo(Test::SetUpTestCaseFunc set_up_tc, Test::TearDownTestCaseFunc tear_down_tc, - TestInfo * test_info) { + TestInfo* test_info) { // In order to support thread-safe death tests, we need to // remember the original working directory when the test program // was first invoked. We cannot do this in RUN_ALL_TESTS(), as @@ -638,7 +640,7 @@ class GTEST_API_ UnitTestImpl { } GetTestCase(test_info->test_case_name(), - test_info->test_case_comment(), + test_info->type_param(), set_up_tc, tear_down_tc)->AddTestInfo(test_info); } diff --git a/src/gtest.cc b/src/gtest.cc index 0e89d2b..575a8a5 100644 --- a/src/gtest.cc +++ b/src/gtest.cc @@ -2174,16 +2174,18 @@ bool Test::HasNonfatalFailure() { // Constructs a TestInfo object. It assumes ownership of the test factory // object. +// TODO(vladl@google.com): Make a_test_case_name and a_name const string&'s +// to signify they cannot be NULLs. TestInfo::TestInfo(const char* a_test_case_name, const char* a_name, - const char* a_test_case_comment, - const char* a_comment, + const char* a_type_param, + const char* a_value_param, internal::TypeId fixture_class_id, internal::TestFactoryBase* factory) : test_case_name_(a_test_case_name), name_(a_name), - test_case_comment_(a_test_case_comment), - comment_(a_comment), + type_param_(a_type_param ? new std::string(a_type_param) : NULL), + value_param_(a_value_param ? new std::string(a_value_param) : NULL), fixture_class_id_(fixture_class_id), should_run_(false), is_disabled_(false), @@ -2203,10 +2205,10 @@ namespace internal { // // test_case_name: name of the test case // name: name of the test -// test_case_comment: a comment on the test case that will be included in -// the test output -// comment: a comment on the test that will be included in the -// test output +// type_param: the name of the test's type parameter, or NULL if +// this is not a typed or a type-parameterized test. +// value_param: text representation of the test's value parameter, +// or NULL if this is not a value-parameterized test. // fixture_class_id: ID of the test fixture class // set_up_tc: pointer to the function that sets up the test case // tear_down_tc: pointer to the function that tears down the test case @@ -2215,13 +2217,14 @@ namespace internal { // ownership of the factory object. TestInfo* MakeAndRegisterTestInfo( const char* test_case_name, const char* name, - const char* test_case_comment, const char* comment, + const char* type_param, + const char* value_param, TypeId fixture_class_id, SetUpTestCaseFunc set_up_tc, TearDownTestCaseFunc tear_down_tc, TestFactoryBase* factory) { TestInfo* const test_info = - new TestInfo(test_case_name, name, test_case_comment, comment, + new TestInfo(test_case_name, name, type_param, value_param, fixture_class_id, factory); GetUnitTestImpl()->AddTestInfo(set_up_tc, tear_down_tc, test_info); return test_info; @@ -2370,13 +2373,15 @@ int TestCase::total_test_count() const { // Arguments: // // name: name of the test case +// a_type_param: the name of the test case's type parameter, or NULL if +// this is not a typed or a type-parameterized test case. // set_up_tc: pointer to the function that sets up the test case // tear_down_tc: pointer to the function that tears down the test case -TestCase::TestCase(const char* a_name, const char* a_comment, +TestCase::TestCase(const char* a_name, const char* a_type_param, Test::SetUpTestCaseFunc set_up_tc, Test::TearDownTestCaseFunc tear_down_tc) : name_(a_name), - comment_(a_comment), + type_param_(a_type_param ? new std::string(a_type_param) : NULL), set_up_tc_(set_up_tc), tear_down_tc_(tear_down_tc), should_run_(false), @@ -2648,15 +2653,19 @@ void ColoredPrintf(GTestColor color, const char* fmt, ...) { } void PrintFullTestCommentIfPresent(const TestInfo& test_info) { - const char* const comment = test_info.comment(); - const char* const test_case_comment = test_info.test_case_comment(); - - if (test_case_comment[0] != '\0' || comment[0] != '\0') { - printf(", where %s", test_case_comment); - if (test_case_comment[0] != '\0' && comment[0] != '\0') { - printf(" and "); + const char* const type_param = test_info.type_param(); + const char* const value_param = test_info.value_param(); + + if (type_param != NULL || value_param != NULL) { + printf(", where "); + if (type_param != NULL) { + printf("TypeParam = %s", type_param); + if (value_param != NULL) + printf(" and "); + } + if (value_param != NULL) { + printf("GetParam() = %s", value_param); } - printf("%s", comment); } } @@ -2739,10 +2748,10 @@ void PrettyUnitTestResultPrinter::OnTestCaseStart(const TestCase& test_case) { FormatCountableNoun(test_case.test_to_run_count(), "test", "tests"); ColoredPrintf(COLOR_GREEN, "[----------] "); printf("%s from %s", counts.c_str(), test_case_name_.c_str()); - if (test_case.comment()[0] == '\0') { + if (test_case.type_param() == NULL) { printf("\n"); } else { - printf(", where %s\n", test_case.comment()); + printf(", where TypeParam = %s\n", test_case.type_param()); } fflush(stdout); } @@ -3208,8 +3217,18 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream, const TestInfo& test_info) { const TestResult& result = *test_info.result(); *stream << " {}; -TEST_P(NamingTest, TestsAreNamedAndCommentedCorrectly) { +TEST_P(NamingTest, TestsReportCorrectNamesAndParameters) { const ::testing::TestInfo* const test_info = ::testing::UnitTest::GetInstance()->current_test_info(); EXPECT_STREQ("ZeroToFiveSequence/NamingTest", test_info->test_case_name()); Message index_stream; - index_stream << "TestsAreNamedAndCommentedCorrectly/" << GetParam(); + index_stream << "TestsReportCorrectNamesAndParameters/" << 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()); + EXPECT_EQ(::testing::PrintToString(GetParam()), test_info->value_param()); } INSTANTIATE_TEST_CASE_P(ZeroToFiveSequence, NamingTest, Range(0, 5)); @@ -823,13 +821,11 @@ class Unstreamable { class CommentTest : public TestWithParam {}; -TEST_P(CommentTest, TestsWithUnstreamableParamsCommentedCorrectly) { +TEST_P(CommentTest, TestsCorrectlyReportUnstreamableParams) { 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()); + EXPECT_EQ(::testing::PrintToString(GetParam()), test_info->value_param()); } INSTANTIATE_TEST_CASE_P(InstantiationWithComments, diff --git a/test/gtest-unittest-api_test.cc b/test/gtest-unittest-api_test.cc index ed5dea8..f53e274 100644 --- a/test/gtest-unittest-api_test.cc +++ b/test/gtest-unittest-api_test.cc @@ -37,6 +37,7 @@ #include // For strcmp. #include +#include using ::testing::InitGoogleTest; @@ -103,12 +104,6 @@ TYPED_TEST(TestCaseWithCommentTest, Dummy) {} const int kTypedTestCases = 1; const int kTypedTests = 1; - -String GetExpectedTestCaseComment() { - Message comment; - comment << "TypeParam = " << GetTypeName().c_str(); - return comment.GetString(); -} #else const int kTypedTestCases = 0; const int kTypedTests = 0; @@ -143,12 +138,19 @@ TEST(ApiTest, UnitTestImmutableAccessorsWork) { RecordProperty("key", "value"); } +AssertionResult IsNull(const char* str) { + if (str != NULL) { + return testing::AssertionFailure() << "argument is " << str; + } + return AssertionSuccess(); +} + TEST(ApiTest, TestCaseImmutableAccessorsWork) { const TestCase* test_case = UnitTestHelper::FindTestCase("ApiTest"); ASSERT_TRUE(test_case != NULL); EXPECT_STREQ("ApiTest", test_case->name()); - EXPECT_STREQ("", test_case->comment()); + EXPECT_TRUE(IsNull(test_case->type_param())); EXPECT_TRUE(test_case->should_run()); EXPECT_EQ(1, test_case->disabled_test_count()); EXPECT_EQ(3, test_case->test_to_run_count()); @@ -158,26 +160,26 @@ TEST(ApiTest, TestCaseImmutableAccessorsWork) { EXPECT_STREQ("DISABLED_Dummy1", tests[0]->name()); EXPECT_STREQ("ApiTest", tests[0]->test_case_name()); - EXPECT_STREQ("", tests[0]->comment()); - EXPECT_STREQ("", tests[0]->test_case_comment()); + EXPECT_TRUE(IsNull(tests[0]->value_param())); + EXPECT_TRUE(IsNull(tests[0]->type_param())); EXPECT_FALSE(tests[0]->should_run()); EXPECT_STREQ("TestCaseDisabledAccessorsWork", tests[1]->name()); EXPECT_STREQ("ApiTest", tests[1]->test_case_name()); - EXPECT_STREQ("", tests[1]->comment()); - EXPECT_STREQ("", tests[1]->test_case_comment()); + EXPECT_TRUE(IsNull(tests[1]->value_param())); + EXPECT_TRUE(IsNull(tests[1]->type_param())); EXPECT_TRUE(tests[1]->should_run()); EXPECT_STREQ("TestCaseImmutableAccessorsWork", tests[2]->name()); EXPECT_STREQ("ApiTest", tests[2]->test_case_name()); - EXPECT_STREQ("", tests[2]->comment()); - EXPECT_STREQ("", tests[2]->test_case_comment()); + EXPECT_TRUE(IsNull(tests[2]->value_param())); + EXPECT_TRUE(IsNull(tests[2]->type_param())); EXPECT_TRUE(tests[2]->should_run()); EXPECT_STREQ("UnitTestImmutableAccessorsWork", tests[3]->name()); EXPECT_STREQ("ApiTest", tests[3]->test_case_name()); - EXPECT_STREQ("", tests[3]->comment()); - EXPECT_STREQ("", tests[3]->test_case_comment()); + EXPECT_TRUE(IsNull(tests[3]->value_param())); + EXPECT_TRUE(IsNull(tests[3]->type_param())); EXPECT_TRUE(tests[3]->should_run()); delete[] tests; @@ -188,7 +190,7 @@ TEST(ApiTest, TestCaseImmutableAccessorsWork) { ASSERT_TRUE(test_case != NULL); EXPECT_STREQ("TestCaseWithCommentTest/0", test_case->name()); - EXPECT_STREQ(GetExpectedTestCaseComment().c_str(), test_case->comment()); + EXPECT_STREQ(GetTypeName().c_str(), test_case->type_param()); EXPECT_TRUE(test_case->should_run()); EXPECT_EQ(0, test_case->disabled_test_count()); EXPECT_EQ(1, test_case->test_to_run_count()); @@ -198,9 +200,8 @@ TEST(ApiTest, TestCaseImmutableAccessorsWork) { EXPECT_STREQ("Dummy", tests[0]->name()); EXPECT_STREQ("TestCaseWithCommentTest/0", tests[0]->test_case_name()); - EXPECT_STREQ("", tests[0]->comment()); - EXPECT_STREQ(GetExpectedTestCaseComment().c_str(), - tests[0]->test_case_comment()); + EXPECT_TRUE(IsNull(tests[0]->value_param())); + EXPECT_STREQ(GetTypeName().c_str(), tests[0]->type_param()); EXPECT_TRUE(tests[0]->should_run()); delete[] tests; @@ -212,7 +213,7 @@ TEST(ApiTest, TestCaseDisabledAccessorsWork) { ASSERT_TRUE(test_case != NULL); EXPECT_STREQ("DISABLED_Test", test_case->name()); - EXPECT_STREQ("", test_case->comment()); + EXPECT_TRUE(IsNull(test_case->type_param())); EXPECT_FALSE(test_case->should_run()); EXPECT_EQ(1, test_case->disabled_test_count()); EXPECT_EQ(0, test_case->test_to_run_count()); @@ -221,8 +222,8 @@ TEST(ApiTest, TestCaseDisabledAccessorsWork) { const TestInfo* const test_info = test_case->GetTestInfo(0); EXPECT_STREQ("Dummy2", test_info->name()); EXPECT_STREQ("DISABLED_Test", test_info->test_case_name()); - EXPECT_STREQ("", test_info->comment()); - EXPECT_STREQ("", test_info->test_case_comment()); + EXPECT_TRUE(IsNull(test_info->value_param())); + EXPECT_TRUE(IsNull(test_info->type_param())); EXPECT_FALSE(test_info->should_run()); } @@ -247,7 +248,7 @@ class FinalSuccessChecker : public Environment { const TestCase** const test_cases = UnitTestHelper::GetSortedTestCases(); EXPECT_STREQ("ApiTest", test_cases[0]->name()); - EXPECT_STREQ("", test_cases[0]->comment()); + EXPECT_TRUE(IsNull(test_cases[0]->type_param())); EXPECT_TRUE(test_cases[0]->should_run()); EXPECT_EQ(1, test_cases[0]->disabled_test_count()); ASSERT_EQ(4, test_cases[0]->total_test_count()); @@ -257,7 +258,7 @@ class FinalSuccessChecker : public Environment { EXPECT_FALSE(test_cases[0]->Failed()); EXPECT_STREQ("DISABLED_Test", test_cases[1]->name()); - EXPECT_STREQ("", test_cases[1]->comment()); + EXPECT_TRUE(IsNull(test_cases[1]->type_param())); EXPECT_FALSE(test_cases[1]->should_run()); EXPECT_EQ(1, test_cases[1]->disabled_test_count()); ASSERT_EQ(1, test_cases[1]->total_test_count()); @@ -266,8 +267,7 @@ class FinalSuccessChecker : public Environment { #if GTEST_HAS_TYPED_TEST EXPECT_STREQ("TestCaseWithCommentTest/0", test_cases[2]->name()); - EXPECT_STREQ(GetExpectedTestCaseComment().c_str(), - test_cases[2]->comment()); + EXPECT_STREQ(GetTypeName().c_str(), test_cases[2]->type_param()); EXPECT_TRUE(test_cases[2]->should_run()); EXPECT_EQ(0, test_cases[2]->disabled_test_count()); ASSERT_EQ(1, test_cases[2]->total_test_count()); @@ -285,24 +285,24 @@ class FinalSuccessChecker : public Environment { EXPECT_STREQ("TestCaseDisabledAccessorsWork", tests[1]->name()); EXPECT_STREQ("ApiTest", tests[1]->test_case_name()); - EXPECT_STREQ("", tests[1]->comment()); - EXPECT_STREQ("", tests[1]->test_case_comment()); + EXPECT_TRUE(IsNull(tests[1]->value_param())); + EXPECT_TRUE(IsNull(tests[1]->type_param())); EXPECT_TRUE(tests[1]->should_run()); EXPECT_TRUE(tests[1]->result()->Passed()); EXPECT_EQ(0, tests[1]->result()->test_property_count()); EXPECT_STREQ("TestCaseImmutableAccessorsWork", tests[2]->name()); EXPECT_STREQ("ApiTest", tests[2]->test_case_name()); - EXPECT_STREQ("", tests[2]->comment()); - EXPECT_STREQ("", tests[2]->test_case_comment()); + EXPECT_TRUE(IsNull(tests[2]->value_param())); + EXPECT_TRUE(IsNull(tests[2]->type_param())); EXPECT_TRUE(tests[2]->should_run()); EXPECT_TRUE(tests[2]->result()->Passed()); EXPECT_EQ(0, tests[2]->result()->test_property_count()); EXPECT_STREQ("UnitTestImmutableAccessorsWork", tests[3]->name()); EXPECT_STREQ("ApiTest", tests[3]->test_case_name()); - EXPECT_STREQ("", tests[3]->comment()); - EXPECT_STREQ("", tests[3]->test_case_comment()); + EXPECT_TRUE(IsNull(tests[3]->value_param())); + EXPECT_TRUE(IsNull(tests[3]->type_param())); EXPECT_TRUE(tests[3]->should_run()); EXPECT_TRUE(tests[3]->result()->Passed()); EXPECT_EQ(1, tests[3]->result()->test_property_count()); @@ -318,9 +318,8 @@ class FinalSuccessChecker : public Environment { EXPECT_STREQ("Dummy", tests[0]->name()); EXPECT_STREQ("TestCaseWithCommentTest/0", tests[0]->test_case_name()); - EXPECT_STREQ("", tests[0]->comment()); - EXPECT_STREQ(GetExpectedTestCaseComment().c_str(), - tests[0]->test_case_comment()); + EXPECT_TRUE(IsNull(tests[0]->value_param())); + EXPECT_STREQ(GetTypeName().c_str(), tests[0]->type_param()); EXPECT_TRUE(tests[0]->should_run()); EXPECT_TRUE(tests[0]->result()->Passed()); EXPECT_EQ(0, tests[0]->result()->test_property_count()); diff --git a/test/gtest_xml_output_unittest.py b/test/gtest_xml_output_unittest.py index 6d44929..bdd5035 100755 --- a/test/gtest_xml_output_unittest.py +++ b/test/gtest_xml_output_unittest.py @@ -54,7 +54,7 @@ else: STACK_TRACE_TEMPLATE = "" EXPECTED_NON_EMPTY_XML = """ - + @@ -105,6 +105,24 @@ Invalid characters in brackets []%(stack)s]]> + + + + + + + + + + + + + + + + + + """ % {'stack': STACK_TRACE_TEMPLATE} diff --git a/test/gtest_xml_output_unittest_.cc b/test/gtest_xml_output_unittest_.cc index 693ffb9..741a887 100644 --- a/test/gtest_xml_output_unittest_.cc +++ b/test/gtest_xml_output_unittest_.cc @@ -42,9 +42,13 @@ using ::testing::InitGoogleTest; using ::testing::TestEventListeners; +using ::testing::TestWithParam; using ::testing::UnitTest; +using ::testing::Test; +using ::testing::Types; +using ::testing::Values; -class SuccessfulTest : public testing::Test { +class SuccessfulTest : public Test { }; TEST_F(SuccessfulTest, Succeeds) { @@ -52,14 +56,14 @@ TEST_F(SuccessfulTest, Succeeds) { ASSERT_EQ(1, 1); } -class FailedTest : public testing::Test { +class FailedTest : public Test { }; TEST_F(FailedTest, Fails) { ASSERT_EQ(1, 2); } -class DisabledTest : public testing::Test { +class DisabledTest : public Test { }; TEST_F(DisabledTest, DISABLED_test_not_run) { @@ -91,7 +95,7 @@ TEST(InvalidCharactersTest, InvalidCharactersInMessage) { FAIL() << "Invalid characters in brackets [\x1\x2]"; } -class PropertyRecordingTest : public testing::Test { +class PropertyRecordingTest : public Test { }; TEST_F(PropertyRecordingTest, OneProperty) { @@ -134,6 +138,31 @@ TEST(NoFixtureTest, ExternalUtilityThatCallsRecordStringValuedProperty) { ExternalUtilityThatCallsRecordProperty("key_for_utility_string", "1"); } +// Verifies that the test parameter value is output in the 'value_param' +// XML attribute for value-parameterized tests. +class ValueParamTest : public TestWithParam {}; +TEST_P(ValueParamTest, HasValueParamAttribute) {} +TEST_P(ValueParamTest, AnotherTestThatHasValueParamAttribute) {} +INSTANTIATE_TEST_CASE_P(Single, ValueParamTest, Values(33, 42)); + +// Verifies that the type parameter name is output in the 'type_param' +// XML attribute for typed tests. +template class TypedTest : public Test {}; +typedef Types TypedTestTypes; +TYPED_TEST_CASE(TypedTest, TypedTestTypes); +TYPED_TEST(TypedTest, HasTypeParamAttribute) {} + +// Verifies that the type parameter name is output in the 'type_param' +// XML attribute for type-parameterized tests. +template class TypeParameterizedTestCase : public Test {}; +TYPED_TEST_CASE_P(TypeParameterizedTestCase); +TYPED_TEST_P(TypeParameterizedTestCase, HasTypeParamAttribute) {} +REGISTER_TYPED_TEST_CASE_P(TypeParameterizedTestCase, HasTypeParamAttribute); +typedef Types TypeParameterizedTestCaseTypes; +INSTANTIATE_TYPED_TEST_CASE_P(Single, + TypeParameterizedTestCase, + TypeParameterizedTestCaseTypes); + int main(int argc, char** argv) { InitGoogleTest(&argc, argv); diff --git a/test/gtest_xml_test_utils.py b/test/gtest_xml_test_utils.py index c83c3b7..0f55c16 100755 --- a/test/gtest_xml_test_utils.py +++ b/test/gtest_xml_test_utils.py @@ -58,8 +58,9 @@ class GTestXMLTestCase(gtest_test_utils.TestCase): * It has the same tag name as expected_node. * It has the same set of attributes as expected_node, each with the same value as the corresponding attribute of expected_node. - An exception is any attribute named "time", which needs only be - convertible to a floating-point number. + Exceptions are any attribute named "time", which needs only be + convertible to a floating-point number and any attribute named + "type_param" which only has to be non-empty. * It has an equivalent set of child nodes (including elements and CDATA sections) as expected_node. Note that we ignore the order of the children as they are not guaranteed to be in any @@ -150,6 +151,9 @@ class GTestXMLTestCase(gtest_test_utils.TestCase): * The "time" attribute of , and elements is replaced with a single asterisk, if it contains only digit characters. + * The "type_param" attribute of elements is replaced with a + single asterisk (if it sn non-empty) as it is the type name returned + by the compiler and is platform dependent. * The line number reported in the first line of the "message" attribute of elements is replaced with a single asterisk. * The directory names in file paths are removed. @@ -159,6 +163,9 @@ class GTestXMLTestCase(gtest_test_utils.TestCase): if element.tagName in ("testsuites", "testsuite", "testcase"): time = element.getAttributeNode("time") time.value = re.sub(r"^\d+(\.\d+)?$", "*", time.value) + type_param = element.getAttributeNode("type_param") + if type_param and type_param.value: + type_param.value = "*" elif element.tagName == "failure": for child in element.childNodes: if child.nodeType == Node.CDATA_SECTION_NODE: -- cgit v0.12