Skip to content

Commit 24358f8

Browse files
committed
Merge pull request cpputest#96 from martiert/master
Make all tests that checks if something throws use the EXPECT_THROWS
2 parents 5f5a518 + 919b488 commit 24358f8

File tree

1 file changed

+6
-32
lines changed

1 file changed

+6
-32
lines changed

tests/MemoryLeakOperatorOverloadsTest.cpp

+6-32
Original file line numberDiff line numberDiff line change
@@ -262,22 +262,12 @@ TEST_GROUP(OutOfMemoryTestsForOperatorNew)
262262

263263
TEST(OutOfMemoryTestsForOperatorNew, FailingNewOperatorThrowsAnExceptionWhenUsingStdCppNew)
264264
{
265-
try {
266-
new char;
267-
FAIL("Should have thrown an exception!")
268-
}
269-
catch (std::bad_alloc&) {
270-
}
265+
CHECK_THROWS(std::bad_alloc, new char);
271266
}
272267

273268
TEST(OutOfMemoryTestsForOperatorNew, FailingNewArrayOperatorThrowsAnExceptionWhenUsingStdCppNew)
274269
{
275-
try {
276-
new char[10];
277-
FAIL("Should have thrown an exception!")
278-
}
279-
catch (std::bad_alloc&) {
280-
}
270+
CHECK_THROWS(std::bad_alloc, new char[10]);
281271
}
282272

283273
class ClassThatThrowsAnExceptionInTheConstructor
@@ -294,18 +284,12 @@ TEST_GROUP(TestForExceptionsInConstructor)
294284

295285
TEST(TestForExceptionsInConstructor,ConstructorThrowsAnException)
296286
{
297-
try {
298-
new ClassThatThrowsAnExceptionInTheConstructor();
299-
}catch(...){
300-
}
287+
CHECK_THROWS(int, new ClassThatThrowsAnExceptionInTheConstructor);
301288
}
302289

303290
TEST(TestForExceptionsInConstructor,ConstructorThrowsAnExceptionAllocatedAsArray)
304291
{
305-
try {
306-
new ClassThatThrowsAnExceptionInTheConstructor[10];
307-
}catch(...){
308-
}
292+
CHECK_THROWS(int, new ClassThatThrowsAnExceptionInTheConstructor[10]);
309293
}
310294

311295
#else
@@ -356,22 +340,12 @@ static char* some_memory;
356340

357341
TEST(OutOfMemoryTestsForOperatorNew, FailingNewOperatorThrowsAnExceptionWhenUsingStdCppNewWithoutOverride)
358342
{
359-
try {
360-
some_memory = new char;
361-
FAIL("Should have thrown an exception!")
362-
}
363-
catch (std::bad_alloc&) {
364-
}
343+
CHECK_THROWS(std::bad_alloc, some_memory = new char);
365344
}
366345

367346
TEST(OutOfMemoryTestsForOperatorNew, FailingNewArrayOperatorThrowsAnExceptionWhenUsingStdCppNewWithoutOverride)
368347
{
369-
try {
370-
some_memory = new char[10];
371-
FAIL("Should have thrown an exception!")
372-
}
373-
catch (std::bad_alloc&) {
374-
}
348+
CHECK_THROWS(std::bad_alloc, some_memory = new char[10]);
375349
}
376350

377351
TEST(OutOfMemoryTestsForOperatorNew, FailingNewOperatorReturnsNullWithoutOverride)

0 commit comments

Comments
 (0)