mirror of
https://git.mirrors.martin98.com/https://github.com/google/googletest.git
synced 2025-04-23 06:29:53 +08:00
Merge pull request #4508 from davidmatson:addJsonSkipped
PiperOrigin-RevId: 622929007 Change-Id: Ifaf5a701baee74503e6845f32ebc27425882e950
This commit is contained in:
commit
3d73dee972
@ -4743,26 +4743,53 @@ void JsonUnitTestResultPrinter::OutputJsonTestResult(::std::ostream* stream,
|
|||||||
const TestResult& result) {
|
const TestResult& result) {
|
||||||
const std::string kIndent = Indent(10);
|
const std::string kIndent = Indent(10);
|
||||||
|
|
||||||
int failures = 0;
|
{
|
||||||
for (int i = 0; i < result.total_part_count(); ++i) {
|
int failures = 0;
|
||||||
const TestPartResult& part = result.GetTestPartResult(i);
|
for (int i = 0; i < result.total_part_count(); ++i) {
|
||||||
if (part.failed()) {
|
const TestPartResult& part = result.GetTestPartResult(i);
|
||||||
*stream << ",\n";
|
if (part.failed()) {
|
||||||
if (++failures == 1) {
|
*stream << ",\n";
|
||||||
*stream << kIndent << "\"" << "failures" << "\": [\n";
|
if (++failures == 1) {
|
||||||
|
*stream << kIndent << "\"" << "failures" << "\": [\n";
|
||||||
|
}
|
||||||
|
const std::string location =
|
||||||
|
internal::FormatCompilerIndependentFileLocation(part.file_name(),
|
||||||
|
part.line_number());
|
||||||
|
const std::string message =
|
||||||
|
EscapeJson(location + "\n" + part.message());
|
||||||
|
*stream << kIndent << " {\n"
|
||||||
|
<< kIndent << " \"failure\": \"" << message << "\",\n"
|
||||||
|
<< kIndent << " \"type\": \"\"\n"
|
||||||
|
<< kIndent << " }";
|
||||||
}
|
}
|
||||||
const std::string location =
|
|
||||||
internal::FormatCompilerIndependentFileLocation(part.file_name(),
|
|
||||||
part.line_number());
|
|
||||||
const std::string message = EscapeJson(location + "\n" + part.message());
|
|
||||||
*stream << kIndent << " {\n"
|
|
||||||
<< kIndent << " \"failure\": \"" << message << "\",\n"
|
|
||||||
<< kIndent << " \"type\": \"\"\n"
|
|
||||||
<< kIndent << " }";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (failures > 0) *stream << "\n" << kIndent << "]";
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
int skipped = 0;
|
||||||
|
for (int i = 0; i < result.total_part_count(); ++i) {
|
||||||
|
const TestPartResult& part = result.GetTestPartResult(i);
|
||||||
|
if (part.skipped()) {
|
||||||
|
*stream << ",\n";
|
||||||
|
if (++skipped == 1) {
|
||||||
|
*stream << kIndent << "\"" << "skipped" << "\": [\n";
|
||||||
|
}
|
||||||
|
const std::string location =
|
||||||
|
internal::FormatCompilerIndependentFileLocation(part.file_name(),
|
||||||
|
part.line_number());
|
||||||
|
const std::string message =
|
||||||
|
EscapeJson(location + "\n" + part.message());
|
||||||
|
*stream << kIndent << " {\n"
|
||||||
|
<< kIndent << " \"message\": \"" << message << "\"\n"
|
||||||
|
<< kIndent << " }";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (skipped > 0) *stream << "\n" << kIndent << "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (failures > 0) *stream << "\n" << kIndent << "]";
|
|
||||||
*stream << "\n" << Indent(8) << "}";
|
*stream << "\n" << Indent(8) << "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,6 +150,9 @@ EXPECTED_NON_EMPTY = {
|
|||||||
'time': '*',
|
'time': '*',
|
||||||
'timestamp': '*',
|
'timestamp': '*',
|
||||||
'classname': 'SkippedTest',
|
'classname': 'SkippedTest',
|
||||||
|
'skipped': [
|
||||||
|
{'message': 'gtest_xml_output_unittest_.cc:*\n\n'}
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': 'SkippedWithMessage',
|
'name': 'SkippedWithMessage',
|
||||||
@ -160,6 +163,12 @@ EXPECTED_NON_EMPTY = {
|
|||||||
'time': '*',
|
'time': '*',
|
||||||
'timestamp': '*',
|
'timestamp': '*',
|
||||||
'classname': 'SkippedTest',
|
'classname': 'SkippedTest',
|
||||||
|
'skipped': [{
|
||||||
|
'message': (
|
||||||
|
'gtest_xml_output_unittest_.cc:*\n'
|
||||||
|
'It is good practice to tell why you skip a test.\n'
|
||||||
|
)
|
||||||
|
}],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': 'SkippedAfterFailure',
|
'name': 'SkippedAfterFailure',
|
||||||
@ -179,6 +188,12 @@ EXPECTED_NON_EMPTY = {
|
|||||||
),
|
),
|
||||||
'type': '',
|
'type': '',
|
||||||
}],
|
}],
|
||||||
|
'skipped': [{
|
||||||
|
'message': (
|
||||||
|
'gtest_xml_output_unittest_.cc:*\n'
|
||||||
|
'It is good practice to tell why you skip a test.\n'
|
||||||
|
)
|
||||||
|
}],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
@ -51,6 +51,9 @@ def normalize(obj):
|
|||||||
elif key == 'failure':
|
elif key == 'failure':
|
||||||
value = re.sub(r'^.*[/\\](.*:)\d+\n', '\\1*\n', value)
|
value = re.sub(r'^.*[/\\](.*:)\d+\n', '\\1*\n', value)
|
||||||
return re.sub(r'Stack trace:\n(.|\n)*', 'Stack trace:\n*', value)
|
return re.sub(r'Stack trace:\n(.|\n)*', 'Stack trace:\n*', value)
|
||||||
|
elif key == 'message':
|
||||||
|
value = re.sub(r'^.*[/\\](.*:)\d+\n', '\\1*\n', value)
|
||||||
|
return re.sub(r'Stack trace:\n(.|\n)*', 'Stack trace:\n*', value)
|
||||||
elif key == 'file':
|
elif key == 'file':
|
||||||
return re.sub(r'^.*[/\\](.*)', '\\1', value)
|
return re.sub(r'^.*[/\\](.*)', '\\1', value)
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user