2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2015-01-11 17:03:30 +00:00
|
|
|
Copyright (c) 2011-2015 Bolero MURAKAMI
|
2013-08-08 09:54:33 +00:00
|
|
|
https://github.com/bolero-MURAKAMI/Sprout
|
|
|
|
|
|
|
|
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)
|
|
|
|
=============================================================================*/
|
2013-01-03 08:01:50 +00:00
|
|
|
#ifndef TESTSPR_ASSERT_HPP
|
|
|
|
#define TESTSPR_ASSERT_HPP
|
|
|
|
|
2013-09-26 13:43:57 +00:00
|
|
|
#include <string>
|
|
|
|
#include <stdexcept>
|
2014-03-01 01:35:24 +00:00
|
|
|
#include <sprout/assert.hpp>
|
2013-01-03 08:01:50 +00:00
|
|
|
#ifdef TESTSPR_CONFIG_ENABLE_STATIC_WARNING
|
2014-03-01 01:35:24 +00:00
|
|
|
# include <sprout/static_warning.hpp>
|
2013-01-03 08:01:50 +00:00
|
|
|
#endif
|
2013-09-26 13:43:57 +00:00
|
|
|
|
|
|
|
namespace testspr {
|
|
|
|
//
|
|
|
|
// assertion_failed
|
|
|
|
//
|
|
|
|
class assertion_failed
|
|
|
|
: public std::runtime_error
|
|
|
|
{
|
|
|
|
public:
|
2014-07-22 00:33:13 +00:00
|
|
|
explicit SPROUT_NON_CONSTEXPR assertion_failed(std::string const& msg)
|
2013-09-26 13:43:57 +00:00
|
|
|
: std::runtime_error(msg)
|
|
|
|
{}
|
2014-07-22 00:33:13 +00:00
|
|
|
explicit SPROUT_NON_CONSTEXPR assertion_failed(char const* msg)
|
2013-09-26 13:43:57 +00:00
|
|
|
: std::runtime_error(msg)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
inline SPROUT_CONSTEXPR bool
|
|
|
|
assertion_check(bool cond, std::string const& msg) {
|
|
|
|
return cond ? true
|
|
|
|
: throw testspr::assertion_failed(msg)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
inline SPROUT_CONSTEXPR bool
|
|
|
|
assertion_check(bool cond, char const* msg) {
|
|
|
|
return cond ? true
|
|
|
|
: throw testspr::assertion_failed(msg)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
} // namespace detail
|
|
|
|
} // namespace testspr
|
2013-01-03 08:01:50 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// TESTSPR_STATIC_ASSERT
|
|
|
|
// TESTSPR_ASSERT
|
2013-09-26 13:43:57 +00:00
|
|
|
//
|
|
|
|
#define TESTSPR_STATIC_ASSERT(expr) \
|
|
|
|
static_assert(expr, #expr)
|
|
|
|
#define TESTSPR_ASSERT(expr) \
|
2015-03-22 15:26:20 +00:00
|
|
|
SPROUT_ASSERT(expr)
|
2013-09-26 13:43:57 +00:00
|
|
|
//
|
2013-01-03 08:01:50 +00:00
|
|
|
// TESTSPR_BOTH_ASSERT
|
|
|
|
//
|
|
|
|
#ifndef SPROUT_CONFIG_DISABLE_CONSTEXPR
|
|
|
|
# define TESTSPR_BOTH_ASSERT(expr) TESTSPR_STATIC_ASSERT(expr); TESTSPR_ASSERT(expr)
|
|
|
|
#else // #ifndef SPROUT_CONFIG_DISABLE_CONSTEXPR
|
|
|
|
# define TESTSPR_BOTH_ASSERT(expr) TESTSPR_ASSERT(expr)
|
|
|
|
#endif // #ifndef SPROUT_CONFIG_DISABLE_CONSTEXPR
|
|
|
|
|
|
|
|
//
|
|
|
|
// TESTSPR_STATIC_WARNING
|
|
|
|
//
|
|
|
|
#ifdef TESTSPR_CONFIG_ENABLE_STATIC_WARNING
|
|
|
|
# define TESTSPR_STATIC_WARNING(expr) BOOST_STATIC_WARNING(expr)
|
|
|
|
#else
|
|
|
|
# define TESTSPR_STATIC_WARNING(expr)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//
|
|
|
|
// TESTSPR_STATIC_UNCHECKED
|
|
|
|
// TESTSPR_UNCHECKED
|
|
|
|
// TESTSPR_BOTH_UNCHECKED
|
|
|
|
//
|
|
|
|
#define TESTSPR_STATIC_UNCHECKED(expr) TESTSPR_STATIC_WARNING(expr)
|
|
|
|
#define TESTSPR_UNCHECKED(expr) (expr)
|
|
|
|
#ifndef SPROUT_CONFIG_DISABLE_CONSTEXPR
|
|
|
|
# define TESTSPR_BOTH_UNCHECKED(expr) TESTSPR_STATIC_UNCHECKED(expr); TESTSPR_UNCHECKED(expr)
|
|
|
|
#else // #ifndef SPROUT_CONFIG_DISABLE_CONSTEXPR
|
|
|
|
# define TESTSPR_BOTH_UNCHECKED(expr) TESTSPR_UNCHECKED(expr)
|
|
|
|
#endif // #ifndef SPROUT_CONFIG_DISABLE_CONSTEXPR
|
|
|
|
|
|
|
|
#endif // #ifndef TESTSPR_ASSERT_HPP
|