proxygen
gtest-death-test_test.cc File Reference
#include "gtest/gtest-death-test.h"
#include "gtest/gtest.h"
#include "gtest/internal/gtest-filepath.h"

Go to the source code of this file.

Functions

 TEST (ConditionalDeathMacrosTest, WarnsWhenDeathTestsNotAvailable)
 
void FuncWithAssert (int *n)
 
 TEST (ConditionalDeathMacrosTest, AssertDeatDoesNotReturnhIfUnsupported)
 
 TEST (ConditionalDeathMacrosSyntaxDeathTest, SingleStatement)
 
 TEST (ConditionalDeathMacrosSyntaxDeathTest, SwitchStatement)
 
 TEST (NotADeathTest, Test)
 

Function Documentation

void FuncWithAssert ( int *  n)

Definition at line 1363 of file gtest-death-test_test.cc.

References ASSERT_DEATH_IF_SUPPORTED.

Referenced by TEST().

1363  {
1364  ASSERT_DEATH_IF_SUPPORTED(return;, "");
1365  (*n)++;
1366 }
#define ASSERT_DEATH_IF_SUPPORTED(statement, regex)
TEST ( ConditionalDeathMacrosTest  ,
WarnsWhenDeathTestsNotAvailable   
)

Definition at line 1334 of file gtest-death-test_test.cc.

References ASSERT_DEATH_IF_SUPPORTED, ASSERT_TRUE, testing::internal::CaptureStderr(), EXPECT_DEATH_IF_SUPPORTED, testing::internal::GetCapturedStderr(), gmock_output_test::output, and string.

1334  {
1335  // Empty statement will not crash, but that should not trigger a failure
1336  // when death tests are not supported.
1337  CaptureStderr();
1340  ASSERT_TRUE(NULL != strstr(output.c_str(),
1341  "Death tests are not supported on this platform"));
1342  ASSERT_TRUE(NULL != strstr(output.c_str(), ";"));
1343 
1344  // The streamed message should not be printed as there is no test failure.
1345  CaptureStderr();
1346  EXPECT_DEATH_IF_SUPPORTED(;, "") << "streamed message";
1347  output = GetCapturedStderr();
1348  ASSERT_TRUE(NULL == strstr(output.c_str(), "streamed message"));
1349 
1350  CaptureStderr();
1351  ASSERT_DEATH_IF_SUPPORTED(;, ""); // NOLINT
1352  output = GetCapturedStderr();
1353  ASSERT_TRUE(NULL != strstr(output.c_str(),
1354  "Death tests are not supported on this platform"));
1355  ASSERT_TRUE(NULL != strstr(output.c_str(), ";"));
1356 
1357  CaptureStderr();
1358  ASSERT_DEATH_IF_SUPPORTED(;, "") << "streamed message"; // NOLINT
1359  output = GetCapturedStderr();
1360  ASSERT_TRUE(NULL == strstr(output.c_str(), "streamed message"));
1361 }
#define ASSERT_DEATH_IF_SUPPORTED(statement, regex)
std::string GetCapturedStderr()
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
const char * string
Definition: Conv.cpp:212
#define ASSERT_TRUE(condition)
Definition: gtest.h:1865
TEST ( ConditionalDeathMacrosTest  ,
AssertDeatDoesNotReturnhIfUnsupported   
)

Definition at line 1370 of file gtest-death-test_test.cc.

References EXPECT_EQ, and FuncWithAssert().

1370  {
1371  int n = 0;
1372  FuncWithAssert(&n);
1373  EXPECT_EQ(1, n);
1374 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
void FuncWithAssert(int *n)
TEST ( ConditionalDeathMacrosSyntaxDeathTest  ,
SingleStatement   
)

Definition at line 1383 of file gtest-death-test_test.cc.

References testing::internal::AlwaysFalse(), testing::internal::AlwaysTrue(), ASSERT_DEATH_IF_SUPPORTED, and EXPECT_DEATH_IF_SUPPORTED.

1383  {
1384  if (AlwaysFalse())
1385  // This would fail if executed; this is a compilation test only
1386  ASSERT_DEATH_IF_SUPPORTED(return, "");
1387 
1388  if (AlwaysTrue())
1389  EXPECT_DEATH_IF_SUPPORTED(_exit(1), "");
1390  else
1391  // This empty "else" branch is meant to ensure that EXPECT_DEATH
1392  // doesn't expand into an "if" statement without an "else"
1393  ; // NOLINT
1394 
1395  if (AlwaysFalse())
1396  ASSERT_DEATH_IF_SUPPORTED(return, "") << "did not die";
1397 
1398  if (AlwaysFalse())
1399  ; // NOLINT
1400  else
1401  EXPECT_DEATH_IF_SUPPORTED(_exit(1), "") << 1 << 2 << 3;
1402 }
#define ASSERT_DEATH_IF_SUPPORTED(statement, regex)
GTEST_API_ bool AlwaysTrue()
Definition: gtest.cc:4988
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
TEST ( ConditionalDeathMacrosSyntaxDeathTest  ,
SwitchStatement   
)

Definition at line 1406 of file gtest-death-test_test.cc.

References ASSERT_DEATH_IF_SUPPORTED, EXPECT_DEATH_IF_SUPPORTED, GTEST_DISABLE_MSC_WARNINGS_POP_, and GTEST_DISABLE_MSC_WARNINGS_PUSH_.

1406  {
1407  // Microsoft compiler usually complains about switch statements without
1408  // case labels. We suppress that warning for this test.
1410 
1411  switch (0)
1412  default:
1413  ASSERT_DEATH_IF_SUPPORTED(_exit(1), "")
1414  << "exit in default switch handler";
1415 
1416  switch (0)
1417  case 0:
1418  EXPECT_DEATH_IF_SUPPORTED(_exit(1), "") << "exit in switch case";
1419 
1421 }
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
Definition: gtest-port.h:317
#define ASSERT_DEATH_IF_SUPPORTED(statement, regex)
void handler(int, siginfo_t *, void *)
#define EXPECT_DEATH_IF_SUPPORTED(statement, regex)
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
Definition: gtest-port.h:318
default
Definition: upload.py:394
TEST ( NotADeathTest  ,
Test   
)

Definition at line 1425 of file gtest-death-test_test.cc.

References SUCCEED.

1425  {
1426  SUCCEED();
1427 }
#define SUCCEED()
Definition: gtest.h:1831