CreatureLib/tests/ExceptionTests.cpp

32 lines
915 B
C++
Raw Normal View History

#ifdef TESTS_BUILD
#include <cstring>
#include "../CInterface/Core.hpp"
#include "../extern/doctest.hpp"
TEST_CASE("When throwing exception, what() is readable") {
bool hasCaught = false;
try {
THROW("foobar");
} catch (const ArbUt::Exception& e) {
hasCaught = true;
INFO(e.what());
REQUIRE(std::string(e.what()) == "[ExceptionTests.cpp:9] foobar");
}
REQUIRE(hasCaught);
}
TEST_CASE("C Interface exception") {
ExceptionHandler::SetLastArbUtException("foo", ArbUt::Exception("foobar"), 1);
REQUIRE(std::string(ExceptionHandler::GetLastException()) == "[foo] foobar");
#if !WINDOWS
#ifndef DEBUG
REQUIRE(std::string(ExceptionHandler::GetLastExceptionStacktrace()) != "");
#else
REQUIRE(std::string(ExceptionHandler::GetLastExceptionStacktrace()) ==
"ExceptionTests.cpp[20] ____C_A_T_C_H____T_E_S_T____3()\n");
#endif
#endif
}
#endif