gtest-death-test.h (googletest-release-1.10.0) | : | gtest-death-test.h (googletest-release-1.11.0) | ||
---|---|---|---|---|
skipping to change at line 38 | skipping to change at line 38 | |||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||
// | // | |||
// The Google C++ Testing and Mocking Framework (Google Test) | // The Google C++ Testing and Mocking Framework (Google Test) | |||
// | // | |||
// This header file defines the public API for death tests. It is | // This header file defines the public API for death tests. It is | |||
// #included by gtest.h so a user doesn't need to include this | // #included by gtest.h so a user doesn't need to include this | |||
// directly. | // directly. | |||
// GOOGLETEST_CM0001 DO NOT DELETE | // GOOGLETEST_CM0001 DO NOT DELETE | |||
#ifndef GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_ | #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_ | |||
#define GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_ | #define GOOGLETEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_ | |||
#include "gtest/internal/gtest-death-test-internal.h" | #include "gtest/internal/gtest-death-test-internal.h" | |||
namespace testing { | namespace testing { | |||
// This flag controls the style of death tests. Valid values are "threadsafe", | // This flag controls the style of death tests. Valid values are "threadsafe", | |||
// meaning that the death test child process will re-execute the test binary | // meaning that the death test child process will re-execute the test binary | |||
// from the start, running only a single death test, or "fast", | // from the start, running only a single death test, or "fast", | |||
// meaning that the child process will execute the test logic immediately | // meaning that the child process will execute the test logic immediately | |||
// after forking. | // after forking. | |||
skipping to change at line 100 | skipping to change at line 100 | |||
// } | // } | |||
// | // | |||
// ASSERT_EXIT(server.ExitNow(), ::testing::ExitedWithCode(0), "Exiting"); | // ASSERT_EXIT(server.ExitNow(), ::testing::ExitedWithCode(0), "Exiting"); | |||
// | // | |||
// bool KilledBySIGHUP(int exit_code) { | // bool KilledBySIGHUP(int exit_code) { | |||
// return WIFSIGNALED(exit_code) && WTERMSIG(exit_code) == SIGHUP; | // return WIFSIGNALED(exit_code) && WTERMSIG(exit_code) == SIGHUP; | |||
// } | // } | |||
// | // | |||
// ASSERT_EXIT(client.HangUpServer(), KilledBySIGHUP, "Hanging up!"); | // ASSERT_EXIT(client.HangUpServer(), KilledBySIGHUP, "Hanging up!"); | |||
// | // | |||
// The final parameter to each of these macros is a matcher applied to any data | ||||
// the sub-process wrote to stderr. For compatibility with existing tests, a | ||||
// bare string is interpreted as a regular expression matcher. | ||||
// | ||||
// On the regular expressions used in death tests: | // On the regular expressions used in death tests: | |||
// | // | |||
// GOOGLETEST_CM0005 DO NOT DELETE | // GOOGLETEST_CM0005 DO NOT DELETE | |||
// On POSIX-compliant systems (*nix), we use the <regex.h> library, | // On POSIX-compliant systems (*nix), we use the <regex.h> library, | |||
// which uses the POSIX extended regex syntax. | // which uses the POSIX extended regex syntax. | |||
// | // | |||
// On other platforms (e.g. Windows or Mac), we only support a simple regex | // On other platforms (e.g. Windows or Mac), we only support a simple regex | |||
// syntax implemented as part of Google Test. This limited | // syntax implemented as part of Google Test. This limited | |||
// implementation should be enough most of the time when writing | // implementation should be enough most of the time when writing | |||
// death tests; though it lacks many features you can find in PCRE | // death tests; though it lacks many features you can find in PCRE | |||
skipping to change at line 165 | skipping to change at line 169 | |||
// program from argv[0] and re-executes it in the sub-process. For | // program from argv[0] and re-executes it in the sub-process. For | |||
// simplicity, the current implementation doesn't search the PATH | // simplicity, the current implementation doesn't search the PATH | |||
// when launching the sub-process. This means that the user must | // when launching the sub-process. This means that the user must | |||
// invoke the test program via a path that contains at least one | // invoke the test program via a path that contains at least one | |||
// path separator (e.g. path/to/foo_test and | // path separator (e.g. path/to/foo_test and | |||
// /absolute/path/to/bar_test are fine, but foo_test is not). This | // /absolute/path/to/bar_test are fine, but foo_test is not). This | |||
// is rarely a problem as people usually don't put the test binary | // is rarely a problem as people usually don't put the test binary | |||
// directory in PATH. | // directory in PATH. | |||
// | // | |||
// Asserts that a given statement causes the program to exit, with an | // Asserts that a given `statement` causes the program to exit, with an | |||
// integer exit status that satisfies predicate, and emitting error output | // integer exit status that satisfies `predicate`, and emitting error output | |||
// that matches regex. | // that matches `matcher`. | |||
# define ASSERT_EXIT(statement, predicate, regex) \ | # define ASSERT_EXIT(statement, predicate, matcher) \ | |||
GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_FATAL_FAILURE_) | GTEST_DEATH_TEST_(statement, predicate, matcher, GTEST_FATAL_FAILURE_) | |||
// Like ASSERT_EXIT, but continues on to successive tests in the | // Like `ASSERT_EXIT`, but continues on to successive tests in the | |||
// test suite, if any: | // test suite, if any: | |||
# define EXPECT_EXIT(statement, predicate, regex) \ | # define EXPECT_EXIT(statement, predicate, matcher) \ | |||
GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_NONFATAL_FAILURE_) | GTEST_DEATH_TEST_(statement, predicate, matcher, GTEST_NONFATAL_FAILURE_) | |||
// Asserts that a given statement causes the program to exit, either by | // Asserts that a given `statement` causes the program to exit, either by | |||
// explicitly exiting with a nonzero exit code or being killed by a | // explicitly exiting with a nonzero exit code or being killed by a | |||
// signal, and emitting error output that matches regex. | // signal, and emitting error output that matches `matcher`. | |||
# define ASSERT_DEATH(statement, regex) \ | # define ASSERT_DEATH(statement, matcher) \ | |||
ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex) | ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, matcher) | |||
// Like ASSERT_DEATH, but continues on to successive tests in the | // Like `ASSERT_DEATH`, but continues on to successive tests in the | |||
// test suite, if any: | // test suite, if any: | |||
# define EXPECT_DEATH(statement, regex) \ | # define EXPECT_DEATH(statement, matcher) \ | |||
EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex) | EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, matcher) | |||
// Two predicate classes that can be used in {ASSERT,EXPECT}_EXIT*: | // Two predicate classes that can be used in {ASSERT,EXPECT}_EXIT*: | |||
// Tests that an exit code describes a normal exit with a given exit code. | // Tests that an exit code describes a normal exit with a given exit code. | |||
class GTEST_API_ ExitedWithCode { | class GTEST_API_ ExitedWithCode { | |||
public: | public: | |||
explicit ExitedWithCode(int exit_code); | explicit ExitedWithCode(int exit_code); | |||
ExitedWithCode(const ExitedWithCode&) = default; | ||||
void operator=(const ExitedWithCode& other) = delete; | ||||
bool operator()(int exit_status) const; | bool operator()(int exit_status) const; | |||
private: | private: | |||
// No implementation - assignment is unsupported. | ||||
void operator=(const ExitedWithCode& other); | ||||
const int exit_code_; | const int exit_code_; | |||
}; | }; | |||
# if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA | # if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA | |||
// Tests that an exit code describes an exit due to termination by a | // Tests that an exit code describes an exit due to termination by a | |||
// given signal. | // given signal. | |||
// GOOGLETEST_CM0006 DO NOT DELETE | // GOOGLETEST_CM0006 DO NOT DELETE | |||
class GTEST_API_ KilledBySignal { | class GTEST_API_ KilledBySignal { | |||
public: | public: | |||
explicit KilledBySignal(int signum); | explicit KilledBySignal(int signum); | |||
skipping to change at line 343 | skipping to change at line 346 | |||
ASSERT_DEATH(statement, regex) | ASSERT_DEATH(statement, regex) | |||
#else | #else | |||
# define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \ | # define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \ | |||
GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, ) | GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, ) | |||
# define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \ | # define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \ | |||
GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, return) | GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, return) | |||
#endif | #endif | |||
} // namespace testing | } // namespace testing | |||
#endif // GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_ | #endif // GOOGLETEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_ | |||
End of changes. 12 change blocks. | ||||
20 lines changed or deleted | 23 lines changed or added |