Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ jobs:
godot --path . --headless --import
- name: Run tests
run: |
godot --path . --headless --script addons/gut/gut_cmdln.gd -gexit
godot --path . --headless -s addons/gut/gut_cmdln.gd -gexit
17 changes: 11 additions & 6 deletions addons/block_code/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,19 @@ This plugin uses the [Godot Unit Test](https://gut.readthedocs.io/en/latest/) (G
Tests can also be run from the command line using the GUT command line script:

```
godot --path . --headless --script addons/gut/gut_cmdln.gd -gexit
godot --path . --headless -s addons/gut/gut_cmdln.gd -gexit
```

A few options are of note here. `--path` instructs Godot to use the project in
the current directory. `--headless` instructs Godot to run without a display or
sound. `--script` instructs Godot to run the GUT command line script instead of
running the main scene. `-gexit` is an option for the GUT command line script
that instructs GUT to exit after the tests complete.
A few options are of note here:

- `--path` instructs Godot to use the project in the current directory.
- `--headless` instructs Godot to run without a display or sound.
- `-s` instructs Godot to run the GUT command line script instead of
running the main scene. Due to a [bug in
GUT](https://github.com/bitwes/Gut/issues/667), the long form `--script`
cannot be used.
- `-gexit` is an option for the GUT command line script that instructs GUT to
exit after the tests complete.

There are several other GUT command line options for running specific tests.
For example, `-gtest=path/to/test_script_1.gd,path/to/test_script_2.gd` can be
Expand Down
3 changes: 3 additions & 0 deletions addons/gut/GutScene.gd
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,6 @@ func use_compact_mode(should=true):
func set_opacity(val):
_normal_gui.modulate.a = val
_compact_gui.modulate.a = val

func set_title(text):
_set_both_titles(text)
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()


59 changes: 47 additions & 12 deletions addons/gut/awaiter.gd
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@ extends Node
signal timeout
signal wait_started

var _wait_time = 0.0
var _wait_frames = 0
var _wait_time := 0.0
var _wait_frames := 0
var _signal_to_wait_on = null

var _elapsed_time = 0.0
var _elapsed_frames = 0
var _predicate_function_waiting_to_be_true = null
var _predicate_time_between := 0.0
var _predicate_time_between_elpased := 0.0

var _did_last_wait_timeout = false
var did_last_wait_timeout = false :
get: return _did_last_wait_timeout
set(val): push_error("Cannot set did_last_wait_timeout")

var _elapsed_time := 0.0
var _elapsed_frames := 0


func _physics_process(delta):
Expand All @@ -22,49 +31,75 @@ func _physics_process(delta):
if(_elapsed_frames >= _wait_frames):
_end_wait()

if(_predicate_function_waiting_to_be_true != null):
_predicate_time_between_elpased += delta
if(_predicate_time_between_elpased >= _predicate_time_between):
_predicate_time_between_elpased = 0.0
var result = _predicate_function_waiting_to_be_true.call()
if(typeof(result) == TYPE_BOOL and result):
_end_wait()


func _end_wait():
# Check for time before checking for frames so that the extra frames added
# when waiting on a signal do not cause a false negative for timing out.
if(_wait_time > 0):
_did_last_wait_timeout = _elapsed_time >= _wait_time
elif(_wait_frames > 0):
_did_last_wait_timeout = _elapsed_frames >= _wait_frames

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
_predicate_function_waiting_to_be_true = null
_elapsed_time = 0.0
_elapsed_frames = 0
timeout.emit()


const ARG_NOT_SET = '_*_argument_*_is_*_not_set_*_'
func _signal_callback(
arg1=ARG_NOT_SET, arg2=ARG_NOT_SET, arg3=ARG_NOT_SET,
arg4=ARG_NOT_SET, arg5=ARG_NOT_SET, arg6=ARG_NOT_SET,
arg7=ARG_NOT_SET, arg8=ARG_NOT_SET, arg9=ARG_NOT_SET):
_arg1=ARG_NOT_SET, _arg2=ARG_NOT_SET, _arg3=ARG_NOT_SET,
_arg4=ARG_NOT_SET, _arg5=ARG_NOT_SET, _arg6=ARG_NOT_SET,
_arg7=ARG_NOT_SET, _arg8=ARG_NOT_SET, _arg9=ARG_NOT_SET):

_signal_to_wait_on.disconnect(_signal_callback)
# DO NOT _end_wait here. For other parts of the test to get the signal that
# was waited on, we have to wait for a couple more frames. For example, the
# signal_watcher doesn't get the signal in time if we don't do this.
_wait_frames = 2


func wait_for(x):
func wait_seconds(x):
_did_last_wait_timeout = false
_wait_time = x
wait_started.emit()


func wait_frames(x):
_did_last_wait_timeout = false
_wait_frames = x
wait_started.emit()


func wait_for_signal(the_signal, x):
func wait_for_signal(the_signal, max_time):
_did_last_wait_timeout = false
the_signal.connect(_signal_callback)
_signal_to_wait_on = the_signal
_wait_time = x
_wait_time = max_time
wait_started.emit()


func wait_until(predicate_function: Callable, max_time, time_between_calls:=0.0):
_predicate_time_between = time_between_calls
_predicate_function_waiting_to_be_true = predicate_function
_predicate_time_between_elpased = 0.0
_did_last_wait_timeout = false
_wait_time = max_time
wait_started.emit()


func is_waiting():
return _wait_time != 0.0 || _wait_frames != 0

Loading