Skip to content

Commit

Permalink
Gut 9 3 (#645)
Browse files Browse the repository at this point in the history
* version bump
* more documentation
* add cli changes to CHANGES
* address flakey i578 tests
* use verbose as default for no_print_logger
* use new no_input_logger
* fix issue with setting array values (CLI)
* testing and documenting monitor switch failing tests
* script parser no longer keeps reference to native instances
* refactor skip script tests to use new dynamicness
* add dedent to create_script_from_source
* moved dynmaic gut script to its own file
  • Loading branch information
bitwes authored Jul 24, 2024
1 parent e264576 commit 6fc7c17
Show file tree
Hide file tree
Showing 27 changed files with 335 additions and 181 deletions.
8 changes: 7 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

# 9.2.2
# 9.3.0

## Features
* You can Monkey Patch your doubles! You can make any method in a double call a specified `Callable` using `.to_call(callable)` on `stub`. Details are on the [Stubbing](https://gut.readthedocs.io/en/latest/Stubbing.html) wiki page.
Expand Down Expand Up @@ -46,6 +46,11 @@ assert_true(await wait_for_signal(my_obj.my_singal, 2),
func should_skip_script():
return EngineDebugger.is_active()
```
* The CLI got an update to its Option Parser. There's more info in #623:
* options that take a value can now be specified with a space (`option value`) instead of using `option=value`.
* `-gh` option now has headings for the different options. It looks a lot better.
* `-gdir` and `-gtest` can be specified multiple times instead of using a comma delimited list.
* You can use `-gconfig=` to not use a config file.
* Minor niceties such as showing that GUT is exiting in the title bar (takes a bit sometimes) and switching to full display at the end of a run if GUT does not automatically exit.
## Bug Fixes
Expand All @@ -57,6 +62,7 @@ assert_true(await wait_for_signal(my_obj.my_singal, 2),
## Deprecations
* The optional `GutTest` script variable `skip_script` has been deprecated. Use the new `should_skip_script` method instead.
* GUT now warns if you have overridden `_ready` in your test script without calling `super._ready`.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* GUT 7 on readthedocs.io: https://gut.readthedocs.io/en/godot_3x


# GUT 9.2.1 (Godot 4.2)
# GUT 9.3.0 (Godot 4.2)
GUT (Godot Unit Test) is a unit testing framework for the [Godot Engine](https://godotengine.org/). It allows you to write tests for your gdscript in gdscript.

GUT versions 9.x are for Godot 4.x
Expand Down
2 changes: 0 additions & 2 deletions addons/gut/autofree.gd
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,3 @@ func free_all():
if(is_instance_valid(_to_queue_free[i])):
_to_queue_free[i].queue_free()
_to_queue_free.clear()


30 changes: 18 additions & 12 deletions addons/gut/cli/optparse.gd
Original file line number Diff line number Diff line change
Expand Up @@ -129,41 +129,45 @@

#-------------------------------------------------------------------------------
# Holds all the properties of a command line option
#
# value will return the default when it has not been set.
#-------------------------------------------------------------------------------
class Option:
static var empty_value = &'--__this_is_an_optparse_empty_value__--'

var _value = empty_value
var value = empty_value:
var _has_been_set = false
var _value = null
# REMEMBER that when this option is an array, you have to set the value
# before you alter the contents of the array (append etc) or has_been_set
# will return false and it might not be used right. For example
# get_value_or_null will return null when you've actually changed the value.
var value = _value:
get:
if(str(_value) == empty_value):
return default
else:
return _value
return _value

set(val):
_has_been_set = true
_value = val

var option_name = ''
var default = null
var description = ''
var required = false


func _init(name,default_value,desc=''):
option_name = name
default = default_value
description = desc
value = empty_value
_value = default


func to_s(min_space=0):
var subbed_desc = description
if(subbed_desc.find('[default]') != -1):
subbed_desc = subbed_desc.replace('[default]', str(default))
subbed_desc = subbed_desc.replace('[default]', str(default))
return str(option_name.rpad(min_space), ' ', subbed_desc)


func has_been_set():
return str(_value) != empty_value
return _has_been_set



Expand Down Expand Up @@ -323,6 +327,8 @@ func _set_option_value(option, raw_value):
option.value = str(raw_value)
elif(t == TYPE_ARRAY):
var values = _convert_value_to_array(raw_value)
if(!option.has_been_set()):
option.value = []
option.value.append_array(values)
elif(t == TYPE_BOOL):
option.value = !option.default
Expand Down
2 changes: 1 addition & 1 deletion addons/gut/double_tools.gd
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ func vararg_warning():
"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.")
"that there are not any parameter count mismatch errors.")
2 changes: 1 addition & 1 deletion addons/gut/dynamic_gdscript.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func create_script_from_source(source, override_path=null):
r_path = override_path

var DynamicScript = GDScript.new()
DynamicScript.source_code = source
DynamicScript.source_code = source.dedent()
# The resource_path must be unique or Godot thinks it is trying
# to load something it has already loaded and generates an error like
# ERROR: Another resource is loaded from path 'workaround for godot
Expand Down
6 changes: 3 additions & 3 deletions addons/gut/input_sender.gd
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class InputQueueItem:
if(frame_delay > 0 and _delay_started):
_waited_frames += 1
if(_waited_frames >= frame_delay):
emit_signal("event_ready")
event_ready.emit()

func _init(t_delay,f_delay):
time_delay = t_delay
Expand All @@ -82,7 +82,7 @@ class InputQueueItem:

func _on_time_timeout():
_is_ready = true
emit_signal("event_ready")
event_ready.emit()

func _delay_timer(t):
return Engine.get_main_loop().root.get_tree().create_timer(t)
Expand Down Expand Up @@ -344,7 +344,7 @@ func _on_queue_item_ready(item):

if(_input_queue.size() == 0):
_next_queue_item = null
emit_signal("idle")
idle.emit()
else:
_input_queue[0].start()

Expand Down
5 changes: 2 additions & 3 deletions addons/gut/logger.gd
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ var fmts = {
}

var _type_data = {
types.debug: {disp='DEBUG', enabled=true, fmt=fmts.none},
types.debug: {disp='DEBUG', enabled=true, fmt=fmts.bold},
types.deprecated: {disp='DEPRECATED', enabled=true, fmt=fmts.none},
types.error: {disp='ERROR', enabled=true, fmt=fmts.red},
types.failed: {disp='Failed', enabled=true, fmt=fmts.red},
Expand Down Expand Up @@ -142,8 +142,7 @@ func _print_test_name():
func _output(text, fmt=null):
for key in _printers:
if(_should_print_to_printer(key)):
var info = ''#str(self, ':', key, ':', _printers[key], '| ')
_printers[key].send(info + text, fmt)
_printers[key].send(text, fmt)

func _log(text, fmt=fmts.none):
_print_test_name()
Expand Down
2 changes: 1 addition & 1 deletion addons/gut/plugin.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
name="Gut"
description="Unit Testing tool for Godot."
author="Butch Wesley"
version="9.2.1"
version="9.3.0"
script="gut_plugin.gd"
22 changes: 12 additions & 10 deletions addons/gut/script_parser.gd
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,14 @@ class ParsedScript:
get: return _resource
set(val): return;

var _native_instance = null

var is_native = false :
get: return _native_instance != null
var _is_native = false
var is_native = _is_native:
get: return _is_native
set(val): return;

func _notification(what, reversed=false):
if(what == NOTIFICATION_PREDELETE):
if(_native_instance != null):
_native_instance.free()
var _native_methods = {}
var _native_class_name = ""



Expand All @@ -109,7 +107,11 @@ class ParsedScript:

if(GutUtils.is_native_class(to_load)):
_resource = to_load
_native_instance = to_load.new()
_is_native = true
var inst = to_load.new()
_native_class_name = inst.get_class()
_native_methods = inst.get_method_list()
inst.free()
else:
if(!script_or_inst is Resource):
to_load = load(script_or_inst.get_script().get_path())
Expand Down Expand Up @@ -145,7 +147,7 @@ class ParsedScript:
func _parse_methods(thing):
var methods = []
if(is_native):
methods = _native_instance.get_method_list()
methods = _native_methods.duplicate()
else:
var base_type = thing.get_instance_base_type()
methods = _get_native_methods(base_type)
Expand Down Expand Up @@ -259,7 +261,7 @@ class ParsedScript:
func get_extends_text():
var text = null
if(is_native):
text = str("extends ", _native_instance.get_class())
text = str("extends ", _native_class_name)
else:
text = str("extends '", _script_path, "'")
if(_subpath != null):
Expand Down
3 changes: 3 additions & 0 deletions addons/gut/stub_params.gd
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ func to_s():
if(call_super):
base_string += " to call SUPER"

if(call_this != null):
base_string += str(" to call ", call_this)

if(parameters != null):
base_string += str(' with params (', parameters, ') returns ', return_val)
else:
Expand Down
2 changes: 1 addition & 1 deletion addons/gut/test.gd
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ func run_x_times(x):
"know why you're doing this."))
var params = []
for i in range(x):
params.append([])
params.append(i)

ph = GutUtils.ParameterHandler.new(params)
gut.parameter_handler = ph
Expand Down
2 changes: 1 addition & 1 deletion addons/gut/test_collector.gd
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func add_script(path):
# them to be run through gut. This helps cut down on creating test
# scripts to be used in test/resources.
if(ResourceLoader.has_cached(path)):
_lgr.info("Using cached version of " + path)
_lgr.debug("Using cached version of " + path)
else:
_lgr.error('Could not find script: ' + path)
return
Expand Down
2 changes: 1 addition & 1 deletion addons/gut/utils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ static var avail_fonts = ['AnonymousPro', 'CourierPrime', 'LobsterTwo', 'Default

static var version_numbers = VersionNumbers.new(
# gut_versrion (source of truth)
'9.2.1',
'9.3.0',
# required_godot_version
'4.2.0'
)
Expand Down
2 changes: 2 additions & 0 deletions documentation/docs/Input-Sender.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The `InputSender` class can be used to send `InputEvent*` events to various obje

And much much more.

__Warning__<br>
If you move the Godot window to a different monitor while tests are running it can cause input tests to fail. [This issue](https://github.com/bitwes/Gut/issues/643) has more details.

## Signals
* `idle` - Emitted when all events in the input queue have been sent.
Expand Down
4 changes: 2 additions & 2 deletions documentation/docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
copyright = '2024, Butch Wesley'
author = 'bitwes'

release = '9.2.1'
version = '9.2.1 for Godot-4'
release = '9.3.0'
version = '9.3.0 for Godot-4'

# -- General configuration

Expand Down
2 changes: 1 addition & 1 deletion documentation/docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@



Gut 9.2.1 (Godot 4.2)
Gut 9.3.0 (Godot 4.2)
=========
GUT (Godot Unit Test) is a utility for writing tests for your Godot Engine game. It allows you to write tests for your gdscripts in gdscript.

Expand Down
15 changes: 9 additions & 6 deletions test/gut_test.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class_name GutInternalTester
extends GutTest

var verbose = false

const DOUBLE_ME_PATH = 'res://test/resources/doubler_test_objects/double_me.gd'
Expand Down Expand Up @@ -123,7 +124,7 @@ func assert_fail_msg_contains(t, text):
func get_error_count(obj):
return obj.logger.get_errors().size()


var new_gut_indent_string = "| "
func new_gut(print_sub_tests=false):
var g = Gut.new()
g.logger = Logger.new()
Expand All @@ -134,8 +135,9 @@ func new_gut(print_sub_tests=false):
g.logger.disable_printer("terminal", false)
g.logger._min_indent_level = 1
g.logger.dec_indent()
g.logger.set_indent_string('|##| ')
g.logger.set_indent_string(new_gut_indent_string)
g.logger.disable_formatting(!print_sub_tests)
g.logger.set_type_enabled(g.logger.types.debug, true)

g._should_print_versions = false
g._should_print_summary = false
Expand All @@ -153,7 +155,7 @@ func new_partial_double_gut(print_sub_tests=false):
g.logger.disable_printer("terminal", false)
g.logger._min_indent_level = 1
g.logger.dec_indent()
g.logger.set_indent_string('|##| ')
g.logger.set_indent_string(new_gut_indent_string)
g.logger.disable_formatting(!print_sub_tests)
else:
g.log_level = g.LOG_LEVEL_FAIL_ONLY
Expand All @@ -164,9 +166,9 @@ func new_partial_double_gut(print_sub_tests=false):
return g


func new_no_print_logger():
func new_no_print_logger(override=!verbose):
var to_return = Logger.new()
to_return.disable_all_printers(true)
to_return.disable_all_printers(override)
return to_return


Expand All @@ -186,4 +188,5 @@ func new_wired_test(gut_instance):
# stub(t, 'get_logger').to_call_super()
# t.set_logger(logger)
# return t
# ----------------------------
# ----------------------------

Loading

0 comments on commit 6fc7c17

Please sign in to comment.