From ff4872659a5ef73012e197d6507f7eb76b888cff Mon Sep 17 00:00:00 2001 From: NINI1988 Date: Fri, 21 Feb 2020 17:51:29 +0100 Subject: [PATCH] Add missing call for gtest_list_output_unittest_ unitTest. Add unitTest for fixed TEST_P line number. Use CodeLocation TestInfo struct. --- googletest/CMakeLists.txt | 3 + googletest/include/gtest/gtest-param-test.h | 3 +- .../include/gtest/internal/gtest-param-util.h | 12 +- googletest/test/gtest_list_output_unittest.py | 154 +++++++++++++++++- .../test/gtest_list_output_unittest_.cc | 29 ++++ 5 files changed, 189 insertions(+), 12 deletions(-) diff --git a/googletest/CMakeLists.txt b/googletest/CMakeLists.txt index 4fd7b526..9958f760 100644 --- a/googletest/CMakeLists.txt +++ b/googletest/CMakeLists.txt @@ -318,6 +318,9 @@ $env:Path = \"$project_bin;$env:Path\" cxx_executable(googletest-uninitialized-test_ test gtest) py_test(googletest-uninitialized-test) + cxx_executable(gtest_list_output_unittest_ test gtest) + py_test(gtest_list_output_unittest) + cxx_executable(gtest_xml_outfile1_test_ test gtest_main) cxx_executable(gtest_xml_outfile2_test_ test gtest_main) py_test(gtest_xml_outfiles_test) diff --git a/googletest/include/gtest/gtest-param-test.h b/googletest/include/gtest/gtest-param-test.h index 90a44aaf..7aa04807 100644 --- a/googletest/include/gtest/gtest-param-test.h +++ b/googletest/include/gtest/gtest-param-test.h @@ -428,7 +428,8 @@ internal::CartesianProductHolder Combine(const Generator&... g) { ->AddTestPattern( \ GTEST_STRINGIFY_(test_suite_name), GTEST_STRINGIFY_(test_name), \ new ::testing::internal::TestMetaFactory(), __LINE__); \ + test_suite_name, test_name)>(), \ + ::testing::internal::CodeLocation(__FILE__, __LINE__)); \ return 0; \ } \ static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \ diff --git a/googletest/include/gtest/internal/gtest-param-util.h b/googletest/include/gtest/internal/gtest-param-util.h index dfc30186..2b8b2729 100644 --- a/googletest/include/gtest/internal/gtest-param-util.h +++ b/googletest/include/gtest/internal/gtest-param-util.h @@ -520,9 +520,9 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase { // parameter index. For the test SequenceA/FooTest.DoBar/1 FooTest is // test suite base name and DoBar is test base name. void AddTestPattern(const char* test_suite_name, const char* test_base_name, - TestMetaFactoryBase* meta_factory, int line) { + TestMetaFactoryBase* meta_factory, CodeLocation code_location) { tests_.push_back(std::shared_ptr( - new TestInfo(test_suite_name, test_base_name, meta_factory, line))); + new TestInfo(test_suite_name, test_base_name, meta_factory, code_location))); } // INSTANTIATE_TEST_SUITE_P macro uses AddGenerator() to record information // about a generator. @@ -589,7 +589,7 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase { MakeAndRegisterTestInfo( test_suite_name.c_str(), test_name_stream.GetString().c_str(), nullptr, // No type parameter. - PrintToString(*param_it).c_str(), CodeLocation(code_location_.file, test_info->line), + PrintToString(*param_it).c_str(), test_info->code_location, GetTestSuiteTypeId(), SuiteApiResolver::GetSetUpCaseOrSuite(file, line), SuiteApiResolver::GetTearDownCaseOrSuite(file, line), @@ -610,16 +610,16 @@ class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase { // with TEST_P macro. struct TestInfo { TestInfo(const char* a_test_suite_base_name, const char* a_test_base_name, - TestMetaFactoryBase* a_test_meta_factory, int a_line) + TestMetaFactoryBase* a_test_meta_factory, CodeLocation a_code_location) : test_suite_base_name(a_test_suite_base_name), test_base_name(a_test_base_name), test_meta_factory(a_test_meta_factory), - line(a_line) {} + code_location(a_code_location) {} const std::string test_suite_base_name; const std::string test_base_name; const std::unique_ptr > test_meta_factory; - const int line; + const CodeLocation code_location; }; using TestInfoContainer = ::std::vector >; // Records data received from INSTANTIATE_TEST_SUITE_P macros: diff --git a/googletest/test/gtest_list_output_unittest.py b/googletest/test/gtest_list_output_unittest.py index 3bba7ea2..6f97f828 100644 --- a/googletest/test/gtest_list_output_unittest.py +++ b/googletest/test/gtest_list_output_unittest.py @@ -46,16 +46,42 @@ GTEST_LIST_TESTS_FLAG = '--gtest_list_tests' GTEST_OUTPUT_FLAG = '--gtest_output' EXPECTED_XML = """<\?xml version="1.0" encoding="UTF-8"\?> - + + + + + + + + + + + + + + + + + + + + + + + + + + + """ EXPECTED_JSON = """{ - "tests": 2, + "tests": 16, "name": "AllTests", "testsuites": \[ { @@ -73,6 +99,124 @@ EXPECTED_JSON = """{ "line": 45 } \] + }, + { + "name": "FooTestFixture", + "tests": 2, + "testsuite": \[ + { + "name": "Test3", + "file": ".*gtest_list_output_unittest_.cc", + "line": 48 + }, + { + "name": "Test4", + "file": ".*gtest_list_output_unittest_.cc", + "line": 49 + } + \] + }, + { + "name": "TypedTest\\\\/0", + "tests": 2, + "testsuite": \[ + { + "name": "Test7", + "type_param": "int", + "file": ".*gtest_list_output_unittest_.cc", + "line": 60 + }, + { + "name": "Test8", + "type_param": "int", + "file": ".*gtest_list_output_unittest_.cc", + "line": 61 + } + \] + }, + { + "name": "TypedTest\\\\/1", + "tests": 2, + "testsuite": \[ + { + "name": "Test7", + "type_param": "long", + "file": ".*gtest_list_output_unittest_.cc", + "line": 60 + }, + { + "name": "Test8", + "type_param": "long", + "file": ".*gtest_list_output_unittest_.cc", + "line": 61 + } + \] + }, + { + "name": "Single\\\\/TypeParameterizedTestSuite\\\\/0", + "tests": 2, + "testsuite": \[ + { + "name": "Test9", + "type_param": "int", + "file": ".*gtest_list_output_unittest_.cc", + "line": 68 + }, + { + "name": "Test10", + "type_param": "int", + "file": ".*gtest_list_output_unittest_.cc", + "line": 69 + } + \] + }, + { + "name": "Single\\\\/TypeParameterizedTestSuite\\\\/1", + "tests": 2, + "testsuite": \[ + { + "name": "Test9", + "type_param": "long", + "file": ".*gtest_list_output_unittest_.cc", + "line": 68 + }, + { + "name": "Test10", + "type_param": "long", + "file": ".*gtest_list_output_unittest_.cc", + "line": 69 + } + \] + }, + { + "name": "ValueParam\\\\/ValueParamTest", + "tests": 4, + "testsuite": \[ + { + "name": "Test5\\\\/0", + "value_param": "33", + "file": ".*gtest_list_output_unittest_.cc", + "line": 52 + }, + { + "name": "Test5\\\\/1", + "value_param": "42", + "file": ".*gtest_list_output_unittest_.cc", + "line": 52 + }, + { + "name": "Test6\\\\/0", + "value_param": "33", + "file": ".*gtest_list_output_unittest_.cc", + "line": 53 + }, + { + "name": "Test6\\\\/1", + "value_param": "42", + "file": ".*gtest_list_output_unittest_.cc", + "line": 53 + } + \] } \] } @@ -114,8 +258,8 @@ class GTestListTestsOutputUnitTest(gtest_test_utils.TestCase): p = gtest_test_utils.Subprocess( command, env=environ_copy, working_dir=gtest_test_utils.GetTempDir()) - self.assert_(p.exited) - self.assertEquals(0, p.exit_code) + self.assertTrue(p.exited) + self.assertEqual(0, p.exit_code) with open(file_path) as f: result = f.read() return result @@ -128,7 +272,7 @@ class GTestListTestsOutputUnitTest(gtest_test_utils.TestCase): for actual_line in actual_lines: expected_line = expected_lines[line_count] expected_line_re = re.compile(expected_line.strip()) - self.assert_( + self.assertTrue( expected_line_re.match(actual_line.strip()), ('actual output of "%s",\n' 'which does not match expected regex of "%s"\n' diff --git a/googletest/test/gtest_list_output_unittest_.cc b/googletest/test/gtest_list_output_unittest_.cc index b1c7b4de..f392bf6b 100644 --- a/googletest/test/gtest_list_output_unittest_.cc +++ b/googletest/test/gtest_list_output_unittest_.cc @@ -44,6 +44,35 @@ TEST(FooTest, Test1) {} TEST(FooTest, Test2) {} +class FooTestFixture : public ::testing::Test {}; +TEST_F(FooTestFixture, Test3) {} +TEST_F(FooTestFixture, Test4) {} + +class ValueParamTest : public ::testing::TestWithParam {}; +TEST_P(ValueParamTest, Test5) {} +TEST_P(ValueParamTest, Test6) {} +INSTANTIATE_TEST_SUITE_P(ValueParam, ValueParamTest, ::testing::Values(33, 42)); + +#if GTEST_HAS_TYPED_TEST +template class TypedTest : public ::testing::Test {}; +typedef testing::Types TypedTestTypes; +TYPED_TEST_SUITE(TypedTest, TypedTestTypes); +TYPED_TEST(TypedTest, Test7) {} +TYPED_TEST(TypedTest, Test8) {} +#endif + +#if GTEST_HAS_TYPED_TEST_P +template +class TypeParameterizedTestSuite : public ::testing::Test {}; +TYPED_TEST_SUITE_P(TypeParameterizedTestSuite); +TYPED_TEST_P(TypeParameterizedTestSuite, Test9) {} +TYPED_TEST_P(TypeParameterizedTestSuite, Test10) {} +REGISTER_TYPED_TEST_SUITE_P(TypeParameterizedTestSuite, Test9, Test10); +typedef testing::Types TypeParameterizedTestSuiteTypes; // NOLINT +INSTANTIATE_TYPED_TEST_SUITE_P(Single, TypeParameterizedTestSuite, + TypeParameterizedTestSuiteTypes); +#endif + int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv);