• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Created by Martin on 01/08/2017.
3  *
4  *  Distributed under the Boost Software License, Version 1.0. (See accompanying
5  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6  */
7 #ifndef TWOBLUECUBES_CATCH_ENFORCE_H_INCLUDED
8 #define TWOBLUECUBES_CATCH_ENFORCE_H_INCLUDED
9 
10 #include "catch_common.h"
11 #include "catch_compiler_capabilities.h"
12 #include "catch_stream.h"
13 
14 #include <exception>
15 
16 namespace Catch {
17 #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
18     template <typename Ex>
19     [[noreturn]]
throw_exception(Ex const & e)20     void throw_exception(Ex const& e) {
21         throw e;
22     }
23 #else // ^^ Exceptions are enabled //  Exceptions are disabled vv
24     [[noreturn]]
25     void throw_exception(std::exception const& e);
26 #endif
27 
28     [[noreturn]]
29     void throw_logic_error(std::string const& msg);
30     [[noreturn]]
31     void throw_domain_error(std::string const& msg);
32     [[noreturn]]
33     void throw_runtime_error(std::string const& msg);
34 
35 } // namespace Catch;
36 
37 #define CATCH_MAKE_MSG(...) \
38     (Catch::ReusableStringStream() << __VA_ARGS__).str()
39 
40 #define CATCH_INTERNAL_ERROR(...) \
41     Catch::throw_logic_error(CATCH_MAKE_MSG( CATCH_INTERNAL_LINEINFO << ": Internal Catch2 error: " << __VA_ARGS__))
42 
43 #define CATCH_ERROR(...) \
44     Catch::throw_domain_error(CATCH_MAKE_MSG( __VA_ARGS__ ))
45 
46 #define CATCH_RUNTIME_ERROR(...) \
47     Catch::throw_runtime_error(CATCH_MAKE_MSG( __VA_ARGS__ ))
48 
49 #define CATCH_ENFORCE( condition, ... ) \
50     do{ if( !(condition) ) CATCH_ERROR( __VA_ARGS__ ); } while(false)
51 
52 
53 #endif // TWOBLUECUBES_CATCH_ENFORCE_H_INCLUDED
54