@@ -19,22 +19,49 @@ using namespace std::literals;
19
19
20
20
namespace {
21
21
template <typename E, typename ... Args>
22
+ CPPTRACE_FORCE_NO_INLINE
22
23
void do_throw (Args&&... args) {
23
24
throw E (std::forward<Args>(args)...);
24
25
}
25
26
26
27
void check_trace (const cpptrace::stacktrace& trace, std::string_view file, int line) {
28
+ #ifndef CPPTRACE_BUILD_NO_SYMBOLS
27
29
for (const auto & frame : trace) {
28
30
if (frame.filename .find (file) != std::string::npos && frame.line == line) {
29
31
SUCCEED ();
30
32
return ;
31
33
}
32
34
}
33
35
FAIL () << " Trace does not contain " <<file<<" :" <<line<<" \n " <<trace.to_string ();
36
+ #endif
37
+ }
38
+
39
+ void check_trace (const cpptrace::stacktrace& trace, std::string_view try_name) {
40
+ EXPECT_NE (
41
+ std::find_if (
42
+ trace.begin (),
43
+ trace.end (),
44
+ [&] (const cpptrace::stacktrace_frame& frame) {
45
+ return frame.symbol .find (try_name) != std::string::npos;
46
+ }
47
+ ),
48
+ trace.end ()
49
+ ) << trace;
50
+ EXPECT_NE (
51
+ std::find_if (
52
+ trace.begin (),
53
+ trace.end (),
54
+ [&] (const cpptrace::stacktrace_frame& frame) {
55
+ return frame.symbol .find (" do_throw" ) != std::string::npos;
56
+ }
57
+ ),
58
+ trace.end ()
59
+ ) << trace;
34
60
}
35
61
}
36
62
37
63
TEST (TryCatch, Basic) {
64
+ constexpr std::string_view test_name = __func__;
38
65
int line = 0 ;
39
66
bool did_catch = false ;
40
67
cpptrace::try_catch (
@@ -46,6 +73,7 @@ TEST(TryCatch, Basic) {
46
73
did_catch = true ;
47
74
EXPECT_EQ (e.what (), " foobar" sv);
48
75
check_trace (cpptrace::from_current_exception (), " try_catch.cpp" , line);
76
+ check_trace (cpptrace::from_current_exception (), test_name);
49
77
}
50
78
);
51
79
EXPECT_TRUE (did_catch);
@@ -65,6 +93,7 @@ TEST(TryCatch, NoException) {
65
93
}
66
94
67
95
TEST (TryCatch, Upcast) {
96
+ constexpr std::string_view test_name = __func__;
68
97
int line = 0 ;
69
98
bool did_catch = false ;
70
99
cpptrace::try_catch (
@@ -76,6 +105,7 @@ TEST(TryCatch, Upcast) {
76
105
did_catch = true ;
77
106
EXPECT_EQ (e.what (), " foobar" sv);
78
107
check_trace (cpptrace::from_current_exception (), " try_catch.cpp" , line);
108
+ check_trace (cpptrace::from_current_exception (), test_name);
79
109
}
80
110
);
81
111
EXPECT_TRUE (did_catch);
@@ -119,6 +149,7 @@ TEST(TryCatch, NoMatchingHandler) {
119
149
}
120
150
121
151
TEST (TryCatch, CorrectHandler) {
152
+ constexpr std::string_view test_name = __func__;
122
153
int line = 0 ;
123
154
bool did_catch = false ;
124
155
cpptrace::try_catch (
@@ -136,6 +167,7 @@ TEST(TryCatch, CorrectHandler) {
136
167
did_catch = true ;
137
168
EXPECT_EQ (e.what (), " foobar" sv);
138
169
check_trace (cpptrace::from_current_exception (), " try_catch.cpp" , line);
170
+ check_trace (cpptrace::from_current_exception (), test_name);
139
171
},
140
172
[&] (const std::exception &) {
141
173
FAIL ();
@@ -145,6 +177,7 @@ TEST(TryCatch, CorrectHandler) {
145
177
}
146
178
147
179
TEST (TryCatch, BlanketHandler) {
180
+ constexpr std::string_view test_name = __func__;
148
181
int line = 0 ;
149
182
bool did_catch = false ;
150
183
cpptrace::try_catch (
@@ -164,12 +197,14 @@ TEST(TryCatch, BlanketHandler) {
164
197
[&] () {
165
198
did_catch = true ;
166
199
check_trace (cpptrace::from_current_exception (), " try_catch.cpp" , line);
200
+ check_trace (cpptrace::from_current_exception (), test_name);
167
201
}
168
202
);
169
203
EXPECT_TRUE (did_catch);
170
204
}
171
205
172
206
TEST (TryCatch, CatchOrdering) {
207
+ constexpr std::string_view test_name = __func__;
173
208
int line = 0 ;
174
209
bool did_catch = false ;
175
210
cpptrace::try_catch (
@@ -186,6 +221,7 @@ TEST(TryCatch, CatchOrdering) {
186
221
[&] () {
187
222
did_catch = true ;
188
223
check_trace (cpptrace::from_current_exception (), " try_catch.cpp" , line);
224
+ check_trace (cpptrace::from_current_exception (), test_name);
189
225
},
190
226
[&] (const std::runtime_error&) {
191
227
FAIL ();
0 commit comments