test_backtrace.cpp
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
#include "crucible/testing.hpp" #include "crucible/unix.hpp" #include <algorithm> namespace crucible::unix::test_backtrace { auto inner_function() -> void { auto const backtrace { backtrace::snapshot() }; EXPECT(!backtrace.empty()); { auto const predicate { [](backtrace::Frame const &frame) -> bool { return frame.get_function() == "crucible::unix::backtrace::snapshot()"; } }; auto const iterator { std::find_if(backtrace.begin(), backtrace.end(), predicate) }; EXPECT_NE(iterator, backtrace.end()); } { auto const predicate { [](backtrace::Frame const &frame) -> bool { return frame.get_function() == "crucible::unix::test_backtrace::inner_function()"; } }; auto const iterator { std::find_if(backtrace.begin(), backtrace.end(), predicate) }; EXPECT_NE(iterator, backtrace.end()); auto const &frame { *iterator }; std::string const expected_format { "crucible::unix::backtrace::Frame { my_function: std::string { \"crucible::unix::test_backtrace::inner_function()\" }, my_details: std::string { \"C++ symbol\" } }" }; EXPECT_EQ(frame.format(), expected_format); } } SCENARIO(backtrace, snapshot) { inner_function(); } }