diff --git a/.gitignore b/.gitignore index cb31bf0..c74f550 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ # .NET bin/ +# Allow GdUnit4 CLI scripts (path contains …/gdUnit4/bin/, not build output). +!client/addons/gdUnit4/bin/ +!client/addons/gdUnit4/bin/** obj/ out/ *.user diff --git a/client/addons/gdUnit4/bin/GdUnitCmdTool.gd b/client/addons/gdUnit4/bin/GdUnitCmdTool.gd new file mode 100644 index 0000000..cae9138 --- /dev/null +++ b/client/addons/gdUnit4/bin/GdUnitCmdTool.gd @@ -0,0 +1,21 @@ +#!/usr/bin/env -S godot -s +extends SceneTree + + +var _cli_runner: GdUnitTestCIRunner + + +func _initialize() -> void: + DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_MINIMIZED) + _cli_runner = GdUnitTestCIRunner.new() + root.add_child(_cli_runner) + + +# do not use print statements on _finalize it results in random crashes +func _finalize() -> void: + queue_delete(_cli_runner) + if OS.is_stdout_verbose(): + prints("Finallize ..") + prints("-Orphan nodes report-----------------------") + Window.print_orphan_nodes() + prints("Finallize .. done") diff --git a/client/addons/gdUnit4/bin/GdUnitCmdTool.gd.uid b/client/addons/gdUnit4/bin/GdUnitCmdTool.gd.uid new file mode 100644 index 0000000..74e82e2 --- /dev/null +++ b/client/addons/gdUnit4/bin/GdUnitCmdTool.gd.uid @@ -0,0 +1 @@ +uid://dy0y43t1ir3sq diff --git a/client/addons/gdUnit4/bin/GdUnitCopyLog.gd b/client/addons/gdUnit4/bin/GdUnitCopyLog.gd new file mode 100644 index 0000000..8b22805 --- /dev/null +++ b/client/addons/gdUnit4/bin/GdUnitCopyLog.gd @@ -0,0 +1,167 @@ +#!/usr/bin/env -S godot -s +extends MainLoop + +const GdUnitTools := preload("res://addons/gdUnit4/src/core/GdUnitTools.gd") + +# gdlint: disable=max-line-length +const LOG_FRAME_TEMPLATE = """ + + +
+ + +In order for logging to take place, you must activate the Activate file logging option in the project settings.
+You can enable the logging under: +Project Settings > Debug > File Logging > Enable File Logging in the project settings.
+""" + +#warning-ignore-all:return_value_discarded +var _cmd_options := CmdOptions.new([ + CmdOption.new( + "-rd, --report-directory", + "-rd" + file.get_as_text() + # patch out console format codes + for color_index in range(0, 256): + var to_replace := "[38;5;%dm" % color_index + content = content.replace(to_replace, "") + content += "" + content = content\ + .replace("[0m", "")\ + .replace(GdUnitCSIMessageWriter.CSI_BOLD, "")\ + .replace(GdUnitCSIMessageWriter.CSI_ITALIC, "")\ + .replace(GdUnitCSIMessageWriter.CSI_UNDERLINE, "") + return GdUnitResult.success(content) + + +func write_report(content: String, godot_log_file: String) -> GdUnitResult: + var file := FileAccess.open(get_log_report_html(), FileAccess.WRITE) + if file == null: + return GdUnitResult.error( + "Can't open to write '%s'. Error: %s" + % [get_log_report_html(), error_string(FileAccess.get_open_error())] + ) + var report_html := LOG_FRAME_TEMPLATE.replace("${content}", content) + file.store_string(report_html) + _update_index_html(godot_log_file) + return GdUnitResult.success(file) + + +func _update_index_html(godot_log_file: String) -> void: + var index_path := "%s/index.html" % _current_report_path + var index_file := FileAccess.open(index_path, FileAccess.READ_WRITE) + if index_file == null: + push_error( + "Can't add log path '%s' to `%s`. Error: %s" + % [godot_log_file, index_path, error_string(FileAccess.get_open_error())] + ) + return + var content := index_file.get_as_text()\ + .replace("${log_report}", get_log_report_html())\ + .replace("${godot_log_file}", godot_log_file) + # overide it + index_file.seek(0) + index_file.store_string(content) + + +func get_cmdline_args() -> PackedStringArray: + if _debug_cmd_args.is_empty(): + return OS.get_cmdline_args() + return _debug_cmd_args diff --git a/client/addons/gdUnit4/bin/GdUnitCopyLog.gd.uid b/client/addons/gdUnit4/bin/GdUnitCopyLog.gd.uid new file mode 100644 index 0000000..e8f4d7b --- /dev/null +++ b/client/addons/gdUnit4/bin/GdUnitCopyLog.gd.uid @@ -0,0 +1 @@ +uid://blqb428xny7rq