Skip to content

Commit a0376f7

Browse files
authored
update gdunit to 4.2 (#157)
1 parent d758bae commit a0376f7

File tree

110 files changed

+2152
-1420
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+2152
-1420
lines changed

addons/gdUnit4/bin/GdUnitCmdTool.gd

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ class CLIRunner extends Node:
2323
var _state = READY
2424
var _test_suites_to_process :Array
2525
var _executor
26+
var _cs_executor
2627
var _report :GdUnitHtmlReport
2728
var _report_dir: String
2829
var _report_max: int = DEFAULT_REPORT_COUNT
2930
var _runner_config := GdUnitRunnerConfig.new()
3031
var _console := CmdConsole.new()
31-
var _cs_executor
3232
var _cmd_options: = CmdOptions.new([
3333
CmdOption.new("-a, --add", "-a <directory|path of testsuite>", "Adds the given test suite or directory to the execution pipeline.", TYPE_STRING),
3434
CmdOption.new("-i, --ignore", "-i <testsuite_name|testsuite_name:test-name>", "Adds the given test suite or test case to the ignore list.", TYPE_STRING),
@@ -50,19 +50,18 @@ class CLIRunner extends Node:
5050
func _ready():
5151
_state = INIT
5252
_report_dir = GdUnitTools.current_dir() + "reports"
53-
_executor = load("res://addons/gdUnit4/src/core/GdUnitExecutor.gd").new()
53+
_executor = load("res://addons/gdUnit4/src/core/execution/GdUnitTestSuiteExecutor.gd").new()
5454
# stop checked first test failure to fail fast
5555
_executor.fail_fast(true)
5656

57-
if GdUnitTools.is_mono_supported():
58-
_cs_executor = GdUnit3MonoAPI.create_executor(self)
59-
57+
if GdUnit4MonoApiLoader.is_mono_supported():
58+
prints("GdUnit4Mono Version %s loaded." % GdUnit4MonoApiLoader.version())
59+
_cs_executor = GdUnit4MonoApiLoader.create_executor(self)
6060
var err = GdUnitSignals.instance().gdunit_event.connect(Callable(self, "_on_gdunit_event"))
6161
if err != OK:
6262
prints("gdUnitSignals failed")
6363
push_error("Error checked startup, can't connect executor for 'send_event'")
6464
quit(RETURN_ERROR)
65-
add_child(_executor)
6665

6766

6867
func _process(_delta):
@@ -78,10 +77,11 @@ class CLIRunner extends Node:
7877
set_process(false)
7978
# process next test suite
8079
var test_suite := _test_suites_to_process.pop_front() as Node
81-
add_child(test_suite)
82-
var executor = _cs_executor if GdObjects.is_cs_test_suite(test_suite) else _executor
83-
executor.Execute(test_suite)
84-
await executor.ExecutionCompleted
80+
if _cs_executor != null and _cs_executor.IsExecutable(test_suite):
81+
_cs_executor.Execute(test_suite)
82+
await _cs_executor.ExecutionCompleted
83+
else:
84+
await _executor.execute(test_suite)
8585
set_process(true)
8686
STOP:
8787
_state = EXIT
@@ -90,9 +90,8 @@ class CLIRunner extends Node:
9090

9191

9292
func quit(code :int) -> void:
93-
if is_instance_valid(_executor):
94-
_executor.free()
9593
GdUnitTools.dispose_all()
94+
await GdUnitMemoryObserver.gc_on_guarded_instances()
9695
await get_tree().physics_frame
9796
get_tree().quit(code)
9897

@@ -290,8 +289,8 @@ class CLIRunner extends Node:
290289
return total
291290

292291

293-
func PublishEvent(data) -> void:
294-
_on_gdunit_event(GdUnitEvent.new().deserialize(data.AsDictionary()))
292+
func PublishEvent(data :Dictionary) -> void:
293+
_on_gdunit_event(GdUnitEvent.new().deserialize(data))
295294

296295

297296
func _on_gdunit_event(event :GdUnitEvent):
@@ -399,9 +398,6 @@ func _initialize():
399398

400399
func _finalize():
401400
prints("Finallize ..")
402-
_cli_runner.free()
403401
prints("-Orphan nodes report-----------------------")
404402
Window.print_orphan_nodes()
405-
prints("-SceneTree report-----------------------")
406-
root.print_tree_pretty()
407403
prints("Finallize .. done")

addons/gdUnit4/bin/GdUnitCopyLog.gd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@ func _patch_report(report_path :String, godot_log :String) -> void:
9191
index_file.seek(0)
9292
index_file.store_string(content)
9393

94-
func _copy_and_pach(from_file: String, to_dir: String) -> Result:
94+
func _copy_and_pach(from_file: String, to_dir: String) -> GdUnitResult:
9595
var result := GdUnitTools.copy_file(from_file, to_dir)
9696
if result.is_error():
9797
return result
9898
var file := FileAccess.open(from_file, FileAccess.READ)
9999
if file == null:
100-
return Result.error("Can't find file '%s'. Error: %s" % [from_file, GdUnitTools.error_as_string(FileAccess.get_open_error())])
100+
return GdUnitResult.error("Can't find file '%s'. Error: %s" % [from_file, GdUnitTools.error_as_string(FileAccess.get_open_error())])
101101
var content := file.get_as_text()
102102
# patch out console format codes
103103
for color_index in range(0, 256):
@@ -110,9 +110,9 @@ func _copy_and_pach(from_file: String, to_dir: String) -> Result:
110110
var to_file := to_dir + "/" + from_file.get_file()
111111
file = FileAccess.open(to_file, FileAccess.WRITE)
112112
if file == null:
113-
return Result.error("Can't open to write '%s'. Error: %s" % [to_file, GdUnitTools.error_as_string(FileAccess.get_open_error())])
113+
return GdUnitResult.error("Can't open to write '%s'. Error: %s" % [to_file, GdUnitTools.error_as_string(FileAccess.get_open_error())])
114114
file.store_string(content)
115-
return Result.empty()
115+
return GdUnitResult.empty()
116116

117117
func reports_available() -> bool:
118118
return DirAccess.dir_exists_absolute(_report_root_path)

addons/gdUnit4/bin/ProjectScanner.gd

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,28 @@ extends SceneTree
44

55
const CmdConsole = preload("res://addons/gdUnit4/src/cmd/CmdConsole.gd")
66

7-
var scanner := ProjectScanner.new()
7+
var scanner := SourceScanner.new()
88

99
func _initialize():
10+
set_auto_accept_quit(false)
1011
root.add_child(scanner)
1112

1213

1314
func _finalize():
14-
if Engine.get_version_info().hex < 0x40100 or Engine.get_version_info().hex > 0x40101:
15-
print("Finalize scanner ..")
16-
scanner.free()
17-
if Engine.get_version_info().hex < 0x40100 or Engine.get_version_info().hex > 0x40101:
18-
prints("done")
15+
prints("__finalize")
1916

2017

21-
class ProjectScanner extends Node:
18+
19+
class SourceScanner extends Node:
2220

2321
enum {
2422
INIT,
2523
SCAN,
26-
QUIT
24+
QUIT,
25+
DONE
2726
}
2827

28+
2929
var _counter = 0
3030
var WAIT_TIME_IN_MS = 5.000
3131
var _state = INIT
@@ -46,7 +46,9 @@ class ProjectScanner extends Node:
4646
_console.prints_color("Running project scan:", Color.CORNFLOWER_BLUE)
4747
await scan_project()
4848
set_process(true)
49+
_state = QUIT
4950
if _state == QUIT or _counter >= WAIT_TIME_IN_MS:
51+
_state = DONE
5052
_console.prints_color("Scan project done.", Color.CORNFLOWER_BLUE)
5153
_console.prints_color("======================================", Color.CORNFLOWER_BLUE)
5254
_console.new_line()
@@ -58,24 +60,31 @@ class ProjectScanner extends Node:
5860
var plugin := EditorPlugin.new()
5961
var fs := plugin.get_editor_interface().get_resource_filesystem()
6062

61-
_console.prints_color("Scan :", Color.SANDY_BROWN)
62-
_console.progressBar(0)
63-
fs.scan()
64-
await get_tree().process_frame
65-
while fs.is_scanning():
66-
await get_tree().process_frame
67-
_console.progressBar(fs.get_scanning_progress() * 100 as int)
68-
_console.progressBar(100)
69-
_console.new_line()
70-
63+
if fs.has_method("reimport_files--"):
64+
_console.prints_color("Reimport images :", Color.SANDY_BROWN)
65+
for source in ["res://addons/gdUnit4/src/ui/assets/orphan", "res://addons/gdUnit4/src/ui/assets/spinner", "res://addons/gdUnit4/src/ui/assets/"]:
66+
var image_files := Array(DirAccess.get_files_at(source))
67+
#_console.prints_color("%s" % image_files, Color.SANDY_BROWN)
68+
var files := image_files.map(func full_path(file_name):
69+
return "%s/%s" % [source, file_name] )\
70+
.filter(func filter_import_files(path :String):
71+
return path.get_extension() != "import")
72+
prints(files)
73+
fs.reimport_files(files)
74+
7175
_console.prints_color("Scan sources: ", Color.SANDY_BROWN)
72-
_console.progressBar(0)
7376
fs.scan_sources()
77+
await get_tree().create_timer(5).timeout
78+
await get_tree().process_frame
79+
80+
_console.prints_color("Scan: ", Color.SANDY_BROWN)
81+
fs.scan()
7482
await get_tree().process_frame
7583
while fs.is_scanning():
7684
await get_tree().process_frame
7785
_console.progressBar(fs.get_scanning_progress() * 100 as int)
7886
_console.progressBar(100)
7987
_console.new_line()
80-
plugin.free()
81-
_state = QUIT
88+
await get_tree().process_frame
89+
plugin.queue_free()
90+
await get_tree().process_frame

addons/gdUnit4/plugin.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ func _enter_tree():
2323
if GdUnitSettings.is_update_notification_enabled():
2424
var update_tool = load("res://addons/gdUnit4/src/update/GdUnitUpdateNotify.tscn").instantiate()
2525
Engine.get_main_loop().root.call_deferred("add_child", update_tool)
26+
if GdUnit4MonoApiLoader.is_mono_supported():
27+
prints("GdUnit4Mono Version %s loaded." % GdUnit4MonoApiLoader.version())
2628

2729

2830
func _exit_tree():

addons/gdUnit4/runtest.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ IF "%GODOT_TYPE%" == "mono" (
1818

1919
%GODOT_BIN% -s -d .\addons\gdUnit4\bin\GdUnitCmdTool.gd %*
2020
SET exit_code=%errorlevel%
21-
%GODOT_BIN% --no-window --quiet -s -d .\addons\gdUnit4\bin\GdUnitCopyLog.gd %*
21+
%GODOT_BIN% --headless --quiet -s -d .\addons\gdUnit4\bin\GdUnitCopyLog.gd %*
2222

2323
ECHO %exit_code%
2424

addons/gdUnit4/src/GdUnitAwaiter.gd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const GdUnitAssertImpl = preload("res://addons/gdUnit4/src/asserts/GdUnitAssertI
99
# signal_name: signal name
1010
# args: the expected signal arguments as an array
1111
# timeout: the timeout in ms, default is set to 2000ms
12-
static func await_signal_on(source :Object, signal_name :String, args :Array = [], timeout_millis :int = 2000) -> Variant:
12+
func await_signal_on(source :Object, signal_name :String, args :Array = [], timeout_millis :int = 2000) -> Variant:
1313
# fail fast if the given source instance invalid
1414
var line_number := GdUnitAssert._get_line_number()
1515
if not is_instance_valid(source):
@@ -34,7 +34,7 @@ static func await_signal_on(source :Object, signal_name :String, args :Array = [
3434
# signal_name: signal name
3535
# args: the expected signal arguments as an array
3636
# timeout: the timeout in ms, default is set to 2000ms
37-
static func await_signal_idle_frames(source :Object, signal_name :String, args :Array = [], timeout_millis :int = 2000) -> Variant:
37+
func await_signal_idle_frames(source :Object, signal_name :String, args :Array = [], timeout_millis :int = 2000) -> Variant:
3838
var line_number := GdUnitAssert._get_line_number()
3939
# fail fast if the given source instance invalid
4040
if not is_instance_valid(source):
@@ -54,17 +54,17 @@ static func await_signal_idle_frames(source :Object, signal_name :String, args :
5454
# # waits for 100ms
5555
# await GdUnitAwaiter.await_millis(myNode, 100).completed
5656
# use this waiter and not `await get_tree().create_timer().timeout to prevent errors when a test case is timed out
57-
static func await_millis(milliSec :int) -> void:
57+
func await_millis(milliSec :int) -> void:
5858
var timer :Timer = Timer.new()
5959
timer.set_name("gdunit_await_millis_timer_%d" % timer.get_instance_id())
6060
Engine.get_main_loop().root.add_child(timer)
6161
timer.add_to_group("GdUnitTimers")
6262
timer.set_one_shot(true)
63-
timer.start(milliSec * 0.001)
63+
timer.start(milliSec / 1000.0)
6464
await timer.timeout
6565
timer.queue_free()
6666

6767

6868
# Waits until the next idle frame
69-
static func await_idle_frame() -> void:
69+
func await_idle_frame() -> void:
7070
await Engine.get_main_loop().process_frame

addons/gdUnit4/src/GdUnitTestSuite.gd

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ const NO_ARG :Variant = GdUnitConstants.NO_ARG
2121
var __is_skipped := false
2222
@warning_ignore("unused_private_class_variable")
2323
var __skip_reason :String = "Unknow."
24+
var __active_test_case :String
25+
var __awaiter := __gdunit_awaiter()
26+
# holds the actual execution context
27+
var __execution_context
2428

2529

2630
### We now load all used asserts and tool scripts into the cache according to the principle of "lazy loading"
2731
### in order to noticeably reduce the loading time of the test suite.
2832
# We go this hard way to increase the loading performance to avoid reparsing all the used scripts
2933
# for more detailed info -> https://github.com/godotengine/godot/issues/67400
3034
func __lazy_load(script_path :String) -> GDScript:
31-
return ResourceLoader.load(script_path, "GDScript", ResourceLoader.CACHE_MODE_REUSE)
35+
return GdUnitAssertions.__lazy_load(script_path)
3236

3337

3438
func __gdunit_assert() -> GDScript:
@@ -39,8 +43,8 @@ func __gdunit_tools() -> GDScript:
3943
return __lazy_load("res://addons/gdUnit4/src/core/GdUnitTools.gd")
4044

4145

42-
func __gdunit_awaiter() -> GDScript:
43-
return __lazy_load("res://addons/gdUnit4/src/GdUnitAwaiter.gd")
46+
func __gdunit_awaiter() -> Object:
47+
return __lazy_load("res://addons/gdUnit4/src/GdUnitAwaiter.gd").new()
4448

4549

4650
func __gdunit_argument_matchers():
@@ -79,7 +83,6 @@ func is_failure(_expected_failure :String = NO_ARG) -> bool:
7983
return Engine.get_meta("GD_TEST_FAILURE") if Engine.has_meta("GD_TEST_FAILURE") else false
8084

8185

82-
var __active_test_case :String
8386
func set_active_test_case(test_case :String) -> void:
8487
__active_test_case = test_case
8588

@@ -93,8 +96,14 @@ func error_as_string(error_number :int) -> String:
9396

9497
## A litle helper to auto freeing your created objects after test execution
9598
func auto_free(obj) -> Variant:
96-
var GdUnitMemoryPool = __lazy_load("res://addons/gdUnit4/src/core/GdUnitMemoryPool.gd")
97-
return GdUnitMemoryPool.register_auto_free(obj, get_meta(GdUnitMemoryPool.META_PARAM))
99+
return __execution_context.register_auto_free(obj)
100+
101+
102+
@warning_ignore("native_method_override")
103+
func add_child(node :Node, force_readable_name := false, internal := Node.INTERNAL_MODE_DISABLED) -> void:
104+
super.add_child(node, force_readable_name, internal)
105+
if __execution_context != null:
106+
__execution_context.orphan_monitor_start()
98107

99108

100109
## Discard the error message triggered by a timeout (interruption).[br]
@@ -151,12 +160,12 @@ func clear_push_errors() -> void:
151160
## args: the expected signal arguments as an array[br]
152161
## timeout: the timeout in ms, default is set to 2000ms
153162
func await_signal_on(source :Object, signal_name :String, args :Array = [], timeout :int = 2000) -> Variant:
154-
return await __gdunit_awaiter().await_signal_on(source, signal_name, args, timeout)
163+
return await __awaiter.await_signal_on(source, signal_name, args, timeout)
155164

156165

157166
## Waits until the next idle frame
158167
func await_idle_frame():
159-
await __gdunit_awaiter().await_idle_frame()
168+
await __awaiter.await_idle_frame()
160169

161170

162171
## Waits for for a given amount of milliseconds[br]
@@ -167,7 +176,7 @@ func await_idle_frame():
167176
## [/codeblock][br]
168177
## use this waiter and not `await get_tree().create_timer().timeout to prevent errors when a test case is timed out
169178
func await_millis(timeout :int):
170-
await __gdunit_awaiter().await_millis(timeout)
179+
await __awaiter.await_millis(timeout)
171180

172181

173182
## Creates a new scene runner to allow simulate interactions checked a scene.[br]
@@ -198,12 +207,12 @@ const RETURN_DEEP_STUB = GdUnitMock.RETURN_DEEP_STUB
198207

199208
## Creates a mock for given class name
200209
func mock(clazz, mock_mode := RETURN_DEFAULTS) -> Object:
201-
return __lazy_load("res://addons/gdUnit4/src/mocking/GdUnitMockBuilder.gd").build(self, clazz, mock_mode)
210+
return __lazy_load("res://addons/gdUnit4/src/mocking/GdUnitMockBuilder.gd").build(clazz, mock_mode)
202211

203212

204213
## Creates a spy checked given object instance
205214
func spy(instance) -> Object:
206-
return __lazy_load("res://addons/gdUnit4/src/spy/GdUnitSpyBuilder.gd").build(self, instance)
215+
return __lazy_load("res://addons/gdUnit4/src/spy/GdUnitSpyBuilder.gd").build(instance)
207216

208217

209218
## Configures a return value for the specified function and used arguments.[br]

0 commit comments

Comments
 (0)