diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 7dc80594..6d6ff1bb 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -451,6 +451,19 @@ static bool ShouldRunTestSuite(const TestSuite* test_suite) { return test_suite->should_run(); } +namespace { + +// Returns true if test part results of type `type` should include a stack +// trace. +bool ShouldEmitStackTraceForResultType(TestPartResult::Type type) { + // Suppress emission of the stack trace for SUCCEED() since it likely never + // requires investigation, and GTEST_SKIP() since skipping is an intentional + // act by the developer rather than a failure requiring investigation. + return type != TestPartResult::kSuccess && type != TestPartResult::kSkip; +} + +} // namespace + // AssertHelper constructor. AssertHelper::AssertHelper(TestPartResult::Type type, const char* file, int line, const char* message) @@ -463,10 +476,7 @@ void AssertHelper::operator=(const Message& message) const { UnitTest::GetInstance()->AddTestPartResult( data_->type, data_->file, data_->line, AppendUserMessage(data_->message, message), - // Suppress emission of the stack trace for GTEST_SKIP() since skipping is - // an intentional act by the developer rather than a failure requiring - // investigation. - data_->type != TestPartResult::kSkip + ShouldEmitStackTraceForResultType(data_->type) ? UnitTest::GetInstance()->impl()->CurrentOsStackTraceExceptTop(1) : "" // Skips the stack frame for this function itself. diff --git a/googletest/test/googletest-output-test-golden-lin.txt b/googletest/test/googletest-output-test-golden-lin.txt index e06856a2..533eb8c6 100644 --- a/googletest/test/googletest-output-test-golden-lin.txt +++ b/googletest/test/googletest-output-test-golden-lin.txt @@ -696,7 +696,6 @@ Expected: 1 fatal failure Actual: googletest-output-test_.cc:#: Success: Succeeded -Stack trace: (omitted) Stack trace: (omitted) @@ -733,7 +732,6 @@ Expected: 1 non-fatal failure Actual: googletest-output-test_.cc:#: Success: Succeeded -Stack trace: (omitted) Stack trace: (omitted) @@ -770,7 +768,6 @@ Expected: 1 fatal failure Actual: googletest-output-test_.cc:#: Success: Succeeded -Stack trace: (omitted) Stack trace: (omitted) @@ -807,7 +804,6 @@ Expected: 1 non-fatal failure Actual: googletest-output-test_.cc:#: Success: Succeeded -Stack trace: (omitted) Stack trace: (omitted)