From e778b6183970ff61f42f5c749774115e43554195 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 15 Aug 2020 14:19:36 +0200 Subject: [PATCH] Don't use stacktrace on Windows. --- CMakeLists.txt | 6 +++++- src/Exception.hpp | 4 +++- tests/ExceptionTests.cpp | 9 +++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c6528a..df31930 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,8 +26,12 @@ if (TESTS) file(GLOB_RECURSE TEST_FILES "tests/*.cpp" "tests/*.hpp") # And create an executable from it. Also include catch.hpp. add_executable(ArbutilsTests ${TEST_FILES} extern/catch.hpp) + set(LINKS Arbutils) + if (NOT WINDOWS) + set(LINKS ${LINKS} -lbfd -ldl) + endif() # And finally link the library to the executable. - target_link_libraries(ArbutilsTests Arbutils -lbfd -ldl) + target_link_libraries(ArbutilsTests ${LINKS}) # Add a compilation definition to the code that we are building a test build. target_compile_definitions(ArbutilsTests PRIVATE TESTS_BUILD) endif () diff --git a/src/Exception.hpp b/src/Exception.hpp index cc9428f..e14a7c2 100644 --- a/src/Exception.hpp +++ b/src/Exception.hpp @@ -1,6 +1,8 @@ #ifndef ARBUTILS_EXCEPTION_HPP #define ARBUTILS_EXCEPTION_HPP +#if !WINDOWS #define BACKWARD_HAS_BFD 1 +#endif #include #include @@ -34,7 +36,7 @@ namespace ArbUt { function += "..."; } ss << objectName; - if (include_addr){ + if (include_addr) { ss << "[" << trace.addr << "]"; } ss << " " << function << std::endl; diff --git a/tests/ExceptionTests.cpp b/tests/ExceptionTests.cpp index b31f6c9..729e93e 100644 --- a/tests/ExceptionTests.cpp +++ b/tests/ExceptionTests.cpp @@ -6,14 +6,11 @@ using namespace ArbUt; TEST_CASE("Throw exception get stack trace") { try { throw ArbUt::Exception("foobar"); - } - catch (const ArbUt::Exception& e) { + } catch (const ArbUt::Exception& e) { #ifndef NDEBUG - REQUIRE(e.GetStacktrace(1) == - "ExceptionTests.cpp[8] ____C_A_T_C_H____T_E_S_T____0()\n"); + REQUIRE(e.GetStacktrace(1) == "ExceptionTests.cpp[8] ____C_A_T_C_H____T_E_S_T____0()\n"); #else - REQUIRE(e.GetStacktrace(1, false) == - "ArbutilsTests Catch::RunContext::runTest(Catch::TestCase const&)\n"); + REQUIRE(e.GetStacktrace(1, false) == "ArbutilsTests Catch::RunContext::runTest(Catch::TestCase const&)\n"); #endif } }