Add missing call for gtest_list_output_unittest_ unitTest.

Add unitTest for fixed TEST_P line number.
Use CodeLocation TestInfo struct.
This commit is contained in:
NINI1988 2020-02-21 17:51:29 +01:00
parent 25385c23e9
commit ff4872659a
5 changed files with 189 additions and 12 deletions

View File

@ -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)

View File

@ -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)>(), __LINE__); \
test_suite_name, test_name)>(), \
::testing::internal::CodeLocation(__FILE__, __LINE__)); \
return 0; \
} \
static int gtest_registering_dummy_ GTEST_ATTRIBUTE_UNUSED_; \

View File

@ -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<ParamType>* meta_factory, int line) {
TestMetaFactoryBase<ParamType>* meta_factory, CodeLocation code_location) {
tests_.push_back(std::shared_ptr<TestInfo>(
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<TestSuite>::GetSetUpCaseOrSuite(file, line),
SuiteApiResolver<TestSuite>::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<ParamType>* a_test_meta_factory, int a_line)
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),
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<TestMetaFactoryBase<ParamType> > test_meta_factory;
const int line;
const CodeLocation code_location;
};
using TestInfoContainer = ::std::vector<std::shared_ptr<TestInfo> >;
// Records data received from INSTANTIATE_TEST_SUITE_P macros:

View File

@ -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="long" file=".*gtest_list_output_unittest_.cc" line="60" />
<testcase name="Test8" type_param="long" 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="long" file=".*gtest_list_output_unittest_.cc" line="68" />
<testcase name="Test10" type_param="long" 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": "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'

View File

@ -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<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, long> 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, long> TypeParameterizedTestSuiteTypes; // NOLINT
INSTANTIATE_TYPED_TEST_SUITE_P(Single, TypeParameterizedTestSuite,
TypeParameterizedTestSuiteTypes);
#endif
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);