Skip to content

Commit

Permalink
chore(GUT): update GUT testing framework to 9.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowApex committed Jan 26, 2024
1 parent a82f4a0 commit d79e5e3
Show file tree
Hide file tree
Showing 40 changed files with 1,779 additions and 1,371 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ clean: ## Remove build artifacts
.PHONY: run run-force
run: build/opengamepad-ui.x86_64 run-force ## Run the project in gamescope
run-force:
$(GAMESCOPE) -w 1920 -h 1080 -f -e \
$(GAMESCOPE) -w 1920 -h 1080 -f \
--xwayland-count 2 -- ./build/opengamepad-ui.x86_64

$(EXPORT_TEMPLATE):
Expand All @@ -170,13 +170,13 @@ $(EXPORT_TEMPLATE):

.PHONY: debug
debug: ## Run the project in debug mode in gamescope
$(GAMESCOPE) -e --xwayland-count 2 -- \
$(GAMESCOPE) --xwayland-count 2 -- \
$(GODOT) --path $(PWD) --remote-debug tcp://127.0.0.1:6007 \
--position 320,140 res://entrypoint.tscn

.PHONY: debug-overlay
debug-overlay: ## Run the project in debug mode in gamescope with --overlay-mode
$(GAMESCOPE) -e --xwayland-count 2 -- \
$(GAMESCOPE) --xwayland-count 2 -- \
$(GODOT) --path $(PWD) --remote-debug tcp://127.0.0.1:6007 \
--position 320,140 res://entrypoint.tscn --overlay-mode -- steam -gamepadui -steamos3 -steampal -steamdeck

Expand Down
2 changes: 1 addition & 1 deletion addons/gut/GutScene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func set_font(font_name):

func _set_font(rtl, font_name, custom_name):
if(font_name == null):
rtl.add_theme_font_override(custom_name, null)
rtl.remove_theme_font_override(custom_name)
else:
var dyn_font = FontFile.new()
dyn_font.load_dynamic_font('res://addons/gut/fonts/' + font_name + '.ttf')
Expand Down
3 changes: 3 additions & 0 deletions addons/gut/awaiter.gd
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ func _physics_process(delta):


func _end_wait():
if(_signal_to_wait_on != null and _signal_to_wait_on.is_connected(_signal_callback)):
_signal_to_wait_on.disconnect(_signal_callback)

_wait_time = 0.0
_wait_frames = 0
_signal_to_wait_on = null
Expand Down
3 changes: 2 additions & 1 deletion addons/gut/double_templates/function_template.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{func_decleration}
__gutdbl.spy_on('{method_name}', {param_array})
{vararg_warning}__gutdbl.spy_on('{method_name}', {param_array})
if(__gutdbl.should_call_super('{method_name}', {param_array})):
return {super_call}
else:
return __gutdbl.get_stubbed_return('{method_name}', {param_array})

1 change: 1 addition & 0 deletions addons/gut/double_templates/script_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ var __gutdbl_values = {
gut = {gut_id},
from_singleton = '{singleton_name}',
is_partial = {is_partial},
doubled_methods = {doubled_methods},
}
var __gutdbl = load('res://addons/gut/double_tools.gd').new(__gutdbl_values)

Expand Down
37 changes: 25 additions & 12 deletions addons/gut/double_tools.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,58 @@ var is_partial = null
var double = null

const NO_DEFAULT_VALUE = '!__gut__no__default__value__!'
func _init(values=null):
if(values != null):
double = values.double
thepath = values.thepath
subpath = values.subpath
stubber = from_id(values.stubber)
spy = from_id(values.spy)
gut = from_id(values.gut)
from_singleton = values.from_singleton
is_partial = values.is_partial

if(gut != null):
gut.get_autofree().add_free(double)


func from_id(inst_id):
if(inst_id == -1):
return null
else:
return instance_from_id(inst_id)


func should_call_super(method_name, called_with):
if(stubber != null):
return stubber.should_call_super(double, method_name, called_with)
else:
return false


func spy_on(method_name, called_with):
if(spy != null):
spy.add_call(double, method_name, called_with)


func get_stubbed_return(method_name, called_with):
if(stubber != null):
return stubber.get_return(double, method_name, called_with)
else:
return null


func default_val(method_name, p_index, default_val=NO_DEFAULT_VALUE):
if(stubber != null):
return stubber.get_default_value(double, method_name, p_index)
else:
return null

func _init(values=null):
if(values != null):
double = values.double
thepath = values.thepath
subpath = values.subpath
stubber = from_id(values.stubber)
spy = from_id(values.spy)
gut = from_id(values.gut)
from_singleton = values.from_singleton
is_partial = values.is_partial

func vararg_warning():
if(gut != null):
gut.get_autofree().add_free(double)

gut.get_logger().warn(
"This method contains a vararg argument and the paramter count was not stubbed. " + \
"GUT adds extra parameters to this method which should fill most needs. " + \
"It is recommended that you stub param_count for this object's class to ensure " + \
"that there are not any parameter count mismatch errors.")
116 changes: 66 additions & 50 deletions addons/gut/doubler.gd
Original file line number Diff line number Diff line change
@@ -1,37 +1,3 @@
# ##############################################################################
#(G)odot (U)nit (T)est class
#
# ##############################################################################
# The MIT License (MIT)
# =====================
#
# Copyright (c) 2020 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.
#
# ##############################################################################
# Description
# -----------
# ##############################################################################



