diff --git a/libraries/AP_Scripting/tests/modules/test/nested.lua b/libraries/AP_Scripting/tests/modules/test/nested.lua new file mode 100644 index 0000000000..350d5e8a40 --- /dev/null +++ b/libraries/AP_Scripting/tests/modules/test/nested.lua @@ -0,0 +1,10 @@ +-- Description: Test require()ing another script +local nested = {} +nested.top = require('test/top') + +-- create some test functions to call +function nested.call_fn() + return "nested" +end + +return nested diff --git a/libraries/AP_Scripting/tests/modules/test/top.lua b/libraries/AP_Scripting/tests/modules/test/top.lua new file mode 100644 index 0000000000..a7e19d6b17 --- /dev/null +++ b/libraries/AP_Scripting/tests/modules/test/top.lua @@ -0,0 +1,9 @@ +-- Description: Test require()ing another script +local top = {} + +-- create some test functions to call +function top.call_fn() + return "top" +end + +return top diff --git a/libraries/AP_Scripting/tests/scripting_test.lua b/libraries/AP_Scripting/tests/scripting_test.lua index 2f8808f2fc..4f794e5493 100644 --- a/libraries/AP_Scripting/tests/scripting_test.lua +++ b/libraries/AP_Scripting/tests/scripting_test.lua @@ -3,6 +3,7 @@ -- heavily commented, and may require quite a bit more RAM to run in local loop_time = 500 -- number of ms between runs +local require_test_global = require('test/nested') function is_equal(v1, v2, tolerance) return math.abs(v1 - v2) < (tolerance or 0.0001) @@ -36,6 +37,20 @@ end function update() local all_tests_passed = true + local require_test_local = require('test/nested') + -- test require()ing a script + if require_test_local.call_fn() ~= 'nested' then + gcs:send_text(0, "Failed to require() the same script multiple times") + all_tests_passed = false + end + if require_test_global.call_fn() ~= 'nested' then + gcs:send_text(0, "Failed to require() the script once") + all_tests_passed = false + end + if require_test_global.top.call_fn() ~= 'top' then + gcs:send_text(0, "Failed to call a function nested in a required script") + all_tests_passed = false + end -- each test should run then and it's result with the previous ones all_tests_passed = test_offset(500, 200) and all_tests_passed