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