diff options
author | gumi <git@gumi.ca> | 2018-07-25 13:49:42 -0400 |
---|---|---|
committer | gumi <git@gumi.ca> | 2020-05-03 11:54:44 -0400 |
commit | 6aed6b4f7c669c3760c5ebd32b40fbb7da1d5715 (patch) | |
tree | 7a258a2f7999c37336682dc280eb20ae2b834676 /npc | |
parent | 695f17f4940ba1f616376f06833317dfab2c1c63 (diff) | |
download | hercules-6aed6b4f7c669c3760c5ebd32b40fbb7da1d5715.tar.gz hercules-6aed6b4f7c669c3760c5ebd32b40fbb7da1d5715.tar.bz2 hercules-6aed6b4f7c669c3760c5ebd32b40fbb7da1d5715.tar.xz hercules-6aed6b4f7c669c3760c5ebd32b40fbb7da1d5715.zip |
add more unit tests for local functions
Diffstat (limited to 'npc')
-rw-r--r-- | npc/dev/test.txt | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/npc/dev/test.txt b/npc/dev/test.txt index a9e78489a..c8c842055 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; @@ -785,6 +819,12 @@ function script HerculesSelfTestHelper { callsub(OnCheck, "data_to_string (string variable)", data_to_string(.@x$), ".@x$"); callsub(OnCheck, "data_to_string (integer variable)", data_to_string(.@x), ".@x"); + "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_DEBUG, "**** The test was completed with " + .errors + " errors. ****"); |