diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp index 4fa88bb580ae..8e146d2927c0 100644 --- a/modules/gdscript/gdscript.cpp +++ b/modules/gdscript/gdscript.cpp @@ -46,7 +46,10 @@ #endif #ifdef TESTS_ENABLED -#include "tests/gdscript_test_runner.h" +#ifndef DISABLE_DEPRECATED +#include "core/error/error_macros.h" +#include "core/os/os.h" +#endif #endif #include "core/config/engine.h" @@ -2151,7 +2154,12 @@ void GDScriptLanguage::init() { #endif // DEBUG_ENABLED #ifdef TESTS_ENABLED - GDScriptTests::GDScriptTestRunner::handle_cmdline(); +#ifndef DISABLE_DEPRECATED + if (OS::get_singleton()->get_cmdline_args().find("--gdscript-generate-tests")) { + ERR_PRINT(R"(The command for generating GDScript test output has changed to "--test gdscript-generate-tests")"); + exit(-1); + } +#endif // !DISABLE_DEPRECATED #endif // TESTS_ENABLED } diff --git a/modules/gdscript/register_types.cpp b/modules/gdscript/register_types.cpp index 52f7397abeb6..bed4146a8bd8 100644 --- a/modules/gdscript/register_types.cpp +++ b/modules/gdscript/register_types.cpp @@ -230,4 +230,5 @@ REGISTER_TEST_COMMAND("gdscript-tokenizer-buffer", &test_tokenizer_buffer); REGISTER_TEST_COMMAND("gdscript-parser", &test_parser); REGISTER_TEST_COMMAND("gdscript-compiler", &test_compiler); REGISTER_TEST_COMMAND("gdscript-bytecode", &test_bytecode); +REGISTER_TEST_COMMAND("gdscript-generate-tests", &GDScriptTests::generate_tests); #endif diff --git a/modules/gdscript/tests/gdscript_test_runner.cpp b/modules/gdscript/tests/gdscript_test_runner.cpp index 27bea5db34bc..845566b10a70 100644 --- a/modules/gdscript/tests/gdscript_test_runner.cpp +++ b/modules/gdscript/tests/gdscript_test_runner.cpp @@ -131,9 +131,8 @@ void finish_language() { StringName GDScriptTestRunner::test_function_name; -GDScriptTestRunner::GDScriptTestRunner(const String &p_source_dir, bool p_init_language, bool p_print_filenames, bool p_use_binary_tokens) { +GDScriptTestRunner::GDScriptTestRunner(const String &p_source_dir, bool p_print_filenames, bool p_use_binary_tokens) { test_function_name = StringName("test"); - do_init_languages = p_init_language; print_filenames = p_print_filenames; binary_tokens = p_use_binary_tokens; @@ -142,9 +141,7 @@ GDScriptTestRunner::GDScriptTestRunner(const String &p_source_dir, bool p_init_l source_dir += "/"; } - if (do_init_languages) { - init_language(p_source_dir); - } + init_language(p_source_dir); #ifdef DEBUG_ENABLED // Set all warning levels to "Warn" in order to test them properly, even the ones that default to error. @@ -170,9 +167,7 @@ GDScriptTestRunner::GDScriptTestRunner(const String &p_source_dir, bool p_init_l GDScriptTestRunner::~GDScriptTestRunner() { test_function_name = StringName(); - if (do_init_languages) { - finish_language(); - } + finish_language(); } #ifndef DEBUG_ENABLED @@ -412,28 +407,6 @@ GDScriptTest::GDScriptTest(const String &p_source_path, const String &p_output_p _error_handler.errfunc = error_handler; } -void GDScriptTestRunner::handle_cmdline() { - List cmdline_args = OS::get_singleton()->get_cmdline_args(); - - for (List::Element *E = cmdline_args.front(); E; E = E->next()) { - String &cmd = E->get(); - if (cmd == "--gdscript-generate-tests") { - String path; - if (E->next()) { - path = E->next()->get(); - } else { - path = "modules/gdscript/tests/scripts"; - } - - GDScriptTestRunner runner(path, false, cmdline_args.find("--print-filenames") != nullptr); - - bool completed = runner.generate_outputs(); - int failed = completed ? 0 : -1; - exit(failed); - } - } -} - void GDScriptTest::enable_stdout() { // TODO: this could likely be handled by doctest or `tests/test_macros.h`. OS::get_singleton()->set_stdout_enabled(true); diff --git a/modules/gdscript/tests/gdscript_test_runner.h b/modules/gdscript/tests/gdscript_test_runner.h index 9d8475e72365..b3cbdab6b516 100644 --- a/modules/gdscript/tests/gdscript_test_runner.h +++ b/modules/gdscript/tests/gdscript_test_runner.h @@ -114,7 +114,6 @@ class GDScriptTestRunner { Vector tests; bool is_generating = false; - bool do_init_languages = false; bool print_filenames; // Whether filenames should be printed when generated/running tests bool binary_tokens; // Test with buffer tokenizer. @@ -125,11 +124,10 @@ class GDScriptTestRunner { public: static StringName test_function_name; - static void handle_cmdline(); int run_tests(); bool generate_outputs(); - GDScriptTestRunner(const String &p_source_dir, bool p_init_language, bool p_print_filenames = false, bool p_use_binary_tokens = false); + GDScriptTestRunner(const String &p_source_dir, bool p_print_filenames = false, bool p_use_binary_tokens = false); ~GDScriptTestRunner(); }; diff --git a/modules/gdscript/tests/gdscript_test_runner_suite.h b/modules/gdscript/tests/gdscript_test_runner_suite.h index df3f0d84cfc6..ae839f1103d8 100644 --- a/modules/gdscript/tests/gdscript_test_runner_suite.h +++ b/modules/gdscript/tests/gdscript_test_runner_suite.h @@ -60,7 +60,7 @@ TEST_SUITE("[Modules][GDScript]") { TEST_CASE("Script compilation and runtime") { bool print_filenames = OS::get_singleton()->get_cmdline_args().find("--print-filenames") != nullptr; bool use_binary_tokens = OS::get_singleton()->get_cmdline_args().find("--use-binary-tokens") != nullptr; - GDScriptTestRunner runner("modules/gdscript/tests/scripts", true, print_filenames, use_binary_tokens); + GDScriptTestRunner runner("modules/gdscript/tests/scripts", print_filenames, use_binary_tokens); int fail_count = runner.run_tests(); INFO("Make sure `*.out` files have expected results."); REQUIRE_MESSAGE(fail_count == 0, "All GDScript tests should pass."); diff --git a/modules/gdscript/tests/test_gdscript.cpp b/modules/gdscript/tests/test_gdscript.cpp index ea2c66588bf5..67ff21d47ac9 100644 --- a/modules/gdscript/tests/test_gdscript.cpp +++ b/modules/gdscript/tests/test_gdscript.cpp @@ -364,4 +364,24 @@ void test(TestType p_type) { finish_language(); } + +void generate_tests() { + List cmdline_args = OS::get_singleton()->get_cmdline_args(); + + const bool print_filenames = cmdline_args.erase("--print-filenames"); + + String path; + if (cmdline_args.size() == 4) { // "", "--test", "gdscript-generate-tests", "" + path = cmdline_args.back()->get(); + } else { + path = "modules/gdscript/tests/scripts"; + } + + GDScriptTestRunner runner(path, print_filenames); + + bool completed = runner.generate_outputs(); + int failed = completed ? 0 : -1; + exit(failed); +} + } // namespace GDScriptTests diff --git a/modules/gdscript/tests/test_gdscript.h b/modules/gdscript/tests/test_gdscript.h index 7d26abee7bdb..cd2beb3aac18 100644 --- a/modules/gdscript/tests/test_gdscript.h +++ b/modules/gdscript/tests/test_gdscript.h @@ -41,5 +41,6 @@ enum TestType { }; void test(TestType p_type); +void generate_tests(); } // namespace GDScriptTests