Add runner for GDScript testing

This is meant for testing the GDScript implementation, not for testing
user scripts nor testing the engine using scripts.

Tests consists in a GDScript file and a .out file with the expected
output. The .out file format is: expected status (based on the enum
GDScriptTest::TestStatus) on the first line, followed by either an error
message or the resulting output. Warnings are added after the first
line, before the output (or compiler errors) if the parser pass without
any error.

The test script must have a function called `test()` which takes no
argument. Such function will be called by the test runner. The test
should not have any dependency unless it's part of the test too. Global
classes (using `class_name`) are registered before the runner starts, so
those should work if needed.

Use the command `godot --gdscript-generate-tests
godot-source/modules/gdscript/tests/scripts` to update the .out files
with the current output (make sure the output are the expected values
before committing).

The tests themselves are part of the doctest suite so those can be
executed with `godot --test`.

Co-authored-by: Andrii Doroshenko (Xrayez) <xrayez@gmail.com>
This commit is contained in:
George Marques 2021-04-07 10:12:51 -03:00
parent 47aef8e8dc
commit 5f77f38573
No known key found for this signature in database
GPG key ID: 046BD46A3201E43D
33 changed files with 882 additions and 78 deletions

View file

@ -45,6 +45,10 @@
#include "gdscript_parser.h"
#include "gdscript_warning.h"
#ifdef TESTS_ENABLED
#include "tests/gdscript_test_runner.h"
#endif
///////////////////////////
GDScriptNativeClass::GDScriptNativeClass(const StringName &p_name) {
@ -1766,6 +1770,10 @@ void GDScriptLanguage::init() {
for (List<Engine::Singleton>::Element *E = singletons.front(); E; E = E->next()) {
_add_global(E->get().name, E->get().ptr);
}
#ifdef TESTS_ENABLED
GDScriptTests::GDScriptTestRunner::handle_cmdline();
#endif
}
String GDScriptLanguage::get_type() const {