|
11 | 11 | #include <cpptrace/from_current.hpp>
|
12 | 12 |
|
13 | 13 | #include "common.hpp"
|
| 14 | +#include "utils/utils.hpp" |
14 | 15 |
|
15 | 16 | using namespace std::literals;
|
16 | 17 |
|
@@ -42,11 +43,16 @@ CPPTRACE_FORCE_NO_INLINE int stacktrace_from_current_1(std::vector<int>& line_nu
|
42 | 43 |
|
43 | 44 | TEST(FromCurrent, Basic) {
|
44 | 45 | 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 | + }); |
45 | 50 | CPPTRACE_TRY {
|
46 | 51 | line_numbers.insert(line_numbers.begin(), __LINE__ + 1);
|
47 | 52 | static volatile int tco_guard = stacktrace_from_current_1(line_numbers);
|
48 | 53 | (void)tco_guard;
|
49 | 54 | } CPPTRACE_CATCH(const std::runtime_error& e) {
|
| 55 | + does_enter_catch = true; |
50 | 56 | EXPECT_FALSE(cpptrace::current_exception_was_rethrown());
|
51 | 57 | EXPECT_EQ(e.what(), "foobar"sv);
|
52 | 58 | const auto& trace = cpptrace::from_current_exception();
|
@@ -149,3 +155,18 @@ TEST(FromCurrent, RawTrace) {
|
149 | 155 | EXPECT_NE(it, trace.frames.end());
|
150 | 156 | }
|
151 | 157 | }
|
| 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