From 5fce13091d223069436ad7a5aad53f026b0f2041 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Wed, 22 Mar 2023 20:19:06 -0700 Subject: [PATCH] gtest.cc: add a newline after a failure when there is no OS stack trace. This makes the behavior consistent when GTEST_STACK_TRACE_DEPTH is set to zero and not: there is always vertical whitespace separating failure messages. PiperOrigin-RevId: 518744611 Change-Id: I5b4af40633849850660504c3f497a76601d4311d --- googlemock/test/gmock_output_test_golden.txt | 18 +++++++++++ googletest/src/gtest.cc | 2 ++ .../test/googletest-json-output-unittest.py | 2 +- googletest/test/googletest-output-test.py | 2 +- googletest/test/gtest_xml_output_unittest.py | 30 +++++++++++-------- 5 files changed, 39 insertions(+), 15 deletions(-) diff --git a/googlemock/test/gmock_output_test_golden.txt b/googlemock/test/gmock_output_test_golden.txt index d6c03338..a2256443 100644 --- a/googlemock/test/gmock_output_test_golden.txt +++ b/googlemock/test/gmock_output_test_golden.txt @@ -40,6 +40,7 @@ FILE:#: EXPECT_CALL(foo_, Bar2(0, _))... Actual: 1 Expected: to be called once Actual: never called - unsatisfied and active + [ FAILED ] GMockOutputTest.UnexpectedCall [ RUN ] GMockOutputTest.UnexpectedCallToVoidFunction unknown file: Failure @@ -53,6 +54,7 @@ FILE:#: EXPECT_CALL(foo_, Bar3(0, _))... Actual: 1 Expected: to be called once Actual: never called - unsatisfied and active + [ FAILED ] GMockOutputTest.UnexpectedCallToVoidFunction [ RUN ] GMockOutputTest.ExcessiveCall FILE:#: Failure @@ -61,6 +63,7 @@ Mock function called more times than expected - returning default value. Returns: false Expected: to be called once Actual: called twice - over-saturated and active + [ FAILED ] GMockOutputTest.ExcessiveCall [ RUN ] GMockOutputTest.ExcessiveCallToVoidFunction FILE:#: Failure @@ -68,6 +71,7 @@ Mock function called more times than expected - returning directly. Function call: Bar3(0, 1) Expected: to be called once Actual: called twice - over-saturated and active + [ FAILED ] GMockOutputTest.ExcessiveCallToVoidFunction [ RUN ] GMockOutputTest.UninterestingCall @@ -104,6 +108,7 @@ FILE:#: tried expectation #1: EXPECT_CALL(foo_, Bar2(0, 0))... Actual: 1 Expected: to be called once Actual: never called - unsatisfied and active + [ FAILED ] GMockOutputTest.RetiredExpectation [ RUN ] GMockOutputTest.UnsatisfiedPrerequisite unknown file: Failure @@ -125,6 +130,7 @@ FILE:#: pre-requisite #0 (end of pre-requisites) Expected: to be called once Actual: never called - unsatisfied and active + [ FAILED ] GMockOutputTest.UnsatisfiedPrerequisite [ RUN ] GMockOutputTest.UnsatisfiedPrerequisites unknown file: Failure @@ -147,6 +153,7 @@ FILE:#: pre-requisite #1 (end of pre-requisites) Expected: to be called once Actual: never called - unsatisfied and active + [ FAILED ] GMockOutputTest.UnsatisfiedPrerequisites [ RUN ] GMockOutputTest.UnsatisfiedWith FILE:#: Failure @@ -154,16 +161,19 @@ Actual function call count doesn't match EXPECT_CALL(foo_, Bar2(_, _))... Expected args: are a pair where the first >= the second Expected: to be called once Actual: never called - unsatisfied and active + [ FAILED ] GMockOutputTest.UnsatisfiedWith [ RUN ] GMockOutputTest.UnsatisfiedExpectation FILE:#: Failure Actual function call count doesn't match EXPECT_CALL(foo_, Bar2(0, _))... Expected: to be called twice Actual: called once - unsatisfied and active + FILE:#: Failure Actual function call count doesn't match EXPECT_CALL(foo_, Bar(_, _, _))... Expected: to be called once Actual: never called - unsatisfied and active + [ FAILED ] GMockOutputTest.UnsatisfiedExpectation [ RUN ] GMockOutputTest.MismatchArguments unknown file: Failure @@ -180,6 +190,7 @@ FILE:#: EXPECT_CALL(foo_, Bar(Ref(s), _, Ge(0)))... Actual: -0.1 Expected: to be called once Actual: never called - unsatisfied and active + [ FAILED ] GMockOutputTest.MismatchArguments [ RUN ] GMockOutputTest.MismatchWith unknown file: Failure @@ -194,6 +205,7 @@ FILE:#: EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1)))... Actual: don't match Expected: to be called once Actual: never called - unsatisfied and active + [ FAILED ] GMockOutputTest.MismatchWith [ RUN ] GMockOutputTest.MismatchArgumentsAndWith unknown file: Failure @@ -210,6 +222,7 @@ FILE:#: EXPECT_CALL(foo_, Bar2(Ge(2), Ge(1)))... Actual: don't match Expected: to be called once Actual: never called - unsatisfied and active + [ FAILED ] GMockOutputTest.MismatchArgumentsAndWith [ RUN ] GMockOutputTest.UnexpectedCallWithDefaultAction unknown file: Failure @@ -227,6 +240,7 @@ FILE:#: EXPECT_CALL(foo_, Bar2(2, 2))... Actual: 0 Expected: to be called once Actual: never called - unsatisfied and active + unknown file: Failure Unexpected mock function call - taking default action specified at: @@ -242,6 +256,7 @@ FILE:#: EXPECT_CALL(foo_, Bar2(2, 2))... Actual: 0 Expected: to be called once Actual: never called - unsatisfied and active + [ FAILED ] GMockOutputTest.UnexpectedCallWithDefaultAction [ RUN ] GMockOutputTest.ExcessiveCallWithDefaultAction FILE:#: Failure @@ -251,6 +266,7 @@ FILE:#: Returns: true Expected: to be called once Actual: called twice - over-saturated and active + FILE:#: Failure Mock function called more times than expected - taking default action specified at: FILE:#: @@ -258,6 +274,7 @@ FILE:#: Returns: false Expected: to be called once Actual: called twice - over-saturated and active + [ FAILED ] GMockOutputTest.ExcessiveCallWithDefaultAction [ RUN ] GMockOutputTest.UninterestingCallWithDefaultAction @@ -293,6 +310,7 @@ FILE:#: Failure Value of: (std::tuple(42, true)) Expected: is pair (first: is >= 48, second: true) Actual: (42, true) + [ FAILED ] GMockOutputTest.PrintsMatcher [ FAILED ] GMockOutputTest.UnexpectedCall [ FAILED ] GMockOutputTest.UnexpectedCallToVoidFunction diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index 55f8e507..897c0cd9 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -5319,6 +5319,8 @@ void UnitTest::AddTestPartResult(TestPartResult::Type result_type, if (os_stack_trace.c_str() != nullptr && !os_stack_trace.empty()) { msg << internal::kStackTraceMarker << os_stack_trace; + } else { + msg << "\n"; } const TestPartResult result = TestPartResult( diff --git a/googletest/test/googletest-json-output-unittest.py b/googletest/test/googletest-json-output-unittest.py index b3a08deb..e955e7b0 100644 --- a/googletest/test/googletest-json-output-unittest.py +++ b/googletest/test/googletest-json-output-unittest.py @@ -54,7 +54,7 @@ SUPPORTS_STACK_TRACES = NO_STACKTRACE_SUPPORT_FLAG not in sys.argv if SUPPORTS_STACK_TRACES: STACK_TRACE_TEMPLATE = '\nStack trace:\n*' else: - STACK_TRACE_TEMPLATE = '' + STACK_TRACE_TEMPLATE = '\n' EXPECTED_NON_EMPTY = { 'tests': 26, diff --git a/googletest/test/googletest-output-test.py b/googletest/test/googletest-output-test.py index 347b8546..6d80d532 100755 --- a/googletest/test/googletest-output-test.py +++ b/googletest/test/googletest-output-test.py @@ -132,7 +132,7 @@ def RemoveStackTraces(output): """Removes all traces of stack traces from a Google Test program's output.""" # *? means "find the shortest string that matches". - return re.sub(r'Stack trace:(.|\n)*?\n\n', '', output) + return re.sub(r'Stack trace:(.|\n)*?\n', '', output) def RemoveTime(output): diff --git a/googletest/test/gtest_xml_output_unittest.py b/googletest/test/gtest_xml_output_unittest.py index 5ca11cb6..e7e44fc1 100755 --- a/googletest/test/gtest_xml_output_unittest.py +++ b/googletest/test/gtest_xml_output_unittest.py @@ -59,8 +59,10 @@ SUPPORTS_STACK_TRACES = NO_STACKTRACE_SUPPORT_FLAG not in sys.argv if SUPPORTS_STACK_TRACES: STACK_TRACE_TEMPLATE = '\nStack trace:\n*' + STACK_TRACE_ENTITY_TEMPLATE = '' else: - STACK_TRACE_TEMPLATE = '' + STACK_TRACE_TEMPLATE = '\n' + STACK_TRACE_ENTITY_TEMPLATE = ' ' # unittest.main() can't handle unknown flags sys.argv.remove(NO_STACKTRACE_SUPPORT_FLAG) @@ -71,7 +73,7 @@ EXPECTED_NON_EMPTY_XML = """ - @@ -80,11 +82,11 @@ Expected equality of these values: - - @@ -93,14 +95,14 @@ Expected equality of these values: - ]]>%(stack)s]]> - @@ -110,19 +112,19 @@ Invalid characters in brackets []%(stack)s]]> - - - - @@ -187,7 +189,8 @@ It is good practice to tell why you skip a test.%(stack)s]]> """ % { - 'stack': STACK_TRACE_TEMPLATE + 'stack': STACK_TRACE_TEMPLATE, + 'stack_entity': STACK_TRACE_ENTITY_TEMPLATE, } EXPECTED_FILTERED_TEST_XML = """ @@ -221,14 +224,15 @@ EXPECTED_NO_TEST_XML = """ timestamp="*" name="AllTests"> - """ % { - 'stack': STACK_TRACE_TEMPLATE + 'stack': STACK_TRACE_TEMPLATE, + 'stack_entity': STACK_TRACE_ENTITY_TEMPLATE, } GTEST_PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath(GTEST_PROGRAM_NAME)