mirror of
https://github.com/google/googletest.git
synced 2026-07-30 16:26:24 +08:00
Merge 015793a4873994090a2eb3833ebe0d8341fb38f5 into a0f06a70e3da7afa88da9527c43951bca1f7cef2
This commit is contained in:
commit
3b15ad9c40
@ -4280,7 +4280,7 @@ void XmlUnitTestResultPrinter::OutputXmlTestSuiteForTestResult(
|
||||
OutputXmlAttribute(
|
||||
stream, "testsuite", "timestamp",
|
||||
FormatEpochTimeInMillisAsIso8601(result.start_timestamp()));
|
||||
*stream << ">";
|
||||
*stream << ">\n";
|
||||
|
||||
OutputXmlTestCaseForTestResult(stream, result);
|
||||
|
||||
@ -4404,13 +4404,18 @@ void XmlUnitTestResultPrinter::OutputXmlTestResult(::std::ostream* stream,
|
||||
void XmlUnitTestResultPrinter::PrintXmlTestSuite(std::ostream* stream,
|
||||
const TestSuite& test_suite) {
|
||||
const std::string kTestsuite = "testsuite";
|
||||
// A failed ad hoc test result (e.g. a failure in SetUpTestSuite) is output
|
||||
// as an extra test case below, so include it in the counts.
|
||||
const int ad_hoc_failure = test_suite.ad_hoc_test_result().Failed() ? 1 : 0;
|
||||
*stream << " <" << kTestsuite;
|
||||
OutputXmlAttribute(stream, kTestsuite, "name", test_suite.name());
|
||||
OutputXmlAttribute(stream, kTestsuite, "tests",
|
||||
StreamableToString(test_suite.reportable_test_count()));
|
||||
OutputXmlAttribute(
|
||||
stream, kTestsuite, "tests",
|
||||
StreamableToString(test_suite.reportable_test_count() + ad_hoc_failure));
|
||||
if (!GTEST_FLAG_GET(list_tests)) {
|
||||
OutputXmlAttribute(stream, kTestsuite, "failures",
|
||||
StreamableToString(test_suite.failed_test_count()));
|
||||
OutputXmlAttribute(
|
||||
stream, kTestsuite, "failures",
|
||||
StreamableToString(test_suite.failed_test_count() + ad_hoc_failure));
|
||||
OutputXmlAttribute(
|
||||
stream, kTestsuite, "disabled",
|
||||
StreamableToString(test_suite.reportable_disabled_test_count()));
|
||||
@ -4439,18 +4444,38 @@ void XmlUnitTestResultPrinter::PrintXmlTestSuite(std::ostream* stream,
|
||||
*stream << " </" << kTestsuite << ">\n";
|
||||
}
|
||||
|
||||
// Counts the synthetic test cases that are output for failures recorded
|
||||
// outside of individual tests (e.g. in SetUpTestSuite or a global test
|
||||
// environment), so that they can be included in the aggregate counts.
|
||||
static int AdHocTestFailureCount(const UnitTest& unit_test) {
|
||||
int count = unit_test.ad_hoc_test_result().Failed() ? 1 : 0;
|
||||
for (int i = 0; i < unit_test.total_test_suite_count(); ++i) {
|
||||
const TestSuite& test_suite = *unit_test.GetTestSuite(i);
|
||||
if (test_suite.reportable_test_count() > 0 &&
|
||||
test_suite.ad_hoc_test_result().Failed()) {
|
||||
++count;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// Prints an XML summary of unit_test to output stream out.
|
||||
void XmlUnitTestResultPrinter::PrintXmlUnitTest(std::ostream* stream,
|
||||
const UnitTest& unit_test) {
|
||||
const std::string kTestsuites = "testsuites";
|
||||
// Failures outside of individual tests are output as synthetic test cases,
|
||||
// so include them in the counts.
|
||||
const int ad_hoc_failures = AdHocTestFailureCount(unit_test);
|
||||
|
||||
*stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
||||
*stream << "<" << kTestsuites;
|
||||
|
||||
OutputXmlAttribute(stream, kTestsuites, "tests",
|
||||
StreamableToString(unit_test.reportable_test_count()));
|
||||
OutputXmlAttribute(stream, kTestsuites, "failures",
|
||||
StreamableToString(unit_test.failed_test_count()));
|
||||
OutputXmlAttribute(
|
||||
stream, kTestsuites, "tests",
|
||||
StreamableToString(unit_test.reportable_test_count() + ad_hoc_failures));
|
||||
OutputXmlAttribute(
|
||||
stream, kTestsuites, "failures",
|
||||
StreamableToString(unit_test.failed_test_count() + ad_hoc_failures));
|
||||
OutputXmlAttribute(
|
||||
stream, kTestsuites, "disabled",
|
||||
StreamableToString(unit_test.reportable_disabled_test_count()));
|
||||
@ -4873,14 +4898,17 @@ void JsonUnitTestResultPrinter::PrintJsonTestSuite(
|
||||
std::ostream* stream, const TestSuite& test_suite) {
|
||||
const std::string kTestsuite = "testsuite";
|
||||
const std::string kIndent = Indent(6);
|
||||
// A failed ad hoc test result (e.g. a failure in SetUpTestSuite) is output
|
||||
// as an extra test case below, so include it in the counts.
|
||||
const int ad_hoc_failure = test_suite.ad_hoc_test_result().Failed() ? 1 : 0;
|
||||
|
||||
*stream << Indent(4) << "{\n";
|
||||
OutputJsonKey(stream, kTestsuite, "name", test_suite.name(), kIndent);
|
||||
OutputJsonKey(stream, kTestsuite, "tests", test_suite.reportable_test_count(),
|
||||
kIndent);
|
||||
OutputJsonKey(stream, kTestsuite, "tests",
|
||||
test_suite.reportable_test_count() + ad_hoc_failure, kIndent);
|
||||
if (!GTEST_FLAG_GET(list_tests)) {
|
||||
OutputJsonKey(stream, kTestsuite, "failures",
|
||||
test_suite.failed_test_count(), kIndent);
|
||||
test_suite.failed_test_count() + ad_hoc_failure, kIndent);
|
||||
OutputJsonKey(stream, kTestsuite, "disabled",
|
||||
test_suite.reportable_disabled_test_count(), kIndent);
|
||||
OutputJsonKey(stream, kTestsuite, "errors", 0, kIndent);
|
||||
@ -4926,12 +4954,15 @@ void JsonUnitTestResultPrinter::PrintJsonUnitTest(std::ostream* stream,
|
||||
const UnitTest& unit_test) {
|
||||
const std::string kTestsuites = "testsuites";
|
||||
const std::string kIndent = Indent(2);
|
||||
// Failures outside of individual tests are output as synthetic test cases,
|
||||
// so include them in the counts.
|
||||
const int ad_hoc_failures = AdHocTestFailureCount(unit_test);
|
||||
*stream << "{\n";
|
||||
|
||||
OutputJsonKey(stream, kTestsuites, "tests", unit_test.reportable_test_count(),
|
||||
kIndent);
|
||||
OutputJsonKey(stream, kTestsuites, "failures", unit_test.failed_test_count(),
|
||||
kIndent);
|
||||
OutputJsonKey(stream, kTestsuites, "tests",
|
||||
unit_test.reportable_test_count() + ad_hoc_failures, kIndent);
|
||||
OutputJsonKey(stream, kTestsuites, "failures",
|
||||
unit_test.failed_test_count() + ad_hoc_failures, kIndent);
|
||||
OutputJsonKey(stream, kTestsuites, "disabled",
|
||||
unit_test.reportable_disabled_test_count(), kIndent);
|
||||
OutputJsonKey(stream, kTestsuites, "errors", 0, kIndent);
|
||||
|
||||
@ -57,8 +57,8 @@ else:
|
||||
STACK_TRACE_TEMPLATE = '\n'
|
||||
|
||||
EXPECTED_NON_EMPTY = {
|
||||
'tests': 28,
|
||||
'failures': 5,
|
||||
'tests': 30,
|
||||
'failures': 7,
|
||||
'disabled': 2,
|
||||
'errors': 0,
|
||||
'timestamp': '*',
|
||||
@ -423,8 +423,8 @@ EXPECTED_NON_EMPTY = {
|
||||
},
|
||||
{
|
||||
'name': 'SetupFailTest',
|
||||
'tests': 1,
|
||||
'failures': 0,
|
||||
'tests': 2,
|
||||
'failures': 1,
|
||||
'disabled': 0,
|
||||
'errors': 0,
|
||||
'time': '*',
|
||||
@ -463,8 +463,8 @@ EXPECTED_NON_EMPTY = {
|
||||
},
|
||||
{
|
||||
'name': 'TearDownFailTest',
|
||||
'tests': 1,
|
||||
'failures': 0,
|
||||
'tests': 2,
|
||||
'failures': 1,
|
||||
'disabled': 0,
|
||||
'errors': 0,
|
||||
'timestamp': '*',
|
||||
@ -667,8 +667,8 @@ EXPECTED_FILTERED = {
|
||||
}
|
||||
|
||||
EXPECTED_NO_TEST = {
|
||||
'tests': 0,
|
||||
'failures': 0,
|
||||
'tests': 1,
|
||||
'failures': 1,
|
||||
'disabled': 0,
|
||||
'errors': 0,
|
||||
'time': '*',
|
||||
|
||||
@ -67,7 +67,7 @@ else:
|
||||
sys.argv.remove(NO_STACKTRACE_SUPPORT_FLAG)
|
||||
|
||||
EXPECTED_NON_EMPTY_XML = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites tests="28" failures="5" disabled="2" errors="0" time="*" timestamp="*" name="AllTests">
|
||||
<testsuites tests="30" failures="7" disabled="2" errors="0" time="*" timestamp="*" name="AllTests">
|
||||
<properties>
|
||||
<property name="ad_hoc_property" value="42"/>
|
||||
</properties>
|
||||
@ -182,7 +182,7 @@ It is good practice to tell why you skip a test.
|
||||
</properties>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
<testsuite name="SetupFailTest" tests="1" failures="0" disabled="0" skipped="1" errors="0" time="*" timestamp="*">
|
||||
<testsuite name="SetupFailTest" tests="2" failures="1" disabled="0" skipped="1" errors="0" time="*" timestamp="*">
|
||||
<testcase name="NoopPassingTest" file="gtest_xml_output_unittest_.cc" line="172" status="run" result="skipped" time="*" timestamp="*" classname="SetupFailTest">
|
||||
<skipped message="gtest_xml_output_unittest_.cc:*
"><![CDATA[gtest_xml_output_unittest_.cc:*
|
||||
]]></skipped>
|
||||
@ -194,7 +194,7 @@ Expected equality of these values:
|
||||
2%(stack)s]]></failure>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
<testsuite name="TearDownFailTest" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testsuite name="TearDownFailTest" tests="2" failures="1" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="NoopPassingTest" file="gtest_xml_output_unittest_.cc" line="179" status="run" result="completed" time="*" timestamp="*" classname="TearDownFailTest"/>
|
||||
<testcase name="" status="run" result="completed" classname="" time="*" timestamp="*">
|
||||
<failure message="gtest_xml_output_unittest_.cc:*
Expected equality of these values:
 1
 2%(stack_entity)s" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
|
||||
@ -264,7 +264,7 @@ EXPECTED_SHARDED_TEST_XML = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
</testsuites>"""
|
||||
|
||||
EXPECTED_NO_TEST_XML = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites tests="0" failures="0" disabled="0" errors="0" time="*"
|
||||
<testsuites tests="1" failures="1" disabled="0" errors="0" time="*"
|
||||
timestamp="*" name="AllTests">
|
||||
<testsuite name="NonTestSuiteFailure" tests="1" failures="1" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="" status="run" result="completed" time="*" timestamp="*" classname="">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user