]> git-server-git.apps.pok.os.sepia.ceph.com Git - googletest.git/commitdiff
Googletest export
authorAbseil Team <absl-team@google.com>
Mon, 22 Apr 2019 22:23:35 +0000 (18:23 -0400)
committerMatt Calabrese <calabrese@x.team>
Wed, 24 Apr 2019 13:34:40 +0000 (09:34 -0400)
Add GTEST_FAIL_AT, an equivalent to ADD_FAILURE_AT but that
spawns a fatal failure rather than a non-fatal, eg. the equivalent
of an ASSERT* failure rather than an EXPECT* failure.

PiperOrigin-RevId: 244746609

googletest/include/gtest/gtest.h
googletest/test/googletest-output-test-golden-lin.txt
googletest/test/googletest-output-test_.cc
googletest/test/gtest_unittest.cc

index 76f4098bf023ef9c8e2510a59d080ac0e4691546..7382442889f738ea9888b006d8392ec18161141e 100644 (file)
@@ -1900,6 +1900,11 @@ class TestWithParam : public Test, public WithParamInterface<T> {
 // Generates a fatal failure with a generic message.
 #define GTEST_FAIL() GTEST_FATAL_FAILURE_("Failed")
 
+// Like GTEST_FAIL(), but at the given source file location.
+#define GTEST_FAIL_AT(file, line)         \
+  GTEST_MESSAGE_AT_(file, line, "Failed", \
+                    ::testing::TestPartResult::kFatalFailure)
+
 // Define this macro to 1 to omit the definition of FAIL(), which is a
 // generic name and clashes with some other libraries.
 #if !GTEST_DONT_DEFINE_FAIL
index 29507fc024d9db11cb7a4a93c72d0e12a9ebd8fe..270b15ae6791f68af37799f527c34217e13cfc4c 100644 (file)
@@ -12,7 +12,7 @@ Expected equality of these values:
   3
 Stack trace: (omitted)
 
-\e[0;32m[==========] \e[mRunning 83 tests from 38 test suites.
+\e[0;32m[==========] \e[mRunning 84 tests from 39 test suites.
 \e[0;32m[----------] \e[mGlobal test environment set-up.
 FooEnvironment::SetUp() called.
 BarEnvironment::SetUp() called.
@@ -380,10 +380,18 @@ Stack trace: (omitted)
 \e[0;32m[ RUN      ] \e[mAddFailureAtTest.MessageContainsSpecifiedFileAndLineNumber
 foo.cc:42: Failure
 Failed
-Expected failure in foo.cc
+Expected nonfatal failure in foo.cc
 Stack trace: (omitted)
 
 \e[0;31m[  FAILED  ] \e[mAddFailureAtTest.MessageContainsSpecifiedFileAndLineNumber
+\e[0;32m[----------] \e[m1 test from GtestFailAtTest
+\e[0;32m[ RUN      ] \e[mGtestFailAtTest.MessageContainsSpecifiedFileAndLineNumber
+foo.cc:42: Failure
+Failed
+Expected fatal failure in foo.cc
+Stack trace: (omitted)
+
+\e[0;31m[  FAILED  ] \e[mGtestFailAtTest.MessageContainsSpecifiedFileAndLineNumber
 \e[0;32m[----------] \e[m4 tests from MixedUpTestSuiteTest
 \e[0;32m[ RUN      ] \e[mMixedUpTestSuiteTest.FirstTestFromNamespaceFoo
 \e[0;32m[       OK ] \e[mMixedUpTestSuiteTest.FirstTestFromNamespaceFoo
@@ -984,9 +992,9 @@ Failed
 Expected fatal failure.
 Stack trace: (omitted)
 
-\e[0;32m[==========] \e[m83 tests from 38 test suites ran.
+\e[0;32m[==========] \e[m84 tests from 39 test suites ran.
 \e[0;32m[  PASSED  ] \e[m30 tests.
-\e[0;31m[  FAILED  ] \e[m53 tests, listed below:
+\e[0;31m[  FAILED  ] \e[m54 tests, listed below:
 \e[0;31m[  FAILED  ] \e[mNonfatalFailureTest.EscapesStringOperands
 \e[0;31m[  FAILED  ] \e[mNonfatalFailureTest.DiffForLongStrings
 \e[0;31m[  FAILED  ] \e[mFatalFailureTest.FatalFailureInSubroutine
@@ -1006,6 +1014,7 @@ Stack trace: (omitted)
 \e[0;31m[  FAILED  ] \e[mNonFatalFailureInSetUpTest.FailureInSetUp
 \e[0;31m[  FAILED  ] \e[mFatalFailureInSetUpTest.FailureInSetUp
 \e[0;31m[  FAILED  ] \e[mAddFailureAtTest.MessageContainsSpecifiedFileAndLineNumber
+\e[0;31m[  FAILED  ] \e[mGtestFailAtTest.MessageContainsSpecifiedFileAndLineNumber
 \e[0;31m[  FAILED  ] \e[mMixedUpTestSuiteTest.ThisShouldFail
 \e[0;31m[  FAILED  ] \e[mMixedUpTestSuiteTest.ThisShouldFailToo
 \e[0;31m[  FAILED  ] \e[mMixedUpTestSuiteWithSameTestNameTest.TheSecondTestWithThisNameShouldFail
@@ -1041,7 +1050,7 @@ Stack trace: (omitted)
 \e[0;31m[  FAILED  ] \e[mPrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2
 \e[0;31m[  FAILED  ] \e[mPrintingStrings/ParamTest.Failure/a, where GetParam() = "a"
 
-53 FAILED TESTS
+54 FAILED TESTS
 \e[0;33m  YOU HAVE 1 DISABLED TEST
 
 \e[mNote: Google Test filter = FatalFailureTest.*:LoggingTest.*
index c6ce59e7a61272560f2237deb978b388741457bb..f1222b6a2dfa66665f944145a73d75dedec3f319 100644 (file)
@@ -461,7 +461,11 @@ TEST_F(FatalFailureInSetUpTest, FailureInSetUp) {
 }
 
 TEST(AddFailureAtTest, MessageContainsSpecifiedFileAndLineNumber) {
-  ADD_FAILURE_AT("foo.cc", 42) << "Expected failure in foo.cc";
+  ADD_FAILURE_AT("foo.cc", 42) << "Expected nonfatal failure in foo.cc";
+}
+
+TEST(GtestFailAtTest, MessageContainsSpecifiedFileAndLineNumber) {
+  GTEST_FAIL_AT("foo.cc", 42) << "Expected fatal failure in foo.cc";
 }
 
 #if GTEST_IS_THREADSAFE
index 28ced73888fed7a8f73c70dbc73ed5063450af25..d48105676f9e6baacc2cbad6ea65db627e3146c7 100644 (file)
@@ -4708,6 +4708,19 @@ TEST(MacroTest, FAIL) {
                        "Intentional failure.");
 }
 
+// Tests GTEST_FAIL_AT.
+TEST(MacroTest, GTEST_FAIL_AT) {
+  // Verifies that GTEST_FAIL_AT does generate a fatal failure and
+  // the failure message contains the user-streamed part.
+  EXPECT_FATAL_FAILURE(GTEST_FAIL_AT("foo.cc", 42) << "Wrong!", "Wrong!");
+
+  // Verifies that the user-streamed part is optional.
+  EXPECT_FATAL_FAILURE(GTEST_FAIL_AT("foo.cc", 42), "Failed");
+
+  // See the ADD_FAIL_AT test above to see how we test that the failure message
+  // contains the right filename and line number -- the same applies here.
+}
+
 // Tests SUCCEED
 TEST(MacroTest, SUCCEED) {
   SUCCEED();