summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgumi <git@gumi.ca>2018-07-25 13:49:42 -0400
committerJesusaves <cpntb1@ymail.com>2025-03-03 18:25:36 -0300
commit661199ce3753917328dcbd0f290e3c011fa67800 (patch)
treef2188c1416b7508528ec0dcdbb1aa1a8a9f900d3
parentdae3bcd398ce02bb6320466f4dfbccfd6b0ad45d (diff)
downloadserverdata-661199ce3753917328dcbd0f290e3c011fa67800.tar.gz
serverdata-661199ce3753917328dcbd0f290e3c011fa67800.tar.bz2
serverdata-661199ce3753917328dcbd0f290e3c011fa67800.tar.xz
serverdata-661199ce3753917328dcbd0f290e3c011fa67800.zip
add more unit tests for local functions
-rw-r--r--npc/dev/test.txt40
1 files changed, 40 insertions, 0 deletions
diff --git a/npc/dev/test.txt b/npc/dev/test.txt
index f98651dfd..268639102 100644
--- a/npc/dev/test.txt
+++ b/npc/dev/test.txt
@@ -116,6 +116,40 @@ function script F_TestVarOfAnotherNPC {
end;
}
+- script export test FAKE_NPC,{
+
+ function OnInit {
+ // functions labels should not be able to be called as events
+ // if a regression occurs, this function could end up being called when
+ // Hercules processes OnInit event calls (issue #2137)
+
+ // NOTE: If script_config.functions_as_events is enabled (defaults: off)
+ // and this this function is marked as public, it will trigger the
+ // warning and fail the unit test regardless.
+
+ $@something_bad_happened[0] = true;
+ end;
+ }
+
+ private function Private {
+ // function explicitly marked as private
+ return;
+ }
+
+ public function Public {
+ // this is for testing public local functions and ownership of the
+ // script
+
+ return getnpcid();
+ }
+
+ public function RefTest {
+ // this is to check if references are passed around properly
+
+ return set(getarg(0), 1337);
+ }
+}
+
function script HerculesSelfTestHelper {
if (.once > 0)
return .errors;
@@ -729,6 +763,12 @@ function script HerculesSelfTestHelper {
callsub(OnCheckStr, "sprintf (positional)", sprintf("'%2$+05d'", 5, 6), "'+0006'");
callsub(OnCheckStr, "sprintf (positional)", sprintf("'%2$s' '%1$c'", "First", "Second"), "'Second' 'F'");
+ "export test"::RefTest(.@refTest = 69);
+ callsub(OnCheck, "function as event (regression)", $@something_bad_happened[0], false);
+ callsub(OnCheck, "public local function ownership", "export test"::Public(), getnpcid());
+ callsub(OnCheck, "public local function var reference test", .@refTest, 1337);
+ callsub(OnCheck, "programatic public local call", callfunctionofnpc("export test", "RefTest", .@refTest = 1), 1337);
+
if (.errors) {
consolemes(CONSOLEMES_DEBUG, "Script engine self-test [ \033[0;31mFAILED\033[0m ]");
consolemes(CONSOLEMES_ERROR, "**** The test was completed with " + .errors + " errors. ****");