mirror of
https://github.com/boostorg/stacktrace.git
synced 2026-01-24 18:32:22 +00:00
Added noop backend. Do not skip frames in backends anymore, because it is impossible to guess the inlining heuristics on different compilers. Fixed tests, added more tests, simplified code, improved docs
This commit is contained in:
@@ -9,13 +9,23 @@
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
|
||||
using boost::stacktrace::stacktrace;
|
||||
BOOST_SYMBOL_IMPORT std::pair<stacktrace, stacktrace> foo2(int i);
|
||||
BOOST_SYMBOL_IMPORT std::pair<stacktrace, stacktrace> foo1(int i);
|
||||
BOOST_SYMBOL_IMPORT stacktrace return_from_nested_namespaces();
|
||||
|
||||
void test_deeply_nested_namespaces() {
|
||||
std::stringstream ss;
|
||||
ss << return_from_nested_namespaces();
|
||||
std::cout << ss.str() << '\n';
|
||||
BOOST_TEST(ss.str().find("main") != std::string::npos);
|
||||
|
||||
#if !defined(BOOST_STACKTRACE_HEADER_ONLY) || !defined(BOOST_STACKTRACE_USE_BACKTRACE)
|
||||
BOOST_TEST(ss.str().find("get_backtrace_from_nested_namespaces") != std::string::npos);
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_nested() {
|
||||
std::pair<stacktrace, stacktrace> res = foo2(15);
|
||||
@@ -24,43 +34,30 @@ void test_nested() {
|
||||
ss1 << res.first;
|
||||
ss2 << res.second;
|
||||
std::cout << "'" << ss1.str() << "'\n\n" << ss2.str() << std::endl;
|
||||
assert(!ss1.str().empty());
|
||||
assert(!ss2.str().empty());
|
||||
BOOST_TEST(!ss1.str().empty());
|
||||
BOOST_TEST(!ss2.str().empty());
|
||||
|
||||
assert(ss1.str().find(" 0# ") != std::string::npos);
|
||||
assert(ss2.str().find(" 0# ") != std::string::npos);
|
||||
BOOST_TEST(ss1.str().find(" 0# ") != std::string::npos);
|
||||
BOOST_TEST(ss2.str().find(" 0# ") != std::string::npos);
|
||||
|
||||
assert(ss1.str().find(" 1# ") != std::string::npos);
|
||||
assert(ss2.str().find(" 1# ") != std::string::npos);
|
||||
BOOST_TEST(ss1.str().find(" 1# ") != std::string::npos);
|
||||
BOOST_TEST(ss2.str().find(" 1# ") != std::string::npos);
|
||||
|
||||
assert(ss1.str().find("main") != std::string::npos);
|
||||
assert(ss2.str().find("main") != std::string::npos);
|
||||
|
||||
|
||||
assert(ss2.str().find("stacktrace") == std::string::npos);
|
||||
BOOST_TEST(ss1.str().find("main") != std::string::npos);
|
||||
BOOST_TEST(ss2.str().find("main") != std::string::npos);
|
||||
|
||||
#if !defined(BOOST_STACKTRACE_HEADER_ONLY) || !defined(BOOST_STACKTRACE_USE_BACKTRACE)
|
||||
assert(ss1.str().find("stacktrace") != std::string::npos);
|
||||
assert(ss1.str().find("pair") != std::string::npos);
|
||||
|
||||
assert(ss1.str().find("foo1") != std::string::npos);
|
||||
assert(ss1.str().find("foo2") != std::string::npos);
|
||||
assert(ss2.str().find("foo1") != std::string::npos);
|
||||
assert(ss2.str().find("foo2") != std::string::npos);
|
||||
BOOST_TEST(ss1.str().find("foo1") != std::string::npos);
|
||||
BOOST_TEST(ss1.str().find("foo2") != std::string::npos);
|
||||
BOOST_TEST(ss2.str().find("foo1") != std::string::npos);
|
||||
BOOST_TEST(ss2.str().find("foo2") != std::string::npos);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
std::stringstream ss;
|
||||
ss << return_from_nested_namespaces();
|
||||
std::cout << ss.str() << '\n';
|
||||
assert(ss.str().find("main") != std::string::npos);
|
||||
assert(ss.str().find("stacktrace") == std::string::npos);
|
||||
|
||||
#if !defined(BOOST_STACKTRACE_HEADER_ONLY) || !defined(BOOST_STACKTRACE_USE_BACKTRACE)
|
||||
assert(ss.str().find("get_backtrace_from_nested_namespaces") != std::string::npos);
|
||||
#endif
|
||||
|
||||
test_deeply_nested_namespaces();
|
||||
test_nested();
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user