Path: blob/master/modules/gdscript/tests/gdscript_test_runner_suite.h
10278 views
/**************************************************************************/1/* gdscript_test_runner_suite.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "gdscript_test_runner.h"3334#include "tests/test_macros.h"3536namespace GDScriptTests {3738// TODO: Handle some cases failing on release builds. See: https://github.com/godotengine/godot/pull/8845239#ifdef TOOLS_ENABLED40TEST_SUITE("[Modules][GDScript]") {41TEST_CASE("Script compilation and runtime") {42bool print_filenames = OS::get_singleton()->get_cmdline_args().find("--print-filenames") != nullptr;43bool use_binary_tokens = OS::get_singleton()->get_cmdline_args().find("--use-binary-tokens") != nullptr;44GDScriptTestRunner runner("modules/gdscript/tests/scripts", true, print_filenames, use_binary_tokens);45int fail_count = runner.run_tests();46INFO("Make sure `*.out` files have expected results.");47REQUIRE_MESSAGE(fail_count == 0, "All GDScript tests should pass.");48}49}50#endif // TOOLS_ENABLED5152TEST_CASE("[Modules][GDScript] Load source code dynamically and run it") {53GDScriptLanguage::get_singleton()->init();54Ref<GDScript> gdscript = memnew(GDScript);55gdscript->set_source_code(R"(56extends RefCounted5758func _init():59set_meta("result", 42)60)");61// A spurious `Condition "err" is true` message is printed (despite parsing being successful and returning `OK`).62// Silence it.63ERR_PRINT_OFF;64const Error error = gdscript->reload();65ERR_PRINT_ON;66CHECK_MESSAGE(error == OK, "The script should parse successfully.");6768// Run the script by assigning it to a reference-counted object.69Ref<RefCounted> ref_counted = memnew(RefCounted);70ref_counted->set_script(gdscript);71CHECK_MESSAGE(int(ref_counted->get_meta("result")) == 42, "The script should assign object metadata successfully.");72}7374TEST_CASE("[Modules][GDScript] Validate built-in API") {75GDScriptLanguage *lang = GDScriptLanguage::get_singleton();7677// Validate methods.78List<MethodInfo> builtin_methods;79lang->get_public_functions(&builtin_methods);8081SUBCASE("[Modules][GDScript] Validate built-in methods") {82for (const MethodInfo &mi : builtin_methods) {83for (int64_t i = 0; i < mi.arguments.size(); ++i) {84TEST_COND((mi.arguments[i].name.is_empty() || mi.arguments[i].name.begins_with("_unnamed_arg")),85vformat("Unnamed argument in position %d of built-in method '%s'.", i, mi.name));86}87}88}8990// Validate annotations.91List<MethodInfo> builtin_annotations;92lang->get_public_annotations(&builtin_annotations);9394SUBCASE("[Modules][GDScript] Validate built-in annotations") {95for (const MethodInfo &ai : builtin_annotations) {96for (int64_t i = 0; i < ai.arguments.size(); ++i) {97TEST_COND((ai.arguments[i].name.is_empty() || ai.arguments[i].name.begins_with("_unnamed_arg")),98vformat("Unnamed argument in position %d of built-in annotation '%s'.", i, ai.name));99}100}101}102}103104} // namespace GDScriptTests105106107