2024-01-06 11:27:15 +01:00
|
|
|
# ##############################################################################
|
|
|
|
#
|
|
|
|
# This holds all the configuratoin values for GUT. It can load and save values
|
|
|
|
# to a json file. It is also responsible for applying these settings to GUT.
|
|
|
|
#
|
|
|
|
# ##############################################################################
|
2023-01-20 23:34:39 +01:00
|
|
|
var Gut = load("res://addons/gut/gut.gd")
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
var valid_fonts = ["AnonymousPro", "CourierPro", "LobsterTwo", "Default"]
|
2022-06-02 04:13:43 +02:00
|
|
|
var default_options = {
|
|
|
|
background_color = Color(.15, .15, .15, 1).to_html(),
|
2023-01-20 23:34:39 +01:00
|
|
|
config_file = "res://.gutconfig.json",
|
2022-06-02 04:13:43 +02:00
|
|
|
dirs = [],
|
|
|
|
disable_colors = false,
|
2024-01-06 11:27:15 +01:00
|
|
|
# double strategy can be the name of the enum value, the enum value or
|
|
|
|
# lowercase name with spaces: 0/SCRIPT_ONLY/script only
|
|
|
|
# The GUI gut config expects the value to be the enum value and not a string
|
|
|
|
# when saved.
|
|
|
|
double_strategy = "SCRIPT_ONLY",
|
|
|
|
# named differently than gut option so we can use it as a flag in the cli
|
|
|
|
errors_do_not_cause_failure = false,
|
2022-06-02 04:13:43 +02:00
|
|
|
font_color = Color(.8, .8, .8, 1).to_html(),
|
2023-01-20 23:34:39 +01:00
|
|
|
font_name = "CourierPrime",
|
2022-06-02 04:13:43 +02:00
|
|
|
font_size = 16,
|
|
|
|
hide_orphans = false,
|
|
|
|
ignore_pause = false,
|
|
|
|
include_subdirs = false,
|
2023-01-20 23:34:39 +01:00
|
|
|
inner_class = "",
|
|
|
|
junit_xml_file = "",
|
2022-06-02 04:13:43 +02:00
|
|
|
junit_xml_timestamp = false,
|
|
|
|
log_level = 1,
|
|
|
|
opacity = 100,
|
2023-01-07 20:26:17 +01:00
|
|
|
paint_after = .1,
|
2023-01-20 23:34:39 +01:00
|
|
|
post_run_script = "",
|
|
|
|
pre_run_script = "",
|
|
|
|
prefix = "test_",
|
|
|
|
selected = "",
|
2022-06-02 04:13:43 +02:00
|
|
|
should_exit = false,
|
|
|
|
should_exit_on_success = false,
|
|
|
|
should_maximize = false,
|
|
|
|
compact_mode = false,
|
|
|
|
show_help = false,
|
2023-01-20 23:34:39 +01:00
|
|
|
suffix = ".gd",
|
2022-06-02 04:13:43 +02:00
|
|
|
tests = [],
|
2023-01-20 23:34:39 +01:00
|
|
|
unit_test_name = "",
|
2022-06-02 04:13:43 +02:00
|
|
|
gut_on_top = true,
|
|
|
|
}
|
|
|
|
|
2023-01-07 20:26:17 +01:00
|
|
|
var default_panel_options = {
|
2023-01-20 23:34:39 +01:00
|
|
|
font_name = "CourierPrime",
|
2024-01-06 11:27:15 +01:00
|
|
|
font_size = 16,
|
|
|
|
output_font_name = "CourierPrime",
|
|
|
|
output_font_size = 30,
|
2023-01-07 20:26:17 +01:00
|
|
|
hide_result_tree = false,
|
|
|
|
hide_output_text = false,
|
|
|
|
hide_settings = false,
|
|
|
|
use_colors = true
|
|
|
|
}
|
2022-06-02 04:13:43 +02:00
|
|
|
|
|
|
|
var options = default_options.duplicate()
|
2023-01-07 20:26:17 +01:00
|
|
|
var json = JSON.new()
|
2022-06-02 04:13:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
func _null_copy(h):
|
|
|
|
var new_hash = {}
|
|
|
|
for key in h:
|
|
|
|
new_hash[key] = null
|
|
|
|
return new_hash
|
|
|
|
|
|
|
|
|
|
|
|
func _load_options_from_config_file(file_path, into):
|
|
|
|
# SHORTCIRCUIT
|
2023-01-20 23:34:39 +01:00
|
|
|
if !FileAccess.file_exists(file_path):
|
|
|
|
if file_path != "res://.gutconfig.json":
|
2022-06-02 04:13:43 +02:00
|
|
|
print('ERROR: Config File "', file_path, '" does not exist.')
|
|
|
|
return -1
|
|
|
|
else:
|
|
|
|
return 1
|
|
|
|
|
2023-01-07 20:26:17 +01:00
|
|
|
var f = FileAccess.open(file_path, FileAccess.READ)
|
2023-01-20 23:34:39 +01:00
|
|
|
if f == null:
|
2023-01-07 20:26:17 +01:00
|
|
|
var result = FileAccess.get_open_error()
|
2023-01-20 23:34:39 +01:00
|
|
|
push_error(str("Could not load data ", file_path, " ", result))
|
2022-06-02 04:13:43 +02:00
|
|
|
return result
|
|
|
|
|
|
|
|
var json = f.get_as_text()
|
2023-01-20 23:34:39 +01:00
|
|
|
f = null # close file
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2022-11-09 21:57:46 +01:00
|
|
|
var test_json_conv = JSON.new()
|
|
|
|
test_json_conv.parse(json)
|
|
|
|
var results = test_json_conv.get_data()
|
2022-06-02 04:13:43 +02:00
|
|
|
# SHORTCIRCUIT
|
2023-01-20 23:34:39 +01:00
|
|
|
if results == null:
|
|
|
|
print("\n\n", "!! ERROR parsing file: ", file_path)
|
|
|
|
print(" at line ", results.error_line, ":")
|
|
|
|
print(" ", results.error_string)
|
2022-06-02 04:13:43 +02:00
|
|
|
return -1
|
|
|
|
|
|
|
|
# Get all the options out of the config file using the option name. The
|
|
|
|
# options hash is now the default source of truth for the name of an option.
|
2023-01-07 20:26:17 +01:00
|
|
|
_load_dict_into(results, into)
|
2022-06-02 04:13:43 +02:00
|
|
|
|
|
|
|
return 1
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
|
2023-01-07 20:26:17 +01:00
|
|
|
func _load_dict_into(source, dest):
|
|
|
|
for key in dest:
|
2023-01-20 23:34:39 +01:00
|
|
|
if source.has(key):
|
|
|
|
if source[key] != null:
|
|
|
|
if typeof(source[key]) == TYPE_DICTIONARY:
|
2023-01-07 20:26:17 +01:00
|
|
|
_load_dict_into(source[key], dest[key])
|
|
|
|
else:
|
|
|
|
dest[key] = source[key]
|
|
|
|
|
|
|
|
|
2024-01-06 11:27:15 +01:00
|
|
|
# Apply all the options specified to tester. This is where the rubber meets
|
2022-06-02 04:13:43 +02:00
|
|
|
# the road.
|
2024-01-06 11:27:15 +01:00
|
|
|
func _apply_options(opts, gut):
|
|
|
|
gut.include_subdirectories = opts.include_subdirs
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
if opts.inner_class != "":
|
2024-01-06 11:27:15 +01:00
|
|
|
gut.inner_class_name = opts.inner_class
|
|
|
|
gut.log_level = opts.log_level
|
|
|
|
gut.ignore_pause_before_teardown = opts.ignore_pause
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2024-01-06 11:27:15 +01:00
|
|
|
gut.select_script(opts.selected)
|
2022-06-02 04:13:43 +02:00
|
|
|
|
|
|
|
for i in range(opts.dirs.size()):
|
2024-01-06 11:27:15 +01:00
|
|
|
gut.add_directory(opts.dirs[i], opts.prefix, opts.suffix)
|
2022-06-02 04:13:43 +02:00
|
|
|
|
|
|
|
for i in range(opts.tests.size()):
|
2024-01-06 11:27:15 +01:00
|
|
|
gut.add_script(opts.tests[i])
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2024-01-06 11:27:15 +01:00
|
|
|
# Sometimes it is the index, sometimes it's a string. This sets it regardless
|
|
|
|
gut.double_strategy = GutUtils.get_enum_value(
|
|
|
|
opts.double_strategy, GutUtils.DOUBLE_STRATEGY, GutUtils.DOUBLE_STRATEGY.INCLUDE_NATIVE
|
|
|
|
)
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2024-01-06 11:27:15 +01:00
|
|
|
gut.unit_test_name = opts.unit_test_name
|
|
|
|
gut.pre_run_script = opts.pre_run_script
|
|
|
|
gut.post_run_script = opts.post_run_script
|
|
|
|
gut.color_output = !opts.disable_colors
|
|
|
|
gut.show_orphans(!opts.hide_orphans)
|
|
|
|
gut.junit_xml_file = opts.junit_xml_file
|
|
|
|
gut.junit_xml_timestamp = opts.junit_xml_timestamp
|
|
|
|
gut.paint_after = str(opts.paint_after).to_float()
|
|
|
|
gut.treat_error_as_failure = !opts.errors_do_not_cause_failure
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2024-01-06 11:27:15 +01:00
|
|
|
return gut
|
2022-06-02 04:13:43 +02:00
|
|
|
|
|
|
|
|
2024-01-06 11:27:15 +01:00
|
|
|
# --------------------------
|
|
|
|
# Public
|
|
|
|
# --------------------------
|
|
|
|
func write_options(path):
|
|
|
|
var content = json.stringify(options, " ")
|
|
|
|
|
|
|
|
var f = FileAccess.open(path, FileAccess.WRITE)
|
|
|
|
var result = FileAccess.get_open_error()
|
|
|
|
if f != null:
|
|
|
|
f.store_string(content)
|
|
|
|
f = null # closes file
|
|
|
|
else:
|
|
|
|
print("ERROR: could not open file ", path, " ", result)
|
|
|
|
return result
|
2022-06-02 04:13:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
func load_options(path):
|
|
|
|
return _load_options_from_config_file(path, options)
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
|
2022-06-02 04:13:43 +02:00
|
|
|
func load_panel_options(path):
|
2023-01-20 23:34:39 +01:00
|
|
|
options["panel_options"] = default_panel_options.duplicate()
|
2022-06-02 04:13:43 +02:00
|
|
|
return _load_options_from_config_file(path, options)
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
|
2022-06-02 04:13:43 +02:00
|
|
|
func load_options_no_defaults(path):
|
|
|
|
options = _null_copy(default_options)
|
|
|
|
return _load_options_from_config_file(path, options)
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
|
2022-06-02 04:13:43 +02:00
|
|
|
func apply_options(gut):
|
|
|
|
_apply_options(options, gut)
|
2024-01-06 11:27:15 +01:00
|
|
|
|
|
|
|
# ##############################################################################
|
|
|
|
# The MIT License (MIT)
|
|
|
|
# =====================
|
|
|
|
#
|
|
|
|
# Copyright (c) 2023 Tom "Butch" Wesley
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in
|
|
|
|
# all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
# THE SOFTWARE.
|
|
|
|
#
|
|
|
|
# ##############################################################################
|