Skip to content

Commit b0d0417

Browse files
committed
Add a test for try/catch behavior
1 parent b882f9a commit b0d0417

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/unit/tracing/from_current.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <cpptrace/from_current.hpp>
1212

1313
#include "common.hpp"
14+
#include "utils/utils.hpp"
1415

1516
using namespace std::literals;
1617

@@ -42,11 +43,16 @@ CPPTRACE_FORCE_NO_INLINE int stacktrace_from_current_1(std::vector<int>& line_nu
4243

4344
TEST(FromCurrent, Basic) {
4445
std::vector<int> line_numbers;
46+
bool does_enter_catch = false;
47+
auto guard = cpptrace::internal::scope_exit([&] {
48+
EXPECT_TRUE(does_enter_catch);
49+
});
4550
CPPTRACE_TRY {
4651
line_numbers.insert(line_numbers.begin(), __LINE__ + 1);
4752
static volatile int tco_guard = stacktrace_from_current_1(line_numbers);
4853
(void)tco_guard;
4954
} CPPTRACE_CATCH(const std::runtime_error& e) {
55+
does_enter_catch = true;
5056
EXPECT_FALSE(cpptrace::current_exception_was_rethrown());
5157
EXPECT_EQ(e.what(), "foobar"sv);
5258
const auto& trace = cpptrace::from_current_exception();
@@ -149,3 +155,18 @@ TEST(FromCurrent, RawTrace) {
149155
EXPECT_NE(it, trace.frames.end());
150156
}
151157
}
158+
159+
TEST(FromCurrent, NonThrowingPath) {
160+
bool does_enter_catch = false;
161+
bool does_reach_end = false;
162+
auto guard = cpptrace::internal::scope_exit([&] {
163+
EXPECT_FALSE(does_enter_catch);
164+
EXPECT_TRUE(does_reach_end);
165+
});
166+
CPPTRACE_TRY {
167+
// pass
168+
} CPPTRACE_CATCH(const std::runtime_error& e) {
169+
does_enter_catch = true;
170+
}
171+
does_reach_end = true;
172+
}

0 commit comments

Comments
 (0)