Skip to content

Commit cfe5076

Browse files
Abseil Teamcopybara-github
authored andcommitted
Do not emit stack traces for messages generated by GTEST_SKIP()
Stack traces in assertion failures are an extremely useful tool for developers tasked with investigating failing tests. It's difficult to understate this. In contrast to ordinary test assertions (e.g., ASSERT_TRUE or EXPECT_FALSE), GTEST_SKIP is a developer-authored directive to skip one or more tests. Stack traces emitted in skip messages do not give the developer useful information, as the skip message itself contains the code location where GTEST_SKIP was used. In addition to being noise in the output, symbolization of stack traces is not free. In some Chromium configurations, symbolization in a skipped test can incur a cost in excess of 25 seconds for a test that otherwise takes 0-1ms; see https://crbug.com/1517343#c9. In this CL, we suppress generation and emission of stack traces for kSkip messages to reduce the output noise and overhead of GTEST_SKIP(). PiperOrigin-RevId: 598899010 Change-Id: I46926fed452c8d7edcb3d636d8fed42cb6c0a9e9
1 parent 7c07a86 commit cfe5076

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

googletest/src/gtest.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,12 @@ void AssertHelper::operator=(const Message& message) const {
459459
UnitTest::GetInstance()->AddTestPartResult(
460460
data_->type, data_->file, data_->line,
461461
AppendUserMessage(data_->message, message),
462-
UnitTest::GetInstance()->impl()->CurrentOsStackTraceExceptTop(1)
462+
// Suppress emission of the stack trace for GTEST_SKIP() since skipping is
463+
// an intentional act by the developer rather than a failure requiring
464+
// investigation.
465+
data_->type != TestPartResult::kSkip
466+
? UnitTest::GetInstance()->impl()->CurrentOsStackTraceExceptTop(1)
467+
: ""
463468
// Skips the stack frame for this function itself.
464469
); // NOLINT
465470
}

googletest/test/googletest-output-test-golden-lin.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,6 @@ googletest-output-test_.cc:#: Skipped
970970
[----------] 1 test from TestSuiteThatSkipsInSetUp
971971
googletest-output-test_.cc:#: Skipped
972972
Skip entire test suite
973-
Stack trace: (omitted)
974973

975974
[ RUN ] TestSuiteThatSkipsInSetUp.ShouldNotRun
976975
googletest-output-test_.cc:#: Skipped

googletest/test/gtest_xml_output_unittest.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,23 @@
112112
</testsuite>
113113
<testsuite name="SkippedTest" tests="3" failures="1" disabled="0" skipped="2" errors="0" time="*" timestamp="*">
114114
<testcase name="Skipped" status="run" file="gtest_xml_output_unittest_.cc" line="75" result="skipped" time="*" timestamp="*" classname="SkippedTest">
115-
<skipped message="gtest_xml_output_unittest_.cc:*&#x0A;%(stack_entity)s"><![CDATA[gtest_xml_output_unittest_.cc:*
116-
%(stack)s]]></skipped>
115+
<skipped message="gtest_xml_output_unittest_.cc:*&#x0A;&#x0A;"><![CDATA[gtest_xml_output_unittest_.cc:*
116+
117+
]]></skipped>
117118
</testcase>
118119
<testcase name="SkippedWithMessage" file="gtest_xml_output_unittest_.cc" line="79" status="run" result="skipped" time="*" timestamp="*" classname="SkippedTest">
119-
<skipped message="gtest_xml_output_unittest_.cc:*&#x0A;It is good practice to tell why you skip a test.%(stack_entity)s"><![CDATA[gtest_xml_output_unittest_.cc:*
120-
It is good practice to tell why you skip a test.%(stack)s]]></skipped>
120+
<skipped message="gtest_xml_output_unittest_.cc:*&#x0A;It is good practice to tell why you skip a test.&#x0A;"><![CDATA[gtest_xml_output_unittest_.cc:*
121+
It is good practice to tell why you skip a test.
122+
]]></skipped>
121123
</testcase>
122124
<testcase name="SkippedAfterFailure" file="gtest_xml_output_unittest_.cc" line="83" status="run" result="completed" time="*" timestamp="*" classname="SkippedTest">
123125
<failure message="gtest_xml_output_unittest_.cc:*&#x0A;Expected equality of these values:&#x0A; 1&#x0A; 2%(stack_entity)s" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
124126
Expected equality of these values:
125127
1
126128
2%(stack)s]]></failure>
127-
<skipped message="gtest_xml_output_unittest_.cc:*&#x0A;It is good practice to tell why you skip a test.%(stack_entity)s"><![CDATA[gtest_xml_output_unittest_.cc:*
128-
It is good practice to tell why you skip a test.%(stack)s]]></skipped>
129+
<skipped message="gtest_xml_output_unittest_.cc:*&#x0A;It is good practice to tell why you skip a test.&#x0A;"><![CDATA[gtest_xml_output_unittest_.cc:*
130+
It is good practice to tell why you skip a test.
131+
]]></skipped>
129132
</testcase>
130133
131134
</testsuite>

0 commit comments

Comments
 (0)