diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-05-19 20:49:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-19 20:49:03 +0200 |
commit | 169268ae20298a312dbb5038d7c70e80ed025391 (patch) | |
tree | b617ef78d92ea16b4db2d7b4cadc876d4e61a7a3 /modules/gdscript | |
parent | 896d84bd156ddc83bb4fd0fcac126662f3964f2b (diff) | |
parent | 6c528e4faef59c6188da9f1032447ea1304596cd (diff) |
Merge pull request #48657 from Calinou/test-add-gdscript
Add a unit test suite for GDScript
Diffstat (limited to 'modules/gdscript')
-rw-r--r-- | modules/gdscript/tests/gdscript_test_runner_suite.h | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/modules/gdscript/tests/gdscript_test_runner_suite.h b/modules/gdscript/tests/gdscript_test_runner_suite.h index 136907b316..8fd77239cd 100644 --- a/modules/gdscript/tests/gdscript_test_runner_suite.h +++ b/modules/gdscript/tests/gdscript_test_runner_suite.h @@ -48,6 +48,27 @@ TEST_SUITE("[Modules][GDScript]") { } } +TEST_CASE("[Modules][GDScript] Load source code dynamically and run it") { + Ref<GDScript> gdscript = memnew(GDScript); + gdscript->set_source_code(R"( +extends Reference + +func _init(): + set_meta("result", 42) +)"); + // A spurious `Condition "err" is true` message is printed (despite parsing being successful and returning `OK`). + // Silence it. + ERR_PRINT_OFF; + const Error error = gdscript->reload(); + ERR_PRINT_ON; + CHECK_MESSAGE(error == OK, "The script should parse successfully."); + + // Run the script by assigning it to a reference-counted object. + Ref<Reference> reference = memnew(Reference); + reference->set_script(gdscript); + CHECK_MESSAGE(int(reference->get_meta("result")) == 42, "The script should assign object metadata successfully."); +} + } // namespace GDScriptTests #endif // GDSCRIPT_TEST_RUNNER_SUITE_H |