diff options
author | Andrii Doroshenko (Xrayez) <xrayez@gmail.com> | 2020-08-18 17:24:45 +0300 |
---|---|---|
committer | Andrii Doroshenko (Xrayez) <xrayez@gmail.com> | 2020-09-02 01:43:26 +0300 |
commit | 0cc05c5a31b6c6d3db76b5982f3f36919e137500 (patch) | |
tree | 7fa6a781b2ecd61ae3bc4372d7c12129ba13eba5 /modules | |
parent | 6b7e50ab3410542d341bd1dd1ec70123fc218ecc (diff) |
Register GDScript test tools as test commands to run via command-line
Diffstat (limited to 'modules')
-rw-r--r-- | modules/gdscript/SCsub | 4 | ||||
-rw-r--r-- | modules/gdscript/register_types.cpp | 28 | ||||
-rw-r--r-- | modules/gdscript/tests/test_gdscript.cpp | 27 | ||||
-rw-r--r-- | modules/gdscript/tests/test_gdscript.h | 5 |
4 files changed, 38 insertions, 26 deletions
diff --git a/modules/gdscript/SCsub b/modules/gdscript/SCsub index e58a1d8edc..5c8cbdf869 100644 --- a/modules/gdscript/SCsub +++ b/modules/gdscript/SCsub @@ -17,3 +17,7 @@ if env["tools"]: # Using a define in the disabled case, to avoid having an extra define # in regular builds where all modules are enabled. env_gdscript.Append(CPPDEFINES=["GDSCRIPT_NO_LSP"]) + +if env["tests"]: + env_gdscript.Append(CPPDEFINES=["TESTS_ENABLED"]) + env_gdscript.add_source_files(env.modules_sources, "./tests/*.cpp") diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp index c554cbac05..7dad878eb1 100644 --- a/modules/gdscript/register_types.cpp +++ b/modules/gdscript/register_types.cpp @@ -39,6 +39,11 @@ #include "gdscript_cache.h" #include "gdscript_tokenizer.h" +#ifdef TESTS_ENABLED +#include "tests/test_gdscript.h" +#include "tests/test_macros.h" +#endif + GDScriptLanguage *script_language_gd = nullptr; Ref<ResourceFormatLoaderGDScript> resource_loader_gd; Ref<ResourceFormatSaverGDScript> resource_saver_gd; @@ -153,3 +158,26 @@ void unregister_gdscript_types() { GDScriptParser::cleanup(); GDScriptAnalyzer::cleanup(); } + +#ifdef TESTS_ENABLED +void test_tokenizer() { + TestGDScript::test(TestGDScript::TestType::TEST_TOKENIZER); +} + +void test_parser() { + TestGDScript::test(TestGDScript::TestType::TEST_PARSER); +} + +void test_compiler() { + TestGDScript::test(TestGDScript::TestType::TEST_COMPILER); +} + +void test_bytecode() { + TestGDScript::test(TestGDScript::TestType::TEST_BYTECODE); +} + +REGISTER_TEST_COMMAND("gdscript-tokenizer", &test_tokenizer); +REGISTER_TEST_COMMAND("gdscript-parser", &test_parser); +REGISTER_TEST_COMMAND("gdscript-compiler", &test_compiler); +REGISTER_TEST_COMMAND("gdscript-bytecode", &test_bytecode); +#endif diff --git a/modules/gdscript/tests/test_gdscript.cpp b/modules/gdscript/tests/test_gdscript.cpp index a909f216ee..68d9984b43 100644 --- a/modules/gdscript/tests/test_gdscript.cpp +++ b/modules/gdscript/tests/test_gdscript.cpp @@ -35,10 +35,6 @@ #include "core/os/os.h" #include "core/string_builder.h" -#include "modules/modules_enabled.gen.h" - -#ifdef MODULE_GDSCRIPT_ENABLED - #include "modules/gdscript/gdscript_analyzer.h" #include "modules/gdscript/gdscript_compiler.h" #include "modules/gdscript/gdscript_parser.h" @@ -183,21 +179,21 @@ static void test_compiler(const String &p_code, const String &p_script_path, con } } -MainLoop *test(TestType p_type) { +void test(TestType p_type) { List<String> cmdlargs = OS::get_singleton()->get_cmdline_args(); if (cmdlargs.empty()) { - return nullptr; + return; } String test = cmdlargs.back()->get(); if (!test.ends_with(".gd")) { print_line("This test expects a path to a GDScript file as its last parameter. Got: " + test); - return nullptr; + return; } FileAccessRef fa = FileAccess::open(test, FileAccess::READ); - ERR_FAIL_COND_V_MSG(!fa, nullptr, "Could not open file: " + test); + ERR_FAIL_COND_MSG(!fa, "Could not open file: " + test); Vector<uint8_t> buf; int flen = fa->get_len(); @@ -230,21 +226,6 @@ MainLoop *test(TestType p_type) { case TEST_BYTECODE: print_line("Not implemented."); } - - return nullptr; -} - -} // namespace TestGDScript - -#else - -namespace TestGDScript { - -MainLoop *test(TestType p_type) { - ERR_PRINT("The GDScript module is disabled, therefore GDScript tests cannot be used."); - return nullptr; } } // namespace TestGDScript - -#endif diff --git a/modules/gdscript/tests/test_gdscript.h b/modules/gdscript/tests/test_gdscript.h index 6595da1430..5aa962dcf8 100644 --- a/modules/gdscript/tests/test_gdscript.h +++ b/modules/gdscript/tests/test_gdscript.h @@ -31,8 +31,6 @@ #ifndef TEST_GDSCRIPT_H #define TEST_GDSCRIPT_H -#include "core/os/main_loop.h" - namespace TestGDScript { enum TestType { @@ -42,7 +40,8 @@ enum TestType { TEST_BYTECODE, }; -MainLoop *test(TestType p_type); +void test(TestType p_type); + } // namespace TestGDScript #endif // TEST_GDSCRIPT_H |