Skip to content

Commit 3d73dee

Browse files
Merge pull request #4508 from davidmatson:addJsonSkipped
PiperOrigin-RevId: 622929007 Change-Id: Ifaf5a701baee74503e6845f32ebc27425882e950
2 parents f10e11f + f16770d commit 3d73dee

File tree

3 files changed

+61
-16
lines changed

3 files changed

+61
-16
lines changed

googletest/src/gtest.cc

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4743,26 +4743,53 @@ void JsonUnitTestResultPrinter::OutputJsonTestResult(::std::ostream* stream,
47434743
const TestResult& result) {
47444744
const std::string kIndent = Indent(10);
47454745

4746-
int failures = 0;
4747-
for (int i = 0; i < result.total_part_count(); ++i) {
4748-
const TestPartResult& part = result.GetTestPartResult(i);
4749-
if (part.failed()) {
4750-
*stream << ",\n";
4751-
if (++failures == 1) {
4752-
*stream << kIndent << "\"" << "failures" << "\": [\n";
4746+
{
4747+
int failures = 0;
4748+
for (int i = 0; i < result.total_part_count(); ++i) {
4749+
const TestPartResult& part = result.GetTestPartResult(i);
4750+
if (part.failed()) {
4751+
*stream << ",\n";
4752+
if (++failures == 1) {
4753+
*stream << kIndent << "\"" << "failures" << "\": [\n";
4754+
}
4755+
const std::string location =
4756+
internal::FormatCompilerIndependentFileLocation(part.file_name(),
4757+
part.line_number());
4758+
const std::string message =
4759+
EscapeJson(location + "\n" + part.message());
4760+
*stream << kIndent << " {\n"
4761+
<< kIndent << " \"failure\": \"" << message << "\",\n"
4762+
<< kIndent << " \"type\": \"\"\n"
4763+
<< kIndent << " }";
4764+
}
4765+
}
4766+
4767+
if (failures > 0) *stream << "\n" << kIndent << "]";
4768+
}
4769+
4770+
{
4771+
int skipped = 0;
4772+
for (int i = 0; i < result.total_part_count(); ++i) {
4773+
const TestPartResult& part = result.GetTestPartResult(i);
4774+
if (part.skipped()) {
4775+
*stream << ",\n";
4776+
if (++skipped == 1) {
4777+
*stream << kIndent << "\"" << "skipped" << "\": [\n";
4778+
}
4779+
const std::string location =
4780+
internal::FormatCompilerIndependentFileLocation(part.file_name(),
4781+
part.line_number());
4782+
const std::string message =
4783+
EscapeJson(location + "\n" + part.message());
4784+
*stream << kIndent << " {\n"
4785+
<< kIndent << " \"message\": \"" << message << "\"\n"
4786+
<< kIndent << " }";
47534787
}
4754-
const std::string location =
4755-
internal::FormatCompilerIndependentFileLocation(part.file_name(),
4756-
part.line_number());
4757-
const std::string message = EscapeJson(location + "\n" + part.message());
4758-
*stream << kIndent << " {\n"
4759-
<< kIndent << " \"failure\": \"" << message << "\",\n"
4760-
<< kIndent << " \"type\": \"\"\n"
4761-
<< kIndent << " }";
47624788
}
4789+
4790+
if (skipped > 0) *stream << "\n" << kIndent << "]";
47634791
}
47644792

4765-
if (failures > 0) *stream << "\n" << kIndent << "]";
47664793
*stream << "\n" << Indent(8) << "}";
47674794
}
47684795

googletest/test/googletest-json-output-unittest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@
150150
'time': '*',
151151
'timestamp': '*',
152152
'classname': 'SkippedTest',
153+
'skipped': [
154+
{'message': 'gtest_xml_output_unittest_.cc:*\n\n'}
155+
],
153156
},
154157
{
155158
'name': 'SkippedWithMessage',
@@ -160,6 +163,12 @@
160163
'time': '*',
161164
'timestamp': '*',
162165
'classname': 'SkippedTest',
166+
'skipped': [{
167+
'message': (
168+
'gtest_xml_output_unittest_.cc:*\n'
169+
'It is good practice to tell why you skip a test.\n'
170+
)
171+
}],
163172
},
164173
{
165174
'name': 'SkippedAfterFailure',
@@ -179,6 +188,12 @@
179188
),
180189
'type': '',
181190
}],
191+
'skipped': [{
192+
'message': (
193+
'gtest_xml_output_unittest_.cc:*\n'
194+
'It is good practice to tell why you skip a test.\n'
195+
)
196+
}],
182197
},
183198
],
184199
},

googletest/test/gtest_json_test_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ def _normalize(key, value):
5151
elif key == 'failure':
5252
value = re.sub(r'^.*[/\\](.*:)\d+\n', '\\1*\n', value)
5353
return re.sub(r'Stack trace:\n(.|\n)*', 'Stack trace:\n*', value)
54+
elif key == 'message':
55+
value = re.sub(r'^.*[/\\](.*:)\d+\n', '\\1*\n', value)
56+
return re.sub(r'Stack trace:\n(.|\n)*', 'Stack trace:\n*', value)
5457
elif key == 'file':
5558
return re.sub(r'^.*[/\\](.*)', '\\1', value)
5659
else:

0 commit comments

Comments
 (0)