#ifdef TESTS_BUILD #include #include "../src/Exception.hpp" using namespace ArbUt; static void Thrower() { throw ArbUt::Exception("foobar"); } static void ThrowerWithMacro() { THROW("foobar"); } static void ThrowerWithMacroAndParameters([[maybe_unused]] int i) { THROW("foobar", ' ', i); } TEST_CASE("Throw exception get stack trace") { try { Thrower(); } catch (const ArbUt::Exception& e) { REQUIRE(e.GetStacktrace(1) == "Stacktrace with depth 1: \n" "ExceptionTests.cpp[6] static void Thrower() { throw ArbUt::Exception(\"foobar\"); }\n" "--- End of Stack ---"); } } TEST_CASE("Throw exception with macro, check message") { try { ThrowerWithMacro(); } catch (const ArbUt::Exception& e) { REQUIRE_EQ(std::string(e.what()), "[ExceptionTests.cpp:7] \"foobar\""); } } TEST_CASE("Throw exception with macro and parameters, check message") { try { ThrowerWithMacroAndParameters(684); } catch (const ArbUt::Exception& e) { REQUIRE_EQ(std::string(e.what()), "[ExceptionTests.cpp:8] \"foobar 684\""); } } #endif