diff options
author | Jonny007-MKD <me@jonny007-mkd.de> | 2018-09-23 13:15:38 (GMT) |
---|---|---|
committer | Jonny007-MKD <me@jonny007-mkd.de> | 2018-09-23 13:15:38 (GMT) |
commit | 1cb10b357a8a96b54ae60d4103918892f58d7fb3 (patch) | |
tree | 0f974c09429f23f55a838cd2720819348ac669d5 /googletest/test/gtest_unittest.cc | |
parent | 258def01a68e3a4d080fee6d4502035218e61e38 (diff) | |
download | googletest-1cb10b357a8a96b54ae60d4103918892f58d7fb3.zip googletest-1cb10b357a8a96b54ae60d4103918892f58d7fb3.tar.gz googletest-1cb10b357a8a96b54ae60d4103918892f58d7fb3.tar.bz2 |
Readded changes from 6494f5232b130a29321e661166442bac324c4383
Diffstat (limited to 'googletest/test/gtest_unittest.cc')
-rw-r--r-- | googletest/test/gtest_unittest.cc | 45 |
1 files changed, 38 insertions, 7 deletions
diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index c03b367..6b75ab4 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -3328,6 +3328,9 @@ TEST_F(SingleEvaluationTest, OtherCases) { void ThrowAnInteger() { throw 1; } +void ThrowAnException(const char* what) { + throw std::runtime_error(what); +} // Tests that assertion arguments are evaluated exactly once. TEST_F(SingleEvaluationTest, ExceptionTests) { @@ -3370,6 +3373,20 @@ TEST_F(SingleEvaluationTest, ExceptionTests) { // failed EXPECT_ANY_THROW EXPECT_NONFATAL_FAILURE(EXPECT_ANY_THROW(a_++), "it doesn't"); EXPECT_EQ(7, a_); + + // failed EXPECT_THROW std::exception, throws different + EXPECT_NONFATAL_FAILURE(EXPECT_THROW({ // NOLINT + a_++; + ThrowAnInteger(); + }, std::exception), "throws a different type"); + EXPECT_EQ(8, a_); + + // failed EXPECT_THROW, throws std::exception + EXPECT_NONFATAL_FAILURE(EXPECT_THROW({ // NOLINT + a_++; + ThrowAnException("blablubb"); + }, bool), "throws a different type with message: blablubb"); + EXPECT_EQ(9, a_); } #endif // GTEST_HAS_EXCEPTIONS @@ -3802,6 +3819,11 @@ TEST(AssertionTest, ASSERT_THROW) { ASSERT_THROW(ThrowNothing(), bool), "Expected: ThrowNothing() throws an exception of type bool.\n" " Actual: it throws nothing."); + + EXPECT_FATAL_FAILURE( + ASSERT_THROW(ThrowAnException("buuh"), bool), + "Expected: ThrowAnException(\"buuh\") throws an exception of type bool.\n" + " Actual: it throws a different type with message: buuh"); } // Tests ASSERT_NO_THROW. @@ -3810,6 +3832,9 @@ TEST(AssertionTest, ASSERT_NO_THROW) { EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowAnInteger()), "Expected: ThrowAnInteger() doesn't throw an exception." "\n Actual: it throws."); + EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowAnException("blablubb")), + "Expected: ThrowAnException(\"blablubb\") doesn't throw an exception." + "\n Actual: it throws: blablubb"); } // Tests ASSERT_ANY_THROW. @@ -4536,13 +4561,16 @@ TEST(ExpectTest, EXPECT_GT) { // Tests EXPECT_THROW. TEST(ExpectTest, EXPECT_THROW) { EXPECT_THROW(ThrowAnInteger(), int); + EXPECT_THROW(ThrowAnException(""), std::exception); EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnInteger(), bool), - "Expected: ThrowAnInteger() throws an exception of " - "type bool.\n Actual: it throws a different type."); - EXPECT_NONFATAL_FAILURE( - EXPECT_THROW(ThrowNothing(), bool), - "Expected: ThrowNothing() throws an exception of type bool.\n" - " Actual: it throws nothing."); + "Expected: ThrowAnInteger() throws an exception of type bool.\n" + " Actual: it throws a different type."); + EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowNothing(), bool), + "Expected: ThrowNothing() throws an exception of type bool.\n" + " Actual: it throws nothing."); + EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnException("buuh"), bool), + "Expected: ThrowAnException(\"buuh\") throws an exception of type bool.\n" + " Actual: it throws a different type with message: buuh"); } // Tests EXPECT_NO_THROW. @@ -4551,6 +4579,9 @@ TEST(ExpectTest, EXPECT_NO_THROW) { EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowAnInteger()), "Expected: ThrowAnInteger() doesn't throw an " "exception.\n Actual: it throws."); + EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowAnException("blablubb")), + "Expected: ThrowAnException(\"blablubb\") doesn't throw an " + "exception.\n Actual: it throws: blablubb"); } // Tests EXPECT_ANY_THROW. @@ -6826,7 +6857,7 @@ TEST(ColoredOutputTest, UsesColorsWhenStdoutIsTty) { TEST(ColoredOutputTest, UsesColorsWhenTermSupportsColors) { GTEST_FLAG(color) = "auto"; -#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW +#if GTEST_OS_WINDOWS // On Windows, we ignore the TERM variable as it's usually not set. SetEnv("TERM", "dumb"); |