Skip to content

Commit

Permalink
Googletest export
Browse files Browse the repository at this point in the history
Support skipped in XML and JSON output

PiperOrigin-RevId: 225386540
  • Loading branch information
Abseil Team authored and jueminyang committed Dec 13, 2018
1 parent 81f0026 commit c6cb7e0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
4 changes: 3 additions & 1 deletion googletest/src/gtest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3761,7 +3761,8 @@ void XmlUnitTestResultPrinter::OutputXmlTestInfo(::std::ostream* stream,
}

OutputXmlAttribute(stream, kTestcase, "status",
test_info.should_run() ? "run" : "notrun");
result.Skipped() ? "skipped" :
test_info.should_run() ? "run" : "notrun");
OutputXmlAttribute(stream, kTestcase, "time",
FormatTimeInMillisAsSeconds(result.elapsed_time()));
OutputXmlAttribute(stream, kTestcase, "classname", test_case_name);
Expand Down Expand Up @@ -4126,6 +4127,7 @@ void JsonUnitTestResultPrinter::OutputJsonTestInfo(::std::ostream* stream,
}

OutputJsonKey(stream, kTestcase, "status",
result.Skipped() ? "SKIPPED" :
test_info.should_run() ? "RUN" : "NOTRUN", kIndent);
OutputJsonKey(stream, kTestcase, "time",
FormatTimeInMillisAsDuration(result.elapsed_time()), kIndent);
Expand Down
18 changes: 17 additions & 1 deletion googletest/test/googletest-json-output-unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
STACK_TRACE_TEMPLATE = ''

EXPECTED_NON_EMPTY = {
u'tests': 23,
u'tests': 24,
u'failures': 4,
u'disabled': 2,
u'errors': 0,
Expand Down Expand Up @@ -123,6 +123,22 @@
}
]
},
{
u'name': u'SkippedTest',
u'tests': 1,
u'failures': 0,
u'disabled': 0,
u'errors': 0,
u'time': u'*',
u'testsuite': [
{
u'name': u'Skipped',
u'status': u'SKIPPED',
u'time': u'*',
u'classname': u'SkippedTest'
}
]
},
{
u'name': u'MixedResultTest',
u'tests': 3,
Expand Down
19 changes: 11 additions & 8 deletions googletest/test/gtest_xml_output_unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
sys.argv.remove(NO_STACKTRACE_SUPPORT_FLAG)

EXPECTED_NON_EMPTY_XML = """<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="23" failures="4" disabled="2" errors="0" time="*" timestamp="*" name="AllTests" ad_hoc_property="42">
<testsuites tests="24" failures="4" disabled="2" errors="0" time="*" timestamp="*" name="AllTests" ad_hoc_property="42">
<testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0" errors="0" time="*">
<testcase name="Succeeds" status="run" time="*" classname="SuccessfulTest"/>
</testsuite>
Expand Down Expand Up @@ -108,6 +108,9 @@
<testsuite name="DisabledTest" tests="1" failures="0" disabled="1" errors="0" time="*">
<testcase name="DISABLED_test_not_run" status="notrun" time="*" classname="DisabledTest"/>
</testsuite>
<testsuite name="SkippedTest" tests="1" failures="0" disabled="0" errors="0" time="*">
<testcase name="Skipped" status="skipped" time="*" classname="SkippedTest"/>
</testsuite>
<testsuite name="PropertyRecordingTest" tests="4" failures="0" disabled="0" errors="0" time="*" SetUpTestCase="yes" TearDownTestCase="aye">
<testcase name="OneProperty" status="run" time="*" classname="PropertyRecordingTest">
<properties>
Expand Down Expand Up @@ -183,15 +186,15 @@
<testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0" errors="0" time="*">
<testcase name="Succeeds" status="run" time="*" classname="SuccessfulTest"/>
</testsuite>
<testsuite name="NoFixtureTest" tests="1" failures="0" disabled="0" errors="0" time="*">
<testcase name="RecordProperty" status="run" time="*" classname="NoFixtureTest">
<properties>
<property name="key" value="1"/>
</properties>
</testcase>
<testsuite name="PropertyRecordingTest" tests="1" failures="0" disabled="0" errors="0" time="*" SetUpTestCase="yes" TearDownTestCase="aye">
<testcase name="TwoValuesForOneKeyUsesLastValue" status="run" time="*" classname="PropertyRecordingTest">
<properties>
<property name="key_1" value="2"/>
</properties>
</testcase>
</testsuite>
<testsuite name="Single/ValueParamTest" tests="1" failures="0" disabled="0" errors="0" time="*">
<testcase name="AnotherTestThatHasValueParamAttribute/1" value_param="42" status="run" time="*" classname="Single/ValueParamTest" />
<testcase name="AnotherTestThatHasValueParamAttribute/0" value_param="33" status="run" time="*" classname="Single/ValueParamTest" />
</testsuite>
</testsuites>"""

Expand Down
7 changes: 7 additions & 0 deletions googletest/test/gtest_xml_output_unittest_.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ TEST_F(DisabledTest, DISABLED_test_not_run) {
FAIL() << "Unexpected failure: Disabled test should not be run";
}

class SkippedTest : public Test {
};

TEST_F(SkippedTest, Skipped) {
GTEST_SKIP();
}

TEST(MixedResultTest, Succeeds) {
EXPECT_EQ(1, 1);
ASSERT_EQ(1, 1);
Expand Down

0 comments on commit c6cb7e0

Please sign in to comment.