2020-08-15 11:31:16 +00:00
|
|
|
#ifdef TESTS_BUILD
|
2022-02-05 12:37:47 +00:00
|
|
|
#include <doctest.h>
|
2020-08-15 11:31:16 +00:00
|
|
|
#include "../src/Exception.hpp"
|
|
|
|
using namespace ArbUt;
|
|
|
|
|
2020-08-16 17:15:45 +00:00
|
|
|
static void Thrower() { throw ArbUt::Exception("foobar"); }
|
2021-11-21 11:27:46 +00:00
|
|
|
static void ThrowerWithMacro() { THROW("foobar"); }
|
|
|
|
static void ThrowerWithMacroAndParameters([[maybe_unused]] int i) { THROW("foobar", ' ', i); }
|
2020-08-16 14:59:13 +00:00
|
|
|
|
2020-08-15 12:05:22 +00:00
|
|
|
TEST_CASE("Throw exception get stack trace") {
|
2020-08-15 11:31:16 +00:00
|
|
|
try {
|
2020-08-16 14:59:13 +00:00
|
|
|
Thrower();
|
2020-08-15 12:19:36 +00:00
|
|
|
} catch (const ArbUt::Exception& e) {
|
2020-08-17 10:05:15 +00:00
|
|
|
REQUIRE(e.GetStacktrace(1) ==
|
|
|
|
"Stacktrace with depth 1: \n"
|
2020-12-23 11:04:20 +00:00
|
|
|
"ExceptionTests.cpp[6] static void Thrower() { throw ArbUt::Exception(\"foobar\"); }\n"
|
|
|
|
"--- End of Stack ---");
|
2020-08-15 11:31:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-21 11:27:46 +00:00
|
|
|
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\"");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-15 11:31:16 +00:00
|
|
|
#endif
|