Echo Writes Code

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
#include "crucible/testing.hpp"
#include "crucible/unix.hpp"

#include <algorithm>

namespace crucible::unix::test_backtrace {
  auto inner_function() -> void {
    auto const backtrace { backtrace::snapshot() };
    CRUCIBLE_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) };
      CRUCIBLE_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) };
      CRUCIBLE_EXPECT_NE(iterator, backtrace.end());
    }
  }

  CRUCIBLE_SCENARIO(backtrace, snapshot) {
    inner_function();
  }
}