26
26
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
27
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
28
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+
29
30
//
30
- // Author: [email protected] (Zhanyong Wan)
31
- //
32
- // The Google C++ Testing Framework (Google Test)
31
+ // The Google C++ Testing and Mocking Framework (Google Test)
33
32
//
34
33
// This header file defines the public API for death tests. It is
35
34
// #included by gtest.h so a user doesn't need to include this
36
35
// directly.
36
+ // GOOGLETEST_CM0001 DO NOT DELETE
37
37
38
- #ifndef GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
39
- #define GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
38
+ #ifndef GOOGLETEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
39
+ #define GOOGLETEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
40
40
41
41
#include " gtest/internal/gtest-death-test-internal.h"
42
42
@@ -97,8 +97,13 @@ GTEST_API_ bool InDeathTestChild();
97
97
//
98
98
// ASSERT_EXIT(client.HangUpServer(), KilledBySIGHUP, "Hanging up!");
99
99
//
100
+ // The final parameter to each of these macros is a matcher applied to any data
101
+ // the sub-process wrote to stderr. For compatibility with existing tests, a
102
+ // bare string is interpreted as a regular expression matcher.
103
+ //
100
104
// On the regular expressions used in death tests:
101
105
//
106
+ // GOOGLETEST_CM0005 DO NOT DELETE
102
107
// On POSIX-compliant systems (*nix), we use the <regex.h> library,
103
108
// which uses the POSIX extended regex syntax.
104
109
//
@@ -160,47 +165,46 @@ GTEST_API_ bool InDeathTestChild();
160
165
// is rarely a problem as people usually don't put the test binary
161
166
// directory in PATH.
162
167
//
163
- // TODO([email protected] ): make thread-safe death tests search the PATH.
164
168
165
- // Asserts that a given statement causes the program to exit, with an
166
- // integer exit status that satisfies predicate, and emitting error output
167
- // that matches regex .
168
- # define ASSERT_EXIT (statement, predicate, regex ) \
169
- GTEST_DEATH_TEST_ (statement, predicate, regex , GTEST_FATAL_FAILURE_)
169
+ // Asserts that a given ` statement` causes the program to exit, with an
170
+ // integer exit status that satisfies ` predicate` , and emitting error output
171
+ // that matches `matcher` .
172
+ # define ASSERT_EXIT (statement, predicate, matcher ) \
173
+ GTEST_DEATH_TEST_ (statement, predicate, matcher , GTEST_FATAL_FAILURE_)
170
174
171
- // Like ASSERT_EXIT, but continues on to successive tests in the
172
- // test case , if any:
173
- # define EXPECT_EXIT (statement, predicate, regex ) \
174
- GTEST_DEATH_TEST_ (statement, predicate, regex , GTEST_NONFATAL_FAILURE_)
175
+ // Like ` ASSERT_EXIT` , but continues on to successive tests in the
176
+ // test suite , if any:
177
+ # define EXPECT_EXIT (statement, predicate, matcher ) \
178
+ GTEST_DEATH_TEST_ (statement, predicate, matcher , GTEST_NONFATAL_FAILURE_)
175
179
176
- // Asserts that a given statement causes the program to exit, either by
180
+ // Asserts that a given ` statement` causes the program to exit, either by
177
181
// explicitly exiting with a nonzero exit code or being killed by a
178
- // signal, and emitting error output that matches regex .
179
- # define ASSERT_DEATH (statement, regex ) \
180
- ASSERT_EXIT (statement, ::testing::internal::ExitedUnsuccessfully, regex )
182
+ // signal, and emitting error output that matches `matcher` .
183
+ # define ASSERT_DEATH (statement, matcher ) \
184
+ ASSERT_EXIT (statement, ::testing::internal::ExitedUnsuccessfully, matcher )
181
185
182
- // Like ASSERT_DEATH, but continues on to successive tests in the
183
- // test case , if any:
184
- # define EXPECT_DEATH (statement, regex ) \
185
- EXPECT_EXIT (statement, ::testing::internal::ExitedUnsuccessfully, regex )
186
+ // Like ` ASSERT_DEATH` , but continues on to successive tests in the
187
+ // test suite , if any:
188
+ # define EXPECT_DEATH (statement, matcher ) \
189
+ EXPECT_EXIT (statement, ::testing::internal::ExitedUnsuccessfully, matcher )
186
190
187
191
// Two predicate classes that can be used in {ASSERT,EXPECT}_EXIT*:
188
192
189
193
// Tests that an exit code describes a normal exit with a given exit code.
190
194
class GTEST_API_ ExitedWithCode {
191
195
public:
192
196
explicit ExitedWithCode (int exit_code);
197
+ ExitedWithCode (const ExitedWithCode&) = default ;
198
+ void operator =(const ExitedWithCode& other) = delete ;
193
199
bool operator ()(int exit_status) const ;
194
200
private:
195
- // No implementation - assignment is unsupported.
196
- void operator =(const ExitedWithCode& other);
197
-
198
201
const int exit_code_;
199
202
};
200
203
201
204
# if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA
202
205
// Tests that an exit code describes an exit due to termination by a
203
206
// given signal.
207
+ // GOOGLETEST_CM0006 DO NOT DELETE
204
208
class GTEST_API_ KilledBySignal {
205
209
public:
206
210
explicit KilledBySignal (int signum);
@@ -226,7 +230,7 @@ class GTEST_API_ KilledBySignal {
226
230
// return 12;
227
231
// }
228
232
//
229
- // TEST(TestCase , TestDieOr12WorksInDgbAndOpt) {
233
+ // TEST(TestSuite , TestDieOr12WorksInDgbAndOpt) {
230
234
// int sideeffect = 0;
231
235
// // Only asserts in dbg.
232
236
// EXPECT_DEBUG_DEATH(DieInDebugOr12(&sideeffect), "death");
@@ -275,20 +279,20 @@ class GTEST_API_ KilledBySignal {
275
279
// This macro is used for implementing macros such as
276
280
// EXPECT_DEATH_IF_SUPPORTED and ASSERT_DEATH_IF_SUPPORTED on systems where
277
281
// death tests are not supported. Those macros must compile on such systems
278
- // iff EXPECT_DEATH and ASSERT_DEATH compile with the same parameters on
279
- // systems that support death tests. This allows one to write such a macro
280
- // on a system that does not support death tests and be sure that it will
281
- // compile on a death-test supporting system. It is exposed publicly so that
282
- // systems that have death-tests with stricter requirements than
283
- // GTEST_HAS_DEATH_TEST can write their own equivalent of
284
- // EXPECT_DEATH_IF_SUPPORTED and ASSERT_DEATH_IF_SUPPORTED.
282
+ // if and only if EXPECT_DEATH and ASSERT_DEATH compile with the same parameters
283
+ // on systems that support death tests. This allows one to write such a macro on
284
+ // a system that does not support death tests and be sure that it will compile
285
+ // on a death-test supporting system. It is exposed publicly so that systems
286
+ // that have death-tests with stricter requirements than GTEST_HAS_DEATH_TEST
287
+ // can write their own equivalent of EXPECT_DEATH_IF_SUPPORTED and
288
+ // ASSERT_DEATH_IF_SUPPORTED.
285
289
//
286
290
// Parameters:
287
291
// statement - A statement that a macro such as EXPECT_DEATH would test
288
292
// for program termination. This macro has to make sure this
289
293
// statement is compiled but not executed, to ensure that
290
294
// EXPECT_DEATH_IF_SUPPORTED compiles with a certain
291
- // parameter iff EXPECT_DEATH compiles with it.
295
+ // parameter if and only if EXPECT_DEATH compiles with it.
292
296
// regex - A regex that a macro such as EXPECT_DEATH would use to test
293
297
// the output of statement. This parameter has to be
294
298
// compiled but not evaluated by this macro, to ensure that
@@ -339,4 +343,4 @@ class GTEST_API_ KilledBySignal {
339
343
340
344
} // namespace testing
341
345
342
- #endif // GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
346
+ #endif // GOOGLETEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_
0 commit comments