Commit 5b752b19 by Abseil Team Committed by Gennadiy Civil

Googletest export

Update XML and JSON output to be consistent with the standard. PiperOrigin-RevId: 239833242
parent 1f64659f
...@@ -20,7 +20,7 @@ instructions for how to sign and return it. Once we receive it, we'll be able to ...@@ -20,7 +20,7 @@ instructions for how to sign and return it. Once we receive it, we'll be able to
accept your pull requests. accept your pull requests.
## Are you a Googler? ## Are you a Googler?
If you are a Googler, it is preferrable to create an internal change and send it for review. If you are a Googler, you can either create an internal change or work on GitHub directly.
## Contributing A Patch ## Contributing A Patch
......
...@@ -2112,8 +2112,14 @@ static const char* const kReservedTestSuiteAttributes[] = { ...@@ -2112,8 +2112,14 @@ static const char* const kReservedTestSuiteAttributes[] = {
// The list of reserved attributes used in the <testcase> element of XML output. // The list of reserved attributes used in the <testcase> element of XML output.
static const char* const kReservedTestCaseAttributes[] = { static const char* const kReservedTestCaseAttributes[] = {
"classname", "name", "status", "time", "classname", "name", "status", "time", "type_param",
"type_param", "value_param", "file", "line"}; "value_param", "file", "line"};
// Use a slightly different set for allowed output to ensure existing tests can
// still RecordProperty("result")
static const char* const kReservedOutputTestCaseAttributes[] = {
"classname", "name", "status", "time", "type_param",
"value_param", "file", "line", "result"};
template <int kSize> template <int kSize>
std::vector<std::string> ArrayAsVector(const char* const (&array)[kSize]) { std::vector<std::string> ArrayAsVector(const char* const (&array)[kSize]) {
...@@ -2135,6 +2141,22 @@ static std::vector<std::string> GetReservedAttributesForElement( ...@@ -2135,6 +2141,22 @@ static std::vector<std::string> GetReservedAttributesForElement(
return std::vector<std::string>(); return std::vector<std::string>();
} }
// TODO(jdesprez): Merge the two getReserved attributes once skip is improved
static std::vector<std::string> GetReservedOutputAttributesForElement(
const std::string& xml_element) {
if (xml_element == "testsuites") {
return ArrayAsVector(kReservedTestSuitesAttributes);
} else if (xml_element == "testsuite") {
return ArrayAsVector(kReservedTestSuiteAttributes);
} else if (xml_element == "testcase") {
return ArrayAsVector(kReservedOutputTestCaseAttributes);
} else {
GTEST_CHECK_(false) << "Unrecognized xml_element provided: " << xml_element;
}
// This code is unreachable but some compilers may not realizes that.
return std::vector<std::string>();
}
static std::string FormatWordList(const std::vector<std::string>& words) { static std::string FormatWordList(const std::vector<std::string>& words) {
Message word_list; Message word_list;
for (size_t i = 0; i < words.size(); ++i) { for (size_t i = 0; i < words.size(); ++i) {
...@@ -3717,7 +3739,7 @@ void XmlUnitTestResultPrinter::OutputXmlAttribute( ...@@ -3717,7 +3739,7 @@ void XmlUnitTestResultPrinter::OutputXmlAttribute(
const std::string& name, const std::string& name,
const std::string& value) { const std::string& value) {
const std::vector<std::string>& allowed_names = const std::vector<std::string>& allowed_names =
GetReservedAttributesForElement(element_name); GetReservedOutputAttributesForElement(element_name);
GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(), name) != GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(), name) !=
allowed_names.end()) allowed_names.end())
...@@ -3757,9 +3779,12 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream, ...@@ -3757,9 +3779,12 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream,
return; return;
} }
OutputXmlAttribute( OutputXmlAttribute(stream, kTestsuite, "status",
stream, kTestsuite, "status", test_info.should_run() ? "run" : "notrun");
result.Skipped() ? "skipped" : test_info.should_run() ? "run" : "notrun"); OutputXmlAttribute(stream, kTestsuite, "result",
test_info.should_run()
? (result.Skipped() ? "skipped" : "completed")
: "suppressed");
OutputXmlAttribute(stream, kTestsuite, "time", OutputXmlAttribute(stream, kTestsuite, "time",
FormatTimeInMillisAsSeconds(result.elapsed_time())); FormatTimeInMillisAsSeconds(result.elapsed_time()));
OutputXmlAttribute(stream, kTestsuite, "classname", test_suite_name); OutputXmlAttribute(stream, kTestsuite, "classname", test_suite_name);
...@@ -4065,7 +4090,7 @@ void JsonUnitTestResultPrinter::OutputJsonKey( ...@@ -4065,7 +4090,7 @@ void JsonUnitTestResultPrinter::OutputJsonKey(
const std::string& indent, const std::string& indent,
bool comma) { bool comma) {
const std::vector<std::string>& allowed_names = const std::vector<std::string>& allowed_names =
GetReservedAttributesForElement(element_name); GetReservedOutputAttributesForElement(element_name);
GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(), name) != GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(), name) !=
allowed_names.end()) allowed_names.end())
...@@ -4085,7 +4110,7 @@ void JsonUnitTestResultPrinter::OutputJsonKey( ...@@ -4085,7 +4110,7 @@ void JsonUnitTestResultPrinter::OutputJsonKey(
const std::string& indent, const std::string& indent,
bool comma) { bool comma) {
const std::vector<std::string>& allowed_names = const std::vector<std::string>& allowed_names =
GetReservedAttributesForElement(element_name); GetReservedOutputAttributesForElement(element_name);
GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(), name) != GTEST_CHECK_(std::find(allowed_names.begin(), allowed_names.end(), name) !=
allowed_names.end()) allowed_names.end())
...@@ -4123,10 +4148,13 @@ void JsonUnitTestResultPrinter::OutputJsonTestInfo(::std::ostream* stream, ...@@ -4123,10 +4148,13 @@ void JsonUnitTestResultPrinter::OutputJsonTestInfo(::std::ostream* stream,
return; return;
} }
OutputJsonKey( OutputJsonKey(stream, kTestsuite, "status",
stream, kTestsuite, "status", test_info.should_run() ? "RUN" : "NOTRUN", kIndent);
result.Skipped() ? "SKIPPED" : test_info.should_run() ? "RUN" : "NOTRUN", OutputJsonKey(stream, kTestsuite, "result",
kIndent); test_info.should_run()
? (result.Skipped() ? "SKIPPED" : "COMPLETED")
: "SUPPRESSED",
kIndent);
OutputJsonKey(stream, kTestsuite, "time", OutputJsonKey(stream, kTestsuite, "time",
FormatTimeInMillisAsDuration(result.elapsed_time()), kIndent); FormatTimeInMillisAsDuration(result.elapsed_time()), kIndent);
OutputJsonKey(stream, kTestsuite, "classname", test_suite_name, kIndent, OutputJsonKey(stream, kTestsuite, "classname", test_suite_name, kIndent,
......
...@@ -40,23 +40,37 @@ GTEST_OUTPUT_1_TEST = 'gtest_xml_outfile1_test_' ...@@ -40,23 +40,37 @@ GTEST_OUTPUT_1_TEST = 'gtest_xml_outfile1_test_'
GTEST_OUTPUT_2_TEST = 'gtest_xml_outfile2_test_' GTEST_OUTPUT_2_TEST = 'gtest_xml_outfile2_test_'
EXPECTED_1 = { EXPECTED_1 = {
u'tests': 1, u'tests':
u'failures': 0, 1,
u'disabled': 0, u'failures':
u'errors': 0, 0,
u'time': u'*', u'disabled':
u'timestamp': u'*', 0,
u'name': u'AllTests', u'errors':
0,
u'time':
u'*',
u'timestamp':
u'*',
u'name':
u'AllTests',
u'testsuites': [{ u'testsuites': [{
u'name': u'PropertyOne', u'name':
u'tests': 1, u'PropertyOne',
u'failures': 0, u'tests':
u'disabled': 0, 1,
u'errors': 0, u'failures':
u'time': u'*', 0,
u'disabled':
0,
u'errors':
0,
u'time':
u'*',
u'testsuite': [{ u'testsuite': [{
u'name': u'TestSomeProperties', u'name': u'TestSomeProperties',
u'status': u'RUN', u'status': u'RUN',
u'result': u'COMPLETED',
u'time': u'*', u'time': u'*',
u'classname': u'PropertyOne', u'classname': u'PropertyOne',
u'SetUpProp': u'1', u'SetUpProp': u'1',
...@@ -67,23 +81,37 @@ EXPECTED_1 = { ...@@ -67,23 +81,37 @@ EXPECTED_1 = {
} }
EXPECTED_2 = { EXPECTED_2 = {
u'tests': 1, u'tests':
u'failures': 0, 1,
u'disabled': 0, u'failures':
u'errors': 0, 0,
u'time': u'*', u'disabled':
u'timestamp': u'*', 0,
u'name': u'AllTests', u'errors':
0,
u'time':
u'*',
u'timestamp':
u'*',
u'name':
u'AllTests',
u'testsuites': [{ u'testsuites': [{
u'name': u'PropertyTwo', u'name':
u'tests': 1, u'PropertyTwo',
u'failures': 0, u'tests':
u'disabled': 0, 1,
u'errors': 0, u'failures':
u'time': u'*', 0,
u'disabled':
0,
u'errors':
0,
u'time':
u'*',
u'testsuite': [{ u'testsuite': [{
u'name': u'TestSomeProperties', u'name': u'TestSomeProperties',
u'status': u'RUN', u'status': u'RUN',
u'result': u'COMPLETED',
u'time': u'*', u'time': u'*',
u'classname': u'PropertyTwo', u'classname': u'PropertyTwo',
u'SetUpProp': u'2', u'SetUpProp': u'2',
......
...@@ -43,7 +43,7 @@ GTEST_OUTPUT_2_TEST = "gtest_xml_outfile2_test_" ...@@ -43,7 +43,7 @@ GTEST_OUTPUT_2_TEST = "gtest_xml_outfile2_test_"
EXPECTED_XML_1 = """<?xml version="1.0" encoding="UTF-8"?> EXPECTED_XML_1 = """<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests"> <testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests">
<testsuite name="PropertyOne" tests="1" failures="0" disabled="0" errors="0" time="*"> <testsuite name="PropertyOne" tests="1" failures="0" disabled="0" errors="0" time="*">
<testcase name="TestSomeProperties" status="run" time="*" classname="PropertyOne"> <testcase name="TestSomeProperties" status="run" result="completed" time="*" classname="PropertyOne">
<properties> <properties>
<property name="SetUpProp" value="1"/> <property name="SetUpProp" value="1"/>
<property name="TestSomeProperty" value="1"/> <property name="TestSomeProperty" value="1"/>
...@@ -57,7 +57,7 @@ EXPECTED_XML_1 = """<?xml version="1.0" encoding="UTF-8"?> ...@@ -57,7 +57,7 @@ EXPECTED_XML_1 = """<?xml version="1.0" encoding="UTF-8"?>
EXPECTED_XML_2 = """<?xml version="1.0" encoding="UTF-8"?> EXPECTED_XML_2 = """<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests"> <testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests">
<testsuite name="PropertyTwo" tests="1" failures="0" disabled="0" errors="0" time="*"> <testsuite name="PropertyTwo" tests="1" failures="0" disabled="0" errors="0" time="*">
<testcase name="TestSomeProperties" status="run" time="*" classname="PropertyTwo"> <testcase name="TestSomeProperties" status="run" result="completed" time="*" classname="PropertyTwo">
<properties> <properties>
<property name="SetUpProp" value="2"/> <property name="SetUpProp" value="2"/>
<property name="TestSomeProperty" value="2"/> <property name="TestSomeProperty" value="2"/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment