From 51cabc168f419dacddd1c88409d2f61451f31db0 Mon Sep 17 00:00:00 2001 From: misterg Date: Fri, 31 Aug 2018 11:53:56 -0400 Subject: Googletest export Project import PiperOrigin-RevId: 211091791 --- .../test/googletest-output-test-golden-lin.txt | 30 +++++----------------- 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/googletest/test/googletest-output-test-golden-lin.txt b/googletest/test/googletest-output-test-golden-lin.txt index 86da845..493aa78 100644 --- a/googletest/test/googletest-output-test-golden-lin.txt +++ b/googletest/test/googletest-output-test-golden-lin.txt @@ -12,7 +12,7 @@ Expected equality of these values: 3 Stack trace: (omitted) -[==========] Running 76 tests from 34 test cases. +[==========] Running 74 tests from 34 test cases. [----------] Global test environment set-up. FooEnvironment::SetUp() called. BarEnvironment::SetUp() called. @@ -463,7 +463,7 @@ case. Stack trace: (omitted) [ FAILED ] TEST_before_TEST_F_in_same_test_case.DefinedUsingTEST_FAndShouldFail -[----------] 8 tests from ExpectNonfatalFailureTest +[----------] 7 tests from ExpectNonfatalFailureTest [ RUN ] ExpectNonfatalFailureTest.CanReferenceGlobalVariables [ OK ] ExpectNonfatalFailureTest.CanReferenceGlobalVariables [ RUN ] ExpectNonfatalFailureTest.CanReferenceLocalVariables @@ -520,15 +520,7 @@ Expected: 1 non-fatal failure Stack trace: (omitted) [ FAILED ] ExpectNonfatalFailureTest.FailsWhenStatementReturns -[ RUN ] ExpectNonfatalFailureTest.FailsWhenStatementThrows -(expecting a failure) -gtest.cc:#: Failure -Expected: 1 non-fatal failure - Actual: 0 failures -Stack trace: (omitted) - -[ FAILED ] ExpectNonfatalFailureTest.FailsWhenStatementThrows -[----------] 8 tests from ExpectFatalFailureTest +[----------] 7 tests from ExpectFatalFailureTest [ RUN ] ExpectFatalFailureTest.CanReferenceGlobalVariables [ OK ] ExpectFatalFailureTest.CanReferenceGlobalVariables [ RUN ] ExpectFatalFailureTest.CanReferenceLocalStaticVariables @@ -585,14 +577,6 @@ Expected: 1 fatal failure Stack trace: (omitted) [ FAILED ] ExpectFatalFailureTest.FailsWhenStatementReturns -[ RUN ] ExpectFatalFailureTest.FailsWhenStatementThrows -(expecting a failure) -gtest.cc:#: Failure -Expected: 1 fatal failure - Actual: 0 failures -Stack trace: (omitted) - -[ FAILED ] ExpectFatalFailureTest.FailsWhenStatementThrows [----------] 2 tests from TypedTest/0, where TypeParam = int [ RUN ] TypedTest/0.Success [ OK ] TypedTest/0.Success @@ -906,9 +890,9 @@ Failed Expected fatal failure. Stack trace: (omitted) -[==========] 76 tests from 34 test cases ran. +[==========] 74 tests from 34 test cases ran. [ PASSED ] 26 tests. -[ FAILED ] 50 tests, listed below: +[ FAILED ] 48 tests, listed below: [ FAILED ] NonfatalFailureTest.EscapesStringOperands [ FAILED ] NonfatalFailureTest.DiffForLongStrings [ FAILED ] FatalFailureTest.FatalFailureInSubroutine @@ -937,12 +921,10 @@ Stack trace: (omitted) [ FAILED ] ExpectNonfatalFailureTest.FailsWhenThereAreTwoNonfatalFailures [ FAILED ] ExpectNonfatalFailureTest.FailsWhenThereIsOneFatalFailure [ FAILED ] ExpectNonfatalFailureTest.FailsWhenStatementReturns -[ FAILED ] ExpectNonfatalFailureTest.FailsWhenStatementThrows [ FAILED ] ExpectFatalFailureTest.FailsWhenThereIsNoFatalFailure [ FAILED ] ExpectFatalFailureTest.FailsWhenThereAreTwoFatalFailures [ FAILED ] ExpectFatalFailureTest.FailsWhenThereIsOneNonfatalFailure [ FAILED ] ExpectFatalFailureTest.FailsWhenStatementReturns -[ FAILED ] ExpectFatalFailureTest.FailsWhenStatementThrows [ FAILED ] TypedTest/0.Failure, where TypeParam = int [ FAILED ] TypedTestWithNames/char0.Failure, where TypeParam = char [ FAILED ] TypedTestWithNames/int1.Failure, where TypeParam = int @@ -960,7 +942,7 @@ Stack trace: (omitted) [ FAILED ] PrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2 [ FAILED ] PrintingStrings/ParamTest.Failure/a, where GetParam() = "a" -50 FAILED TESTS +48 FAILED TESTS  YOU HAVE 1 DISABLED TEST Note: Google Test filter = FatalFailureTest.*:LoggingTest.* -- cgit v0.12 From dbd55366c8b010b558795223db6036747eb1c388 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 4 Sep 2018 17:00:34 -0400 Subject: Googletest export Make EXPECT_THROW print the actual exception type on the "threw the wrong exception type" case if the actual exception is a std::exception PiperOrigin-RevId: 211519873 --- googletest/include/gtest/internal/gtest-internal.h | 75 +++++++++++++--------- googletest/test/gtest_unittest.cc | 9 +++ 2 files changed, 53 insertions(+), 31 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index b762f61..60c7964 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -771,13 +771,12 @@ GTEST_API_ bool AlwaysTrue(); // Always returns false. inline bool AlwaysFalse() { return !AlwaysTrue(); } -// Helper for suppressing false warning from Clang on a const char* -// variable declared in a conditional expression always being NULL in -// the else branch. -struct GTEST_API_ ConstCharPtr { - ConstCharPtr(const char* str) : value(str) {} +// Helper for creating strings in if() statement branches. Always converts to +// true. +struct GTEST_API_ TrueString { + TrueString() {} operator bool() const { return true; } - const char* value; + std::string value; }; // A simple Linear Congruential Generator for generating random @@ -1214,31 +1213,45 @@ class NativeArray { #define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \ if (::testing::internal::AlwaysTrue()) { statement; } -#define GTEST_TEST_THROW_(statement, expected_exception, fail) \ - GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (::testing::internal::ConstCharPtr gtest_msg = "") { \ - bool gtest_caught_expected = false; \ - try { \ - GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ - } \ - catch (expected_exception const&) { \ - gtest_caught_expected = true; \ - } \ - catch (...) { \ - gtest_msg.value = \ - "Expected: " #statement " throws an exception of type " \ - #expected_exception ".\n Actual: it throws a different type."; \ - goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ - } \ - if (!gtest_caught_expected) { \ - gtest_msg.value = \ - "Expected: " #statement " throws an exception of type " \ - #expected_exception ".\n Actual: it throws nothing."; \ - goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ - } \ - } else \ - GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \ - fail(gtest_msg.value) +#define GTEST_WRONG_EXCEPTION_MESSAGE_(statement, expected_exception) \ + "Expected: " #statement " throws an exception of type " #expected_exception \ + ".\n Actual: it throws " + +// The nested try-catch block allows us to catch erroneous exceptions which +// inherit from std::exception and feed what() to the failure description. If +// there was no nested try-catch and expected_exception was std::exception, then +// this would fail to build due to two blocks both catching std::exceptions. +#define GTEST_TEST_THROW_(statement, expected_exception, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::testing::internal::TrueString gtest_msg = \ + ::testing::internal::TrueString()) { \ + bool gtest_caught_expected = false; \ + try { \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + } catch (expected_exception const&) { \ + gtest_caught_expected = true; \ + } catch (...) { \ + try { \ + throw; \ + } catch (const std::exception& e) { \ + gtest_msg.value = std::string(GTEST_WRONG_EXCEPTION_MESSAGE_( \ + statement, expected_expression)) + \ + e.what() + "."; \ + } catch (...) { \ + gtest_msg.value = GTEST_WRONG_EXCEPTION_MESSAGE_( \ + statement, expected_exception) "a different type."; \ + } \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ + } \ + if (!gtest_caught_expected) { \ + gtest_msg.value = "Expected: " #statement \ + " throws an exception of type " #expected_exception \ + ".\n Actual: it throws nothing."; \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ + } \ + } else \ + GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__) \ + : fail(gtest_msg.value.c_str()) #define GTEST_TEST_NO_THROW_(statement, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index f7213fb..3965f46 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -4541,12 +4541,21 @@ TEST(ExpectTest, EXPECT_THROW) { EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnInteger(), bool), "Expected: ThrowAnInteger() throws an exception of " "type bool.\n Actual: it throws a different type."); + std::string expected = "what() arg"; + EXPECT_NONFATAL_FAILURE(EXPECT_THROW(throw std::out_of_range(expected), bool), + expected); EXPECT_NONFATAL_FAILURE( EXPECT_THROW(ThrowNothing(), bool), "Expected: ThrowNothing() throws an exception of type bool.\n" " Actual: it throws nothing."); } +// We need to make sure always to avoid having multiple blocks which catch a +// std::exception +TEST(ExpectTest, EXPECT_THROW_STD_EXCEPTION) { + EXPECT_THROW(throw std::exception(), std::exception); +} + // Tests EXPECT_NO_THROW. TEST(ExpectTest, EXPECT_NO_THROW) { EXPECT_NO_THROW(ThrowNothing()); -- cgit v0.12 From 0d2262138c63e8c5ae8f00286e016e4df5e716be Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 4 Sep 2018 17:27:33 -0400 Subject: Googletest export Make EXPECT_THROW print the actual exception type on the "threw the wrong exception type" case if the actual exception is a std::exception PiperOrigin-RevId: 211524592 --- googletest/include/gtest/internal/gtest-internal.h | 75 +++++++++------------- googletest/test/gtest_unittest.cc | 9 --- 2 files changed, 31 insertions(+), 53 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index 60c7964..b762f61 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -771,12 +771,13 @@ GTEST_API_ bool AlwaysTrue(); // Always returns false. inline bool AlwaysFalse() { return !AlwaysTrue(); } -// Helper for creating strings in if() statement branches. Always converts to -// true. -struct GTEST_API_ TrueString { - TrueString() {} +// Helper for suppressing false warning from Clang on a const char* +// variable declared in a conditional expression always being NULL in +// the else branch. +struct GTEST_API_ ConstCharPtr { + ConstCharPtr(const char* str) : value(str) {} operator bool() const { return true; } - std::string value; + const char* value; }; // A simple Linear Congruential Generator for generating random @@ -1213,45 +1214,31 @@ class NativeArray { #define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \ if (::testing::internal::AlwaysTrue()) { statement; } -#define GTEST_WRONG_EXCEPTION_MESSAGE_(statement, expected_exception) \ - "Expected: " #statement " throws an exception of type " #expected_exception \ - ".\n Actual: it throws " - -// The nested try-catch block allows us to catch erroneous exceptions which -// inherit from std::exception and feed what() to the failure description. If -// there was no nested try-catch and expected_exception was std::exception, then -// this would fail to build due to two blocks both catching std::exceptions. -#define GTEST_TEST_THROW_(statement, expected_exception, fail) \ - GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (::testing::internal::TrueString gtest_msg = \ - ::testing::internal::TrueString()) { \ - bool gtest_caught_expected = false; \ - try { \ - GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ - } catch (expected_exception const&) { \ - gtest_caught_expected = true; \ - } catch (...) { \ - try { \ - throw; \ - } catch (const std::exception& e) { \ - gtest_msg.value = std::string(GTEST_WRONG_EXCEPTION_MESSAGE_( \ - statement, expected_expression)) + \ - e.what() + "."; \ - } catch (...) { \ - gtest_msg.value = GTEST_WRONG_EXCEPTION_MESSAGE_( \ - statement, expected_exception) "a different type."; \ - } \ - goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ - } \ - if (!gtest_caught_expected) { \ - gtest_msg.value = "Expected: " #statement \ - " throws an exception of type " #expected_exception \ - ".\n Actual: it throws nothing."; \ - goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ - } \ - } else \ - GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__) \ - : fail(gtest_msg.value.c_str()) +#define GTEST_TEST_THROW_(statement, expected_exception, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::testing::internal::ConstCharPtr gtest_msg = "") { \ + bool gtest_caught_expected = false; \ + try { \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + } \ + catch (expected_exception const&) { \ + gtest_caught_expected = true; \ + } \ + catch (...) { \ + gtest_msg.value = \ + "Expected: " #statement " throws an exception of type " \ + #expected_exception ".\n Actual: it throws a different type."; \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ + } \ + if (!gtest_caught_expected) { \ + gtest_msg.value = \ + "Expected: " #statement " throws an exception of type " \ + #expected_exception ".\n Actual: it throws nothing."; \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ + } \ + } else \ + GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \ + fail(gtest_msg.value) #define GTEST_TEST_NO_THROW_(statement, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 3965f46..f7213fb 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -4541,21 +4541,12 @@ TEST(ExpectTest, EXPECT_THROW) { EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnInteger(), bool), "Expected: ThrowAnInteger() throws an exception of " "type bool.\n Actual: it throws a different type."); - std::string expected = "what() arg"; - EXPECT_NONFATAL_FAILURE(EXPECT_THROW(throw std::out_of_range(expected), bool), - expected); EXPECT_NONFATAL_FAILURE( EXPECT_THROW(ThrowNothing(), bool), "Expected: ThrowNothing() throws an exception of type bool.\n" " Actual: it throws nothing."); } -// We need to make sure always to avoid having multiple blocks which catch a -// std::exception -TEST(ExpectTest, EXPECT_THROW_STD_EXCEPTION) { - EXPECT_THROW(throw std::exception(), std::exception); -} - // Tests EXPECT_NO_THROW. TEST(ExpectTest, EXPECT_NO_THROW) { EXPECT_NO_THROW(ThrowNothing()); -- cgit v0.12 From 0ddb6bf09b703683e8c81033b3167a86e6307a1f Mon Sep 17 00:00:00 2001 From: misterg Date: Wed, 5 Sep 2018 17:26:26 -0400 Subject: Googletest export Internal Change PiperOrigin-RevId: 211699161 --- .../test/googletest-output-test-golden-lin.txt | 30 +++++++++++++++++----- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/googletest/test/googletest-output-test-golden-lin.txt b/googletest/test/googletest-output-test-golden-lin.txt index 493aa78..86da845 100644 --- a/googletest/test/googletest-output-test-golden-lin.txt +++ b/googletest/test/googletest-output-test-golden-lin.txt @@ -12,7 +12,7 @@ Expected equality of these values: 3 Stack trace: (omitted) -[==========] Running 74 tests from 34 test cases. +[==========] Running 76 tests from 34 test cases. [----------] Global test environment set-up. FooEnvironment::SetUp() called. BarEnvironment::SetUp() called. @@ -463,7 +463,7 @@ case. Stack trace: (omitted) [ FAILED ] TEST_before_TEST_F_in_same_test_case.DefinedUsingTEST_FAndShouldFail -[----------] 7 tests from ExpectNonfatalFailureTest +[----------] 8 tests from ExpectNonfatalFailureTest [ RUN ] ExpectNonfatalFailureTest.CanReferenceGlobalVariables [ OK ] ExpectNonfatalFailureTest.CanReferenceGlobalVariables [ RUN ] ExpectNonfatalFailureTest.CanReferenceLocalVariables @@ -520,7 +520,15 @@ Expected: 1 non-fatal failure Stack trace: (omitted) [ FAILED ] ExpectNonfatalFailureTest.FailsWhenStatementReturns -[----------] 7 tests from ExpectFatalFailureTest +[ RUN ] ExpectNonfatalFailureTest.FailsWhenStatementThrows +(expecting a failure) +gtest.cc:#: Failure +Expected: 1 non-fatal failure + Actual: 0 failures +Stack trace: (omitted) + +[ FAILED ] ExpectNonfatalFailureTest.FailsWhenStatementThrows +[----------] 8 tests from ExpectFatalFailureTest [ RUN ] ExpectFatalFailureTest.CanReferenceGlobalVariables [ OK ] ExpectFatalFailureTest.CanReferenceGlobalVariables [ RUN ] ExpectFatalFailureTest.CanReferenceLocalStaticVariables @@ -577,6 +585,14 @@ Expected: 1 fatal failure Stack trace: (omitted) [ FAILED ] ExpectFatalFailureTest.FailsWhenStatementReturns +[ RUN ] ExpectFatalFailureTest.FailsWhenStatementThrows +(expecting a failure) +gtest.cc:#: Failure +Expected: 1 fatal failure + Actual: 0 failures +Stack trace: (omitted) + +[ FAILED ] ExpectFatalFailureTest.FailsWhenStatementThrows [----------] 2 tests from TypedTest/0, where TypeParam = int [ RUN ] TypedTest/0.Success [ OK ] TypedTest/0.Success @@ -890,9 +906,9 @@ Failed Expected fatal failure. Stack trace: (omitted) -[==========] 74 tests from 34 test cases ran. +[==========] 76 tests from 34 test cases ran. [ PASSED ] 26 tests. -[ FAILED ] 48 tests, listed below: +[ FAILED ] 50 tests, listed below: [ FAILED ] NonfatalFailureTest.EscapesStringOperands [ FAILED ] NonfatalFailureTest.DiffForLongStrings [ FAILED ] FatalFailureTest.FatalFailureInSubroutine @@ -921,10 +937,12 @@ Stack trace: (omitted) [ FAILED ] ExpectNonfatalFailureTest.FailsWhenThereAreTwoNonfatalFailures [ FAILED ] ExpectNonfatalFailureTest.FailsWhenThereIsOneFatalFailure [ FAILED ] ExpectNonfatalFailureTest.FailsWhenStatementReturns +[ FAILED ] ExpectNonfatalFailureTest.FailsWhenStatementThrows [ FAILED ] ExpectFatalFailureTest.FailsWhenThereIsNoFatalFailure [ FAILED ] ExpectFatalFailureTest.FailsWhenThereAreTwoFatalFailures [ FAILED ] ExpectFatalFailureTest.FailsWhenThereIsOneNonfatalFailure [ FAILED ] ExpectFatalFailureTest.FailsWhenStatementReturns +[ FAILED ] ExpectFatalFailureTest.FailsWhenStatementThrows [ FAILED ] TypedTest/0.Failure, where TypeParam = int [ FAILED ] TypedTestWithNames/char0.Failure, where TypeParam = char [ FAILED ] TypedTestWithNames/int1.Failure, where TypeParam = int @@ -942,7 +960,7 @@ Stack trace: (omitted) [ FAILED ] PrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2 [ FAILED ] PrintingStrings/ParamTest.Failure/a, where GetParam() = "a" -48 FAILED TESTS +50 FAILED TESTS  YOU HAVE 1 DISABLED TEST Note: Google Test filter = FatalFailureTest.*:LoggingTest.* -- cgit v0.12