Improve script exception error message.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-02-16 11:44:50 +01:00
parent 7a452f96a7
commit 5bbb880700
3 changed files with 29 additions and 2 deletions

View File

@@ -56,6 +56,9 @@ void StopBeforeAttack(ExecutingMove@ attack, bool& result) override{
AS_CLASS(OnAfterHitsScript,
"int value = 0; void OnAfterHits(ExecutingMove@ attack, Pokemon@ target) override { value++; } "
"int GetValue() { return value; }"),
AS_CLASS(throwScript,
R"(void PreventAttack(ExecutingMove@ attack, bool& result) override{ throw("test exception"); })"),
};
@@ -271,4 +274,21 @@ TEST_CASE("Invoke OnAfterHits script function") {
delete script;
}
TEST_CASE("Handle script exceptions.") {
auto mainLib = TestLibrary::GetLibrary();
auto script = GetScript(mainLib, "throwScript");
bool b = false;
bool hasThrown = false;
try{
script->PreventAttack(nullptr, &b);
}
catch (const CreatureException& e){
hasThrown = true;
REQUIRE(strcmp("Script exception in script 'throwScript', line 1. Message: 'test exception'.", e.what()) == 0);
}
REQUIRE(hasThrown);
delete script;
}
#endif