# ------------------------------------------------------------------------------
# A stroke of genius if I do say so. This allows for doubling a scene without
# having to write any files. By overloading the "instantiate" method we can
Expand All @@ -47,8 +13,22 @@ class PackedSceneDouble:

func instantiate(edit_state=0):
var inst = _scene.instantiate(edit_state)
var export_props = []
var script_export_flag = (PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_SCRIPT_VARIABLE)

if(_script != null):
if(inst.get_script() != null):
# Get all the exported props and values so we can set them again
for prop in inst.get_property_list():
var is_export = prop.usage & (script_export_flag) == script_export_flag
if(is_export):
export_props.append([prop.name, inst.get(prop.name)])

inst.set_script(_script)
for exported_value in export_props:
print('setting ', exported_value)
inst.set(exported_value[0], exported_value[1])

return inst

func load_scene(path):
Expand Down Expand Up @@ -129,15 +109,15 @@ func _get_indented_line(indents, text):


func _stub_to_call_super(parsed, method_name):
if(_utils.non_super_methods.has(method_name)):
if(!parsed.get_method(method_name).is_eligible_for_doubling()):
return

var params = _utils.StubParams.new(parsed.script_path, method_name, parsed.subpath)
params.to_call_super()
_stubber.add_stub(params)


func _get_base_script_text(parsed, override_path, partial):
func _get_base_script_text(parsed, override_path, partial, included_methods):
var path = parsed.script_path
if(override_path != null):
path = override_path
Expand Down Expand Up @@ -170,14 +150,15 @@ func _get_base_script_text(parsed, override_path, partial):
"gut_id":gut_id,
"singleton_name":'',#GutUtils.nvl(obj_info.get_singleton_name(), ''),
"is_partial":partial,
"doubled_methods":included_methods,
}

return _base_script_text.format(values)


func _is_valid_double_method(parsed_script, parsed_method):
func _is_method_eligible_for_doubling(parsed_script, parsed_method):
return !parsed_method.is_accessor() and \
!parsed_method.is_black_listed() and \
parsed_method.is_eligible_for_doubling() and \
!_ignored_methods.has(parsed_script.resource, parsed_method.meta.name)


Expand All @@ -197,30 +178,34 @@ func _create_script_no_warnings(src):


func _create_double(parsed, strategy, override_path, partial):
var base_script = _get_base_script_text(parsed, override_path, partial)
var super_name = ""
var path = ""

path = parsed.script_path
var dbl_src = ""
dbl_src += base_script
var included_methods = []

for method in parsed.get_local_methods():
if(_is_valid_double_method(parsed, method)):
if(_is_method_eligible_for_doubling(parsed, method)):
included_methods.append(method.meta.name)
var mthd = parsed.get_local_method(method.meta.name)
if(parsed.is_native):
dbl_src += _get_func_text(method.meta, parsed.resource, super_name)
dbl_src += _get_func_text(method.meta, parsed.resource)
else:
dbl_src += _get_func_text(method.meta, path, super_name)
dbl_src += _get_func_text(method.meta, path)

if(strategy == _utils.DOUBLE_STRATEGY.INCLUDE_NATIVE):
for method in parsed.get_super_methods():
if(_is_valid_double_method(parsed, method)):
if(_is_method_eligible_for_doubling(parsed, method)):
included_methods.append(method.meta.name)
_stub_to_call_super(parsed, method.meta.name)
if(parsed.is_native):
dbl_src += _get_func_text(method.meta, parsed.resource, super_name)
dbl_src += _get_func_text(method.meta, parsed.resource)
else:
dbl_src += _get_func_text(method.meta, path, super_name)
dbl_src += _get_func_text(method.meta, path)

var base_script = _get_base_script_text(parsed, override_path, partial, included_methods)
dbl_src = base_script + "\n\n" + dbl_src


if(print_source):
print(_utils.add_line_numbers(dbl_src))
Expand All @@ -234,7 +219,7 @@ func _create_double(parsed, strategy, override_path, partial):

func _stub_method_default_values(which, parsed, strategy):
for method in parsed.get_local_methods():
if(!method.is_black_listed() && !_ignored_methods.has(parsed.resource, method.meta.name)):
if(method.is_eligible_for_doubling() && !_ignored_methods.has(parsed.resource, method.meta.name)):
_stubber.stub_defaults_from_meta(parsed.script_path, method.meta)


Expand Down Expand Up @@ -262,12 +247,12 @@ func _get_inst_id_ref_str(inst):
return ref_str


func _get_func_text(method_hash, path, super_=""):
func _get_func_text(method_hash, path):
var override_count = null;
if(_stubber != null):
override_count = _stubber.get_parameter_count(path, method_hash.name)

var text = _method_maker.get_function_text(method_hash, path, override_count, super_) + "\n"
var text = _method_maker.get_function_text(method_hash, override_count) + "\n"

return text

Expand Down Expand Up @@ -338,3 +323,34 @@ func partial_double_inner(parent, inner, strategy=_strategy):

func add_ignored_method(obj, method_name):
_ignored_methods.add(obj, method_name)



# ##############################################################################
#(G)odot (U)nit (T)est class
#
# ##############################################################################
# The MIT License (MIT)
# =====================
#
# Copyright (c) 2024 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.
#
# ##############################################################################
Loading

0 comments on commit d79e5e3

Please sign in to comment.