Add a unit test suite for GDScript

This tests run-time script loading.
This commit is contained in:
Hugo Locurcio 2021-05-12 00:19:59 +02:00
parent 0f334e60f2
commit 6c528e4fae
No known key found for this signature in database
GPG Key ID: 39E8F8BE30B0A49C
1 changed files with 21 additions and 0 deletions

View File

@ -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 } // namespace GDScriptTests
#endif // GDSCRIPT_TEST_RUNNER_SUITE_H #endif // GDSCRIPT_TEST_RUNNER_SUITE_H