-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathlest_expect_assert.hpp
110 lines (91 loc) · 2.74 KB
/
lest_expect_assert.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2016 by Martin Moene
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef LEST_LEST_EXPECT_ASSERT_HPP_INCLUDED
#define LEST_LEST_EXPECT_ASSERT_HPP_INCLUDED
#include "lest/lest.hpp"
#include <csetjmp>
#if ! defined( lest_NO_SHORT_MACRO_NAMES )
# define EXPECT_NO_ASSERT lest_EXPECT_NO_ASSERT
# define EXPECT_ASSERTS lest_EXPECT_ASSERTS
#endif
// "include" lest_assert.hpp:
#ifndef LEST_LEST_ASSERT_HPP_INCLUDED
#define LEST_LEST_ASSERT_HPP_INCLUDED
#ifndef lest_FEATURE_ASSERT
# define lest_FEATURE_ASSERT 1
#endif
#if lest_FEATURE_ASSERT
# define assert( expr ) ( !!(expr) ? ((void)0) : ::lest::assertion_failed( #expr, lest___FUNC__, __FILE__, __LINE__) )
#else
# include <cassert>
#endif
#if __cplusplus >= 201103 || _MSC_VER >= 1800
# define lest___FUNC__ __func__
#else
# define lest___FUNC__ "(unknown)"
#endif
#endif // LEST_LEST_ASSERT_HPP_INCLUDED
#define lest_EXPECT_NO_ASSERT( expr ) \
do \
{ \
try \
{ \
try \
{ \
expr; \
} \
catch ( lest::assertion_failed_ const & ) \
{ \
throw lest::asserted{ "failed", lest_LOCATION, #expr }; \
} \
} \
catch (...) \
{ \
lest::inform( lest_LOCATION, #expr ); \
} \
if ( lest_env.pass() ) \
lest::report( lest_env.os, lest::not_asserted{ "passed", lest_LOCATION, #expr }, lest_env.testing ); \
} while ( lest::is_false() )
#define lest_EXPECT_ASSERTS( expr ) \
do \
{ \
try \
{ \
try \
{ \
expr; \
} \
catch ( lest::assertion_failed_ const & ) \
{ \
if ( lest_env.pass() ) \
lest::report( lest_env.os, lest::asserted{ "passed", lest_LOCATION, #expr }, lest_env.testing ); \
break; \
} \
} \
catch (...) \
{ \
lest::inform( lest_LOCATION, #expr ); \
} \
throw lest::not_asserted{ "failed", lest_LOCATION, #expr }; \
} \
while ( lest::is_false() )
namespace lest {
struct asserted : message
{
asserted( text kind, location where, text expr )
: message{ kind + ": asserted", where, expr } {}
};
struct not_asserted : message
{
not_asserted( text kind, location where, text expr )
: message{ kind + ": didn't assert", where, expr } {}
};
struct assertion_failed_{};
void assertion_failed( char const * /*expr*/, char const * /*function*/, char const * /*file*/, long /*line*/ )
{
throw assertion_failed_{};
}
} // namespace lest
#endif // LEST_LEST_EXPECT_ASSERT_HPP_INCLUDED