2022-06-02 04:13:43 +02:00
|
|
|
extends Node2D
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
var Gut = load("res://addons/gut/gut.gd")
|
|
|
|
var ResultExporter = load("res://addons/gut/result_exporter.gd")
|
|
|
|
var GutConfig = load("res://addons/gut/gut_config.gd")
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
const RUNNER_JSON_PATH = "res://.gut_editor_config.json"
|
|
|
|
const RESULT_FILE = "user://.gut_editor.bbcode"
|
|
|
|
const RESULT_JSON = "user://.gut_editor.json"
|
2022-06-02 04:13:43 +02:00
|
|
|
|
|
|
|
var _gut_config = null
|
2023-01-20 23:34:39 +01:00
|
|
|
var _gut = null
|
2022-06-02 04:13:43 +02:00
|
|
|
var _wrote_results = false
|
|
|
|
# Flag for when this is being used at the command line. Otherwise it is
|
|
|
|
# assumed this is being used by the panel and being launched with
|
|
|
|
# play_custom_scene
|
|
|
|
var _cmdln_mode = false
|
|
|
|
|
2022-11-09 21:57:46 +01:00
|
|
|
@onready var _gut_layer = $GutLayer
|
2023-01-07 20:26:17 +01:00
|
|
|
@onready var _gui = $GutLayer/GutScene
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2023-01-07 20:26:17 +01:00
|
|
|
var auto_run_tests = true
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
|
2022-06-02 04:13:43 +02:00
|
|
|
func _ready():
|
2023-01-20 23:34:39 +01:00
|
|
|
if _gut_config == null:
|
2022-06-02 04:13:43 +02:00
|
|
|
_gut_config = GutConfig.new()
|
2023-01-07 20:26:17 +01:00
|
|
|
_gut_config.load_panel_options(RUNNER_JSON_PATH)
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2022-11-09 22:52:54 +01:00
|
|
|
# The command line will call run_tests on its own. When used from the panel
|
|
|
|
# we have to kick off the tests ourselves b/c there's no way I know of to
|
2022-06-02 04:13:43 +02:00
|
|
|
# interact with the scene that was run via play_custom_scene.
|
2023-01-20 23:34:39 +01:00
|
|
|
if !_cmdln_mode and auto_run_tests:
|
|
|
|
call_deferred("run_tests")
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2023-01-07 20:26:17 +01:00
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
func run_tests(show_gui = true):
|
|
|
|
if _gut == null:
|
2023-01-07 20:26:17 +01:00
|
|
|
get_gut()
|
|
|
|
|
|
|
|
_setup_gui(show_gui)
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2023-01-07 20:26:17 +01:00
|
|
|
_gut.add_children_to = self
|
2023-01-20 23:34:39 +01:00
|
|
|
if _gut_config.options.gut_on_top:
|
2022-06-02 04:13:43 +02:00
|
|
|
_gut_layer.add_child(_gut)
|
|
|
|
else:
|
|
|
|
add_child(_gut)
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
if !_cmdln_mode:
|
|
|
|
(
|
|
|
|
_gut
|
|
|
|
. end_run
|
|
|
|
. connect(
|
|
|
|
_on_tests_finished.bind(
|
|
|
|
_gut_config.options.should_exit, _gut_config.options.should_exit_on_success
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
2022-06-02 04:13:43 +02:00
|
|
|
|
|
|
|
_gut_config.config_gut(_gut)
|
2023-01-20 23:34:39 +01:00
|
|
|
var run_rest_of_scripts = _gut_config.options.unit_test_name == ""
|
2022-06-02 04:13:43 +02:00
|
|
|
|
|
|
|
_gut.test_scripts(run_rest_of_scripts)
|
|
|
|
|
|
|
|
|
2023-01-07 20:26:17 +01:00
|
|
|
func _setup_gui(show_gui):
|
2023-01-20 23:34:39 +01:00
|
|
|
if show_gui:
|
2023-01-07 20:26:17 +01:00
|
|
|
_gui.gut = _gut
|
2023-01-20 23:34:39 +01:00
|
|
|
var printer = _gut.logger.get_printer("gui")
|
2023-01-07 20:26:17 +01:00
|
|
|
printer.set_textbox(_gui.get_textbox())
|
|
|
|
else:
|
2023-01-20 23:34:39 +01:00
|
|
|
_gut.logger.disable_printer("gui", true)
|
2023-01-07 20:26:17 +01:00
|
|
|
_gui.visible = false
|
|
|
|
|
|
|
|
var opts = _gut_config.options
|
|
|
|
_gui.set_font_size(opts.font_size)
|
|
|
|
_gui.set_font(opts.font_name)
|
2023-01-20 23:34:39 +01:00
|
|
|
if opts.font_color != null and opts.font_color.is_valid_html_color():
|
2023-01-07 20:26:17 +01:00
|
|
|
_gui.set_default_font_color(Color(opts.font_color))
|
2023-01-20 23:34:39 +01:00
|
|
|
if opts.background_color != null and opts.background_color.is_valid_html_color():
|
2023-01-07 20:26:17 +01:00
|
|
|
_gui.set_background_color(Color(opts.background_color))
|
|
|
|
|
|
|
|
#_tester.set_modulate(Color(1.0, 1.0, 1.0, min(1.0, float(opts.opacity) / 100)))
|
|
|
|
# if(opts.should_maximize):
|
|
|
|
# _tester.maximize()
|
|
|
|
#if(opts.compact_mode):
|
|
|
|
# _tester.get_gui().compact_mode(true)
|
|
|
|
|
|
|
|
|
2022-06-02 04:13:43 +02:00
|
|
|
func _write_results():
|
2023-01-20 23:34:39 +01:00
|
|
|
var content = _gui.get_textbox().text #_gut.logger.get_gui_bbcode()
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2023-01-07 20:26:17 +01:00
|
|
|
var f = FileAccess.open(RESULT_FILE, FileAccess.WRITE)
|
2023-01-20 23:34:39 +01:00
|
|
|
if f != null:
|
2022-06-02 04:13:43 +02:00
|
|
|
f.store_string(content)
|
|
|
|
f.close()
|
|
|
|
else:
|
2023-01-20 23:34:39 +01:00
|
|
|
push_error("Could not save bbcode, result = ", FileAccess.get_open_error())
|
2022-06-02 04:13:43 +02:00
|
|
|
|
|
|
|
var exporter = ResultExporter.new()
|
2023-01-07 20:26:17 +01:00
|
|
|
var f_result = exporter.write_json_file(_gut, RESULT_JSON)
|
2022-06-02 04:13:43 +02:00
|
|
|
_wrote_results = true
|
|
|
|
|
|
|
|
|
|
|
|
func _exit_tree():
|
2023-01-20 23:34:39 +01:00
|
|
|
if !_wrote_results and !_cmdln_mode:
|
2022-06-02 04:13:43 +02:00
|
|
|
_write_results()
|
|
|
|
|
|
|
|
|
|
|
|
func _on_tests_finished(should_exit, should_exit_on_success):
|
|
|
|
_write_results()
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
if should_exit:
|
2022-06-02 04:13:43 +02:00
|
|
|
get_tree().quit()
|
2023-01-20 23:34:39 +01:00
|
|
|
elif should_exit_on_success and _gut.get_fail_count() == 0:
|
2022-06-02 04:13:43 +02:00
|
|
|
get_tree().quit()
|
|
|
|
|
|
|
|
|
|
|
|
func get_gut():
|
2023-01-20 23:34:39 +01:00
|
|
|
if _gut == null:
|
2022-06-02 04:13:43 +02:00
|
|
|
_gut = Gut.new()
|
|
|
|
return _gut
|
|
|
|
|
|
|
|
|
|
|
|
func set_gut_config(which):
|
|
|
|
_gut_config = which
|
|
|
|
|
|
|
|
|
|
|
|
func set_cmdln_mode(is_it):
|
|
|
|
_cmdln_mode = is_it
|