summaryrefslogtreecommitdiffstats
path: root/googletest
diff options
context:
space:
mode:
authorMark Barolak <mbar@google.com>2020-06-26 16:03:26 (GMT)
committerMark Barolak <mbar@google.com>2020-06-26 16:03:26 (GMT)
commit5e0cf72b7cd0ee0b1d66308da708c103caadce51 (patch)
treec7308fd2fc738d87b55af098f10d30fe0273a760 /googletest
parent62f388e15fb0a3ece2506096e30b4ec8fb861020 (diff)
parentff4872659a5ef73012e197d6507f7eb76b888cff (diff)
downloadgoogletest-5e0cf72b7cd0ee0b1d66308da708c103caadce51.zip
googletest-5e0cf72b7cd0ee0b1d66308da708c103caadce51.tar.gz
googletest-5e0cf72b7cd0ee0b1d66308da708c103caadce51.tar.bz2
Merge pull request #2718 from NINI1988:master
PiperOrigin-RevId: 317696457
Diffstat (limited to 'googletest')
-rw-r--r--googletest/CMakeLists.txt3
-rw-r--r--googletest/include/gtest/gtest-param-test.h3
-rw-r--r--googletest/include/gtest/internal/gtest-param-util.h16
-rw-r--r--googletest/test/gtest_list_output_unittest.py154
-rw-r--r--googletest/test/gtest_list_output_unittest_.cc30
5 files changed, 194 insertions, 12 deletions
diff --git a/googletest/CMakeLists.txt b/googletest/CMakeLists.txt
index f538c96..cf63c60 100644
--- a/googletest/CMakeLists.txt
+++ b/googletest/CMakeLists.txt
@@ -320,6 +320,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 5b039df..9a60b76 100644
--- a/googletest/include/gtest/gtest-param-test.h
+++ b/googletest/include/gtest/gtest-param-test.h
@@ -428,7 +428,8 @@ internal::CartesianProductHolder<Generator...> Combine(const Generator&... g) {
->AddTestPattern( \
GTEST_STRINGIFY_(test_suite_name), GTEST_STRINGIFY_(test_name), \
new ::testing::internal::TestMetaFactory<GTEST_TEST_CLASS_NAME_( \
- test_suite_name, test_name)>()); \
+ 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 7f7a13b..f26d7d1 100644
--- a/googletest/include/gtest/internal/gtest-param-util.h
+++ b/googletest/include/gtest/internal/gtest-param-util.h
@@ -520,9 +520,10 @@ 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<ParamType>* meta_factory) {
- tests_.push_back(std::shared_ptr<TestInfo>(
- new TestInfo(test_suite_name, test_base_name, meta_factory)));
+ TestMetaFactoryBase<ParamType>* meta_factory,
+ CodeLocation code_location) {
+ tests_.push_back(std::shared_ptr<TestInfo>(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 +590,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(), code_location_,
+ PrintToString(*param_it).c_str(), test_info->code_location,
GetTestSuiteTypeId(),
SuiteApiResolver<TestSuite>::GetSetUpCaseOrSuite(file, line),
SuiteApiResolver<TestSuite>::GetTearDownCaseOrSuite(file, line),
@@ -610,14 +611,17 @@ 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<ParamType>* a_test_meta_factory)
+ TestMetaFactoryBase<ParamType>* 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) {}
+ test_meta_factory(a_test_meta_factory),
+ code_location(a_code_location) {}
const std::string test_suite_base_name;
const std::string test_base_name;
const std::unique_ptr<TestMetaFactoryBase<ParamType> > test_meta_factory;
+ const CodeLocation code_location;
};
using TestInfoContainer = ::std::vector<std::shared_ptr<TestInfo> >;
// 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 3bba7ea..396c04c 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"\?>
-<testsuites tests="2" name="AllTests">
+<testsuites tests="16" name="AllTests">
<testsuite name="FooTest" tests="2">
<testcase name="Test1" file=".*gtest_list_output_unittest_.cc" line="43" />
<testcase name="Test2" file=".*gtest_list_output_unittest_.cc" line="45" />
</testsuite>
+ <testsuite name="FooTestFixture" tests="2">
+ <testcase name="Test3" file=".*gtest_list_output_unittest_.cc" line="48" />
+ <testcase name="Test4" file=".*gtest_list_output_unittest_.cc" line="49" />
+ </testsuite>
+ <testsuite name="TypedTest/0" tests="2">
+ <testcase name="Test7" type_param="int" file=".*gtest_list_output_unittest_.cc" line="60" />
+ <testcase name="Test8" type_param="int" file=".*gtest_list_output_unittest_.cc" line="61" />
+ </testsuite>
+ <testsuite name="TypedTest/1" tests="2">
+ <testcase name="Test7" type_param="bool" file=".*gtest_list_output_unittest_.cc" line="60" />
+ <testcase name="Test8" type_param="bool" file=".*gtest_list_output_unittest_.cc" line="61" />
+ </testsuite>
+ <testsuite name="Single/TypeParameterizedTestSuite/0" tests="2">
+ <testcase name="Test9" type_param="int" file=".*gtest_list_output_unittest_.cc" line="68" />
+ <testcase name="Test10" type_param="int" file=".*gtest_list_output_unittest_.cc" line="69" />
+ </testsuite>
+ <testsuite name="Single/TypeParameterizedTestSuite/1" tests="2">
+ <testcase name="Test9" type_param="bool" file=".*gtest_list_output_unittest_.cc" line="68" />
+ <testcase name="Test10" type_param="bool" file=".*gtest_list_output_unittest_.cc" line="69" />
+ </testsuite>
+ <testsuite name="ValueParam/ValueParamTest" tests="4">
+ <testcase name="Test5/0" value_param="33" file=".*gtest_list_output_unittest_.cc" line="52" />
+ <testcase name="Test5/1" value_param="42" file=".*gtest_list_output_unittest_.cc" line="52" />
+ <testcase name="Test6/0" value_param="33" file=".*gtest_list_output_unittest_.cc" line="53" />
+ <testcase name="Test6/1" value_param="42" file=".*gtest_list_output_unittest_.cc" line="53" />
+ </testsuite>
</testsuites>
"""
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": "bool",
+ "file": ".*gtest_list_output_unittest_.cc",
+ "line": 60
+ },
+ {
+ "name": "Test8",
+ "type_param": "bool",
+ "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": "bool",
+ "file": ".*gtest_list_output_unittest_.cc",
+ "line": 68
+ },
+ {
+ "name": "Test10",
+ "type_param": "bool",
+ "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 b1c7b4d..2eea3eb 100644
--- a/googletest/test/gtest_list_output_unittest_.cc
+++ b/googletest/test/gtest_list_output_unittest_.cc
@@ -44,6 +44,36 @@ TEST(FooTest, Test1) {}
TEST(FooTest, Test2) {}
+class FooTestFixture : public ::testing::Test {};
+TEST_F(FooTestFixture, Test3) {}
+TEST_F(FooTestFixture, Test4) {}
+
+class ValueParamTest : public ::testing::TestWithParam<int> {};
+TEST_P(ValueParamTest, Test5) {}
+TEST_P(ValueParamTest, Test6) {}
+INSTANTIATE_TEST_SUITE_P(ValueParam, ValueParamTest, ::testing::Values(33, 42));
+
+#if GTEST_HAS_TYPED_TEST
+template <typename T>
+class TypedTest : public ::testing::Test {};
+typedef testing::Types<int, bool> TypedTestTypes;
+TYPED_TEST_SUITE(TypedTest, TypedTestTypes);
+TYPED_TEST(TypedTest, Test7) {}
+TYPED_TEST(TypedTest, Test8) {}
+#endif
+
+#if GTEST_HAS_TYPED_TEST_P
+template <typename T>
+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<int, bool> TypeParameterizedTestSuiteTypes; // NOLINT
+INSTANTIATE_TYPED_TEST_SUITE_P(Single, TypeParameterizedTestSuite,
+ TypeParameterizedTestSuiteTypes);
+#endif
+
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);