diff options
Diffstat (limited to 'tests/test_main.cpp')
-rw-r--r-- | tests/test_main.cpp | 135 |
1 files changed, 68 insertions, 67 deletions
diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 84d2fe1f6c..5d961854cb 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -30,101 +30,102 @@ #include "test_main.h" -#include "core/list.h" - -#ifdef DEBUG_ENABLED +#include "core/templates/list.h" +#include "test_aabb.h" #include "test_astar.h" #include "test_basis.h" #include "test_class_db.h" -#include "test_gdscript.h" +#include "test_color.h" +#include "test_command_queue.h" +#include "test_config_file.h" +#include "test_crypto.h" +#include "test_curve.h" +#include "test_expression.h" +#include "test_file_access.h" +#include "test_gradient.h" #include "test_gui.h" +#include "test_json.h" +#include "test_list.h" +#include "test_lru.h" #include "test_math.h" +#include "test_method_bind.h" +#include "test_node_path.h" #include "test_oa_hash_map.h" +#include "test_object.h" #include "test_ordered_hash_map.h" +#include "test_paged_array.h" +#include "test_pck_packer.h" #include "test_physics_2d.h" #include "test_physics_3d.h" +#include "test_random_number_generator.h" +#include "test_rect2.h" #include "test_render.h" #include "test_shader_lang.h" #include "test_string.h" +#include "test_text_server.h" #include "test_validate_testing.h" #include "test_variant.h" #include "modules/modules_tests.gen.h" -#include "thirdparty/doctest/doctest.h" +#include "tests/test_macros.h" -const char **tests_get_names() { - static const char *test_names[] = { - "*", - "all", - "math", - "basis", - "physics_2d", - "physics_3d", - "render", - "oa_hash_map", - "class_db", - "gui", - "shaderlang", - "gd_tokenizer", - "gd_parser", - "gd_compiler", - "gd_bytecode", - "ordered_hash_map", - "astar", - nullptr - }; +int test_main(int argc, char *argv[]) { + bool run_tests = true; - return test_names; -} + // Convert arguments to Godot's command-line. + List<String> args; -int test_main(int argc, char *argv[]) { - // doctest runner for when legacy unit tests are no found + for (int i = 0; i < argc; i++) { + args.push_back(String::utf8(argv[i])); + } + OS::get_singleton()->set_cmdline("", args); + + // Run custom test tools. + if (test_commands) { + for (Map<String, TestFunc>::Element *E = test_commands->front(); E; E = E->next()) { + if (args.find(E->key())) { + const TestFunc &test_func = E->get(); + test_func(); + run_tests = false; + break; + } + } + if (!run_tests) { + delete test_commands; + return 0; + } + } + // Doctest runner. doctest::Context test_context; - List<String> valid_arguments; + List<String> test_args; - // clean arguments of --test from the args - int argument_count = 0; + // Clean arguments of "--test" from the args. for (int x = 0; x < argc; x++) { - if (strncmp(argv[x], "--test", 6) != 0) { - valid_arguments.push_back(String(argv[x])); - argument_count++; + String arg = String(argv[x]); + if (arg != "--test") { + test_args.push_back(arg); } } - - // convert godot command line arguments back to standard arguments. - char **args = new char *[valid_arguments.size()]; - for (int x = 0; x < valid_arguments.size(); x++) { - // operation to convert godot string to non wchar string - const char *str = valid_arguments[x].utf8().ptr(); - // allocate the string copy - args[x] = new char[strlen(str) + 1]; - // copy this into memory - std::memcpy(args[x], str, strlen(str) + 1); + // Convert Godot command line arguments back to standard arguments. + char **doctest_args = new char *[test_args.size()]; + for (int x = 0; x < test_args.size(); x++) { + // Operation to convert Godot string to non wchar string. + CharString cs = test_args[x].utf8(); + const char *str = cs.get_data(); + // Allocate the string copy. + doctest_args[x] = new char[strlen(str) + 1]; + // Copy this into memory. + memcpy(doctest_args[x], str, strlen(str) + 1); } - test_context.applyCommandLine(valid_arguments.size(), args); + test_context.applyCommandLine(test_args.size(), doctest_args); - test_context.setOption("order-by", "name"); - test_context.setOption("abort-after", 5); - test_context.setOption("no-breaks", true); - delete[] args; - return test_context.run(); -} - -#else - -const char **tests_get_names() { - static const char *test_names[] = { - nullptr - }; - - return test_names; -} + for (int x = 0; x < test_args.size(); x++) { + delete[] doctest_args[x]; + } + delete[] doctest_args; -int test_main(int argc, char *argv[]) { - return 0; + return test_context.run(); } - -#endif |