summaryrefslogtreecommitdiffstats
path: root/googletest/test
diff options
context:
space:
mode:
authorAntoine Pitrou <antoine@python.org>2019-08-06 11:11:40 (GMT)
committerAntoine Pitrou <antoine@python.org>2019-08-06 11:11:40 (GMT)
commitc39ee9c460e6bb0b2b86209932b708ddaaf69695 (patch)
treebfdaa24afb4f86592c1065836bbacd7487241c07 /googletest/test
parent11be5f534cfca1139880dd66727c15f5bd1e0780 (diff)
downloadgoogletest-c39ee9c460e6bb0b2b86209932b708ddaaf69695.zip
googletest-c39ee9c460e6bb0b2b86209932b708ddaaf69695.tar.gz
googletest-c39ee9c460e6bb0b2b86209932b708ddaaf69695.tar.bz2
Fix #2371: Redirect Windows CRT assertions to stderrrefs/pull/2372/head
Diffstat (limited to 'googletest/test')
-rw-r--r--googletest/test/googletest-death-test-test.cc56
1 files changed, 56 insertions, 0 deletions
diff --git a/googletest/test/googletest-death-test-test.cc b/googletest/test/googletest-death-test-test.cc
index 6c71fd8..814d771 100644
--- a/googletest/test/googletest-death-test-test.cc
+++ b/googletest/test/googletest-death-test-test.cc
@@ -41,7 +41,9 @@ using testing::internal::AlwaysTrue;
#if GTEST_HAS_DEATH_TEST
# if GTEST_OS_WINDOWS
+# include <fcntl.h> // For O_BINARY
# include <direct.h> // For chdir().
+# include <io.h>
# else
# include <unistd.h>
# include <sys/wait.h> // For waitpid.
@@ -202,6 +204,26 @@ int DieInDebugElse12(int* sideeffect) {
return 12;
}
+# if GTEST_OS_WINDOWS
+
+// Death in dbg due to Windows CRT assertion failure, not opt.
+int DieInCRTDebugElse12(int* sideeffect) {
+ if (sideeffect) *sideeffect = 12;
+
+ // Create an invalid fd by closing a valid one
+ int fdpipe[2];
+ EXPECT_EQ(_pipe(fdpipe, 256, O_BINARY), 0);
+ EXPECT_EQ(_close(fdpipe[0]), 0);
+ EXPECT_EQ(_close(fdpipe[1]), 0);
+
+ // _dup() should crash in debug mode
+ EXPECT_EQ(_dup(fdpipe[0]), -1);
+
+ return 12;
+}
+
+#endif // GTEST_OS_WINDOWS
+
# if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
// Tests the ExitedWithCode predicate.
@@ -632,6 +654,40 @@ TEST_F(TestForDeathTest, TestExpectDebugDeath) {
# endif
}
+# if GTEST_OS_WINDOWS
+
+// Tests that EXPECT_DEBUG_DEATH works as expected when in debug mode
+// the Windows CRT crashes the process with an assertion failure.
+// 1. Asserts on death.
+// 2. Has no side effect (doesn't pop up a window or wait for user input).
+//
+// And in opt mode, it:
+// 1. Has side effects but does not assert.
+TEST_F(TestForDeathTest, CRTDebugDeath) {
+ int sideeffect = 0;
+
+ // Put the regex in a local variable to make sure we don't get an "unused"
+ // warning in opt mode.
+ const char* regex = "dup.* : Assertion failed";
+
+ EXPECT_DEBUG_DEATH(DieInCRTDebugElse12(&sideeffect), regex)
+ << "Must accept a streamed message";
+
+# ifdef NDEBUG
+
+ // Checks that the assignment occurs in opt mode (sideeffect).
+ EXPECT_EQ(12, sideeffect);
+
+# else
+
+ // Checks that the assignment does not occur in dbg mode (no sideeffect).
+ EXPECT_EQ(0, sideeffect);
+
+# endif
+}
+
+# endif // GTEST_OS_WINDOWS
+
// Tests that ASSERT_DEBUG_DEATH works as expected, that is, you can stream a
// message to it, and in debug mode it:
// 1. Asserts on death.