diff options
| author | Phil Nash | 2010-11-09 23:24:00 +0000 |
|---|---|---|
| committer | Phil Nash | 2010-11-09 23:24:00 +0000 |
| commit | d80260001bdc4811b5c63604041e3139fb80ecd4 (patch) | |
| tree | fa429b6436db26c905416a92c555d6dca11c73bf /Test/ExceptionTests.cpp | |
| download | catch3-d80260001bdc4811b5c63604041e3139fb80ecd4.tar.gz | |
First commit for GitHub
Diffstat (limited to 'Test/ExceptionTests.cpp')
| -rw-r--r-- | Test/ExceptionTests.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/Test/ExceptionTests.cpp b/Test/ExceptionTests.cpp new file mode 100644 index 00000000..3bb222ee --- /dev/null +++ b/Test/ExceptionTests.cpp @@ -0,0 +1,58 @@ +/* + * ExceptionTests.cpp + * Catch - Test + * + * Created by Phil on 09/11/2010. + * Copyright 2010 Two Blue Cubes Ltd. All rights reserved. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + * + */ + +#include "catch.hpp" + +#include <string> + +namespace +{ + int thisThrows() + { + throw std::domain_error( "expected exception" ); + } + + int thisDoesntThrow() + { + return 0; + } +} + +TEST_CASE( "succeeding/exceptions/explicit", "When checked exceptions are thrown they can be expected or unexpected" ) +{ + CHECK_THROWS_AS( thisThrows(), std::domain_error ); + CHECK_NOTHROW( thisDoesntThrow() ); + EXPECT_THROWS( thisThrows() ); +} + +TEST_CASE( "failing/exceptions/explicit", "When checked exceptions are thrown they can be expected or unexpected" ) +{ + CHECK_THROWS_AS( thisThrows(), std::string ); + CHECK_THROWS_AS( thisDoesntThrow(), std::domain_error ); + CHECK_NOTHROW( thisThrows() ); +} + +TEST_CASE( "failing/exceptions/implicit", "When unchecked exceptions are thrown they are always failures" ) +{ + throw std::domain_error( "unexpected exception" ); +} + +TEST_CASE( "succeeding/exceptions/implicit", "When unchecked exceptions are thrown, but caught, they do not affect the test" ) +{ + try + { + throw std::domain_error( "unexpected exception" ); + } + catch(...) + { + } +} |