Skip to content

Commit

Permalink
Godot 4.2 update (#136)
Browse files Browse the repository at this point in the history
* Re-import assets for new/changed format properties
* Build: update Godot versions to run tests on
* Upgrade project settings file to Godot 4.2
* Add Godot Version Badge to main `README.md`
* gdUnit4
  * Update gdUnit4 to latest version
  * Enable run all tests button for gdUnit4
* Disable Blender import to avoid warning
  • Loading branch information
Structed committed Jan 6, 2024
1 parent 0c116fb commit 2817eb0
Show file tree
Hide file tree
Showing 166 changed files with 2,752 additions and 1,904 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main-godot4.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-22.04]
godot-version: ['4.1.1']
godot-version: ['4.1.3', '4.2.1']
godot-status-version: ['stable']
include:
- os: ubuntu-22.04
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

[![CI](https://github.com/structed/godot-playfab/workflows/CI/badge.svg?branch=main)](https://github.com/Structed/godot-playfab/actions/workflows/main.yml)
[![Discord](https://img.shields.io/discord/1020665079668166677?color=rgb%2888%2C%20101%2C%20242%29&label=Discord&logo=discord)](https://discord.gg/7K7q2YuNXe)
![Godot Version - 4.2](https://img.shields.io/badge/Godot_Version-4.2-2ea44f?logo=godotengine)



# godot-playfab - for Godot 4!
Expand Down
2 changes: 1 addition & 1 deletion Textures/round_metal.png.import
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ dest_files=["res://.godot/imported/round_metal.png-4948e35416c2b444f27580d24cde3
[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/bptc_ldr=0
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
Expand Down
37 changes: 20 additions & 17 deletions addons/gdUnit4/bin/GdUnitCmdTool.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env -S godot -s
extends SceneTree

const GdUnitTools := preload("res://addons/gdUnit4/src/core/GdUnitTools.gd")

#warning-ignore-all:return_value_discarded
class CLIRunner extends Node:

Expand All @@ -16,17 +18,18 @@ class CLIRunner extends Node:
const RETURN_SUCCESS = 0
const RETURN_ERROR = 100
const RETURN_ERROR_HEADLESS_NOT_SUPPORTED = 103
const RETURN_ERROR_GODOT_VERSION_NOT_SUPPORTED = 104
const RETURN_WARNING = 101

var _state = READY
var _test_suites_to_process :Array
var _executor
var _cs_executor
var _report :GdUnitHtmlReport
var _report_dir: String
var _report_max: int = DEFAULT_REPORT_COUNT
var _runner_config := GdUnitRunnerConfig.new()
var _console := CmdConsole.new()
var _cs_executor
var _cmd_options: = CmdOptions.new([
CmdOption.new("-a, --add", "-a <directory|path of testsuite>", "Adds the given test suite or directory to the execution pipeline.", TYPE_STRING),
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),
Expand All @@ -48,19 +51,18 @@ class CLIRunner extends Node:
func _ready():
_state = INIT
_report_dir = GdUnitTools.current_dir() + "reports"
_executor = load("res://addons/gdUnit4/src/core/GdUnitExecutor.gd").new()
_executor = load("res://addons/gdUnit4/src/core/execution/GdUnitTestSuiteExecutor.gd").new()
# stop checked first test failure to fail fast
_executor.fail_fast(true)

if GdUnitTools.is_mono_supported():
_cs_executor = GdUnit3MonoAPI.create_executor(self)

if GdUnit4MonoApiLoader.is_mono_supported():
prints("GdUnit4Mono Version %s loaded." % GdUnit4MonoApiLoader.version())
_cs_executor = GdUnit4MonoApiLoader.create_executor(self)
var err = GdUnitSignals.instance().gdunit_event.connect(Callable(self, "_on_gdunit_event"))
if err != OK:
prints("gdUnitSignals failed")
push_error("Error checked startup, can't connect executor for 'send_event'")
quit(RETURN_ERROR)
add_child(_executor)


func _process(_delta):
Expand All @@ -76,10 +78,11 @@ class CLIRunner extends Node:
set_process(false)
# process next test suite
var test_suite := _test_suites_to_process.pop_front() as Node
add_child(test_suite)
var executor = _cs_executor if GdObjects.is_cs_test_suite(test_suite) else _executor
executor.Execute(test_suite)
await executor.ExecutionCompleted
if _cs_executor != null and _cs_executor.IsExecutable(test_suite):
_cs_executor.Execute(test_suite)
await _cs_executor.ExecutionCompleted
else:
await _executor.execute(test_suite)
set_process(true)
STOP:
_state = EXIT
Expand All @@ -88,9 +91,8 @@ class CLIRunner extends Node:


func quit(code :int) -> void:
if is_instance_valid(_executor):
_executor.free()
GdUnitTools.dispose_all()
await GdUnitMemoryObserver.gc_on_guarded_instances()
await get_tree().physics_frame
get_tree().quit(code)

Expand Down Expand Up @@ -288,8 +290,8 @@ class CLIRunner extends Node:
return total


func PublishEvent(data) -> void:
_on_gdunit_event(GdUnitEvent.new().deserialize(data.AsDictionary()))
func PublishEvent(data :Dictionary) -> void:
_on_gdunit_event(GdUnitEvent.new().deserialize(data))


func _on_gdunit_event(event :GdUnitEvent):
Expand Down Expand Up @@ -390,16 +392,17 @@ var _cli_runner :CLIRunner


func _initialize():
if Engine.get_version_info().hex < 0x40100:
prints("GdUnit4 requires a minimum of Godot 4.1.x Version!")
quit(CLIRunner.RETURN_ERROR_GODOT_VERSION_NOT_SUPPORTED)
return
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_MINIMIZED)
_cli_runner = CLIRunner.new()
root.add_child(_cli_runner)


func _finalize():
prints("Finallize ..")
_cli_runner.free()
prints("-Orphan nodes report-----------------------")
Window.print_orphan_nodes()
prints("-SceneTree report-----------------------")
root.print_tree_pretty()
prints("Finallize .. done")
10 changes: 6 additions & 4 deletions addons/gdUnit4/bin/GdUnitCopyLog.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env -S godot -s
extends MainLoop

const GdUnitTools := preload("res://addons/gdUnit4/src/core/GdUnitTools.gd")

const NO_LOG_TEMPLATE = """
<!DOCTYPE html>
<html>
Expand Down Expand Up @@ -89,13 +91,13 @@ func _patch_report(report_path :String, godot_log :String) -> void:
index_file.seek(0)
index_file.store_string(content)

func _copy_and_pach(from_file: String, to_dir: String) -> Result:
func _copy_and_pach(from_file: String, to_dir: String) -> GdUnitResult:
var result := GdUnitTools.copy_file(from_file, to_dir)
if result.is_error():
return result
var file := FileAccess.open(from_file, FileAccess.READ)
if file == null:
return Result.error("Can't find file '%s'. Error: %s" % [from_file, GdUnitTools.error_as_string(FileAccess.get_open_error())])
return GdUnitResult.error("Can't find file '%s'. Error: %s" % [from_file, GdUnitTools.error_as_string(FileAccess.get_open_error())])
var content := file.get_as_text()
# patch out console format codes
for color_index in range(0, 256):
Expand All @@ -108,9 +110,9 @@ func _copy_and_pach(from_file: String, to_dir: String) -> Result:
var to_file := to_dir + "/" + from_file.get_file()
file = FileAccess.open(to_file, FileAccess.WRITE)
if file == null:
return Result.error("Can't open to write '%s'. Error: %s" % [to_file, GdUnitTools.error_as_string(FileAccess.get_open_error())])
return GdUnitResult.error("Can't open to write '%s'. Error: %s" % [to_file, GdUnitTools.error_as_string(FileAccess.get_open_error())])
file.store_string(content)
return Result.empty()
return GdUnitResult.empty()

func reports_available() -> bool:
return DirAccess.dir_exists_absolute(_report_root_path)
51 changes: 30 additions & 21 deletions addons/gdUnit4/bin/ProjectScanner.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ extends SceneTree

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

var scanner := ProjectScanner.new()
var scanner := SourceScanner.new()

func _initialize():
set_auto_accept_quit(false)
root.add_child(scanner)


func _finalize():
if Engine.get_version_info().hex < 0x40100 or Engine.get_version_info().hex > 0x40101:
print("Finalize scanner ..")
scanner.free()
if Engine.get_version_info().hex < 0x40100 or Engine.get_version_info().hex > 0x40101:
prints("done")
prints("__finalize")


class ProjectScanner extends Node:

class SourceScanner extends Node:

enum {
INIT,
SCAN,
QUIT
QUIT,
DONE
}


var _counter = 0
var WAIT_TIME_IN_MS = 5.000
var _state = INIT
Expand All @@ -46,7 +46,9 @@ class ProjectScanner extends Node:
_console.prints_color("Running project scan:", Color.CORNFLOWER_BLUE)
await scan_project()
set_process(true)
_state = QUIT
if _state == QUIT or _counter >= WAIT_TIME_IN_MS:
_state = DONE
_console.prints_color("Scan project done.", Color.CORNFLOWER_BLUE)
_console.prints_color("======================================", Color.CORNFLOWER_BLUE)
_console.new_line()
Expand All @@ -58,24 +60,31 @@ class ProjectScanner extends Node:
var plugin := EditorPlugin.new()
var fs := plugin.get_editor_interface().get_resource_filesystem()

_console.prints_color("Scan :", Color.SANDY_BROWN)
_console.progressBar(0)
fs.scan()
await get_tree().process_frame
while fs.is_scanning():
await get_tree().process_frame
_console.progressBar(fs.get_scanning_progress() * 100 as int)
_console.progressBar(100)
_console.new_line()

if fs.has_method("reimport_files--"):
_console.prints_color("Reimport images :", Color.SANDY_BROWN)
for source in ["res://addons/gdUnit4/src/ui/assets/orphan", "res://addons/gdUnit4/src/ui/assets/spinner", "res://addons/gdUnit4/src/ui/assets/"]:
var image_files := Array(DirAccess.get_files_at(source))
#_console.prints_color("%s" % image_files, Color.SANDY_BROWN)
var files := image_files.map(func full_path(file_name):
return "%s/%s" % [source, file_name] )\
.filter(func filter_import_files(path :String):
return path.get_extension() != "import")
prints(files)
fs.reimport_files(files)

_console.prints_color("Scan sources: ", Color.SANDY_BROWN)
_console.progressBar(0)
fs.scan_sources()
await get_tree().create_timer(5).timeout
await get_tree().process_frame

_console.prints_color("Scan: ", Color.SANDY_BROWN)
fs.scan()
await get_tree().process_frame
while fs.is_scanning():
await get_tree().process_frame
_console.progressBar(fs.get_scanning_progress() * 100 as int)
_console.progressBar(100)
_console.new_line()
plugin.free()
_state = QUIT
await get_tree().process_frame
plugin.queue_free()
await get_tree().process_frame
2 changes: 1 addition & 1 deletion addons/gdUnit4/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="gdUnit4"
description="Unit Testing Framework for Godot Scripts"
author="Mike Schulze"
version="4.1.4"
version="4.2.1"
script="plugin.gd"
21 changes: 7 additions & 14 deletions addons/gdUnit4/plugin.gd
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
@tool
extends EditorPlugin

const GdUnitTools := preload("res://addons/gdUnit4/src/core/GdUnitTools.gd")

var _gd_inspector :Node
var _server_node
var _gd_console :Node


# removes GdUnit classes inherits from Godot.Node from the node inspecor, ohterwise it takes very long to popup the dialog
func _fixup_node_inspector() -> void:
var classes := PackedStringArray([
"GdUnitTestSuite",
"_TestCase",
"GdUnitInspecor",
"GdUnitExecutor",
"GdUnitTcpClient",
"GdUnitTcpServer"])
for clazz in classes:
remove_custom_type(clazz)


func _enter_tree():
if Engine.get_version_info().hex < 0x40100:
prints("GdUnit4 plugin requires a minimum of Godot 4.1.x Version!")
return
Engine.set_meta("GdUnitEditorPlugin", self)
GdUnitSettings.setup()
# install the GdUnit inspector
Expand All @@ -30,11 +22,12 @@ func _enter_tree():
add_control_to_bottom_panel(_gd_console, "gdUnitConsole")
_server_node = load("res://addons/gdUnit4/src/network/GdUnitServer.tscn").instantiate()
add_child(_server_node)
_fixup_node_inspector()
prints("Loading GdUnit4 Plugin success")
if GdUnitSettings.is_update_notification_enabled():
var update_tool = load("res://addons/gdUnit4/src/update/GdUnitUpdateNotify.tscn").instantiate()
Engine.get_main_loop().root.call_deferred("add_child", update_tool)
if GdUnit4MonoApiLoader.is_mono_supported():
prints("GdUnit4Mono Version %s loaded." % GdUnit4MonoApiLoader.version())


func _exit_tree():
Expand Down
2 changes: 1 addition & 1 deletion addons/gdUnit4/runtest.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ IF "%GODOT_TYPE%" == "mono" (

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

ECHO %exit_code%

Expand Down
26 changes: 26 additions & 0 deletions addons/gdUnit4/src/GdUnitAssert.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,32 @@ class_name GdUnitAssert
extends RefCounted


# Scans the current stack trace for the root cause to extract the line number
static func _get_line_number() -> int:
var stack_trace := get_stack()
if stack_trace == null or stack_trace.is_empty():
return -1
for stack_info in stack_trace:
var function :String = stack_info.get("function")
# we catch helper asserts to skip over to return the correct line number
if function.begins_with("assert_"):
continue
if function.begins_with("test_"):
return stack_info.get("line")
var source :String = stack_info.get("source")
if source.is_empty() \
or source.begins_with("user://") \
or source.ends_with("GdUnitAssert.gd") \
or source.ends_with("AssertImpl.gd") \
or source.ends_with("GdUnitTestSuite.gd") \
or source.ends_with("GdUnitSceneRunnerImpl.gd") \
or source.ends_with("GdUnitObjectInteractions.gd") \
or source.ends_with("GdUnitAwaiter.gd"):
continue
return stack_info.get("line")
return -1


## Verifies that the current value is null.
func is_null():
return self
Expand Down

0 comments on commit 2817eb0

Please sign in to comment.