Skip to content

Commit

Permalink
Resolving issue CxxTest#53
Browse files Browse the repository at this point in the history
Changing try/catch logic within TS_ASSERT_THROWS to properly
catch std::exception without generating compiler warnings.
  • Loading branch information
whart222 committed Mar 16, 2013
1 parent 6ddbbd1 commit 4a92571
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
3 changes: 1 addition & 2 deletions cxxtest/TestSuite.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,7 @@ void doAssertSameFiles(const char* file, int line,
// TS_ASSERT_THROWS_ASSERT
# define ___TS_ASSERT_THROWS_ASSERT(f,l,e,t,a,m) { \
bool _ts_threw_expected = false, _ts_threw_else = false; \
_TS_TRY { e; } \
_TS_CATCH_TYPE( (t), { a; _ts_threw_expected = true; } ) \
_TS_TRY { try{ e; } _TS_CATCH_TYPE( (t), { a; _ts_threw_expected = true; } ) } \
_TS_CATCH_ABORT( { throw; } ) \
_TS_CATCH_STD( ex, { _ts_threw_expected = true; CxxTest::doFailAssertThrows((f), (l), #e, #t, true, (m), ex.what() ); } ) \
_TS_LAST_CATCH( { _ts_threw_else = true; } ) \
Expand Down
2 changes: 2 additions & 0 deletions sample/ExceptionTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class ExceptionTest : public CxxTest::TestSuite {
TS_ASSERT_EQUALS(throwThis(3), 333);
// You can assert that a function throws nothing
TS_ASSERT_THROWS_NOTHING(throwThis(-1));
// This assert fails, since throwThis() throws (Number)
TS_ASSERT_THROWS(throwThis(3), std::exception&);
// If you want to catch the exceptions yourself, use the ETS_ marcos
try {
ETS_ASSERT_EQUALS(throwThis(3), 333);
Expand Down
3 changes: 2 additions & 1 deletion test/error.out
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ ExceptionTest.h:18: Error: Expected (throwThis(5)) to throw (const char *) but i
ExceptionTest.h:20: Error: Expected (goodFunction(1)) to throw (...) but it didn't throw
ExceptionTest.h:22: Error: Test failed: Unhandled exception
ExceptionTest.h:24: Error: Expected (throwThis(-1)) not to throw, but it did
ExceptionTest.h:29: Error: Test failed: throwThis(3) failed
ExceptionTest.h:26: Error: Expected (throwThis(3)) to throw (std::exception&) but it threw something else
ExceptionTest.h:31: Error: Test failed: throwThis(3) failed
In FixtureTest::test_strcpy:
FixtureTest.h:28: Error: Expected (_buffer[1] == 'E'), found ('e' != 'E')
In MessageTest::testValues:
Expand Down
3 changes: 2 additions & 1 deletion test/paren.out
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ ExceptionTest.h(18): Error: Expected (throwThis(5)) to throw (const char *) but
ExceptionTest.h(20): Error: Expected (goodFunction(1)) to throw (...) but it didn't throw
ExceptionTest.h(22): Error: Test failed: Unhandled exception
ExceptionTest.h(24): Error: Expected (throwThis(-1)) not to throw, but it did
ExceptionTest.h(29): Error: Test failed: throwThis(3) failed
ExceptionTest.h(26): Error: Expected (throwThis(3)) to throw (std::exception&) but it threw something else
ExceptionTest.h(31): Error: Test failed: throwThis(3) failed
In FixtureTest::test_strcpy:
FixtureTest.h(28): Error: Expected (_buffer[1] == 'E'), found ('e' != 'E')
In MessageTest::testValues:
Expand Down

0 comments on commit 4a92571

Please sign in to comment.