Skip to content

Commit 9e51222

Browse files
committed
Fix Gut being stuck
1 parent dfc9a92 commit 9e51222

File tree

10 files changed

+146
-263
lines changed

10 files changed

+146
-263
lines changed

harness/tests/.gut_editor_config.json

Lines changed: 0 additions & 45 deletions
This file was deleted.

harness/tests/.gut_editor_shortcuts.cfg

Lines changed: 0 additions & 17 deletions
This file was deleted.

harness/tests/.gutconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"post_run_script": "",
2929
"pre_run_script": "",
3030
"prefix": "test_",
31-
"should_exit": false,
31+
"should_exit": true,
3232
"should_exit_on_success": false,
3333
"should_maximize": false,
3434
"suffix": ".gd",

harness/tests/build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,5 +231,6 @@ fun provideEditorExecutable(): File = (
231231
.also {
232232
println("[${it.joinToString()}]")
233233
}
234-
.firstOrNull { it.name.startsWith("godot.") && it.name.contains("editor") }
234+
.firstOrNull { it.name.startsWith("godot.") && it.name.contains("editor") && !it.name.contains("console") }
235+
.also{ println("Godot executable selected: $it")}
235236
?: throw Exception("Could not find editor executable"))

harness/tests/test/GutTests.gd

Lines changed: 0 additions & 138 deletions
This file was deleted.

harness/tests/test/GutTests.gd.uid

Lines changed: 0 additions & 1 deletion
This file was deleted.

harness/tests/test/GutTests.tscn

Lines changed: 143 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,150 @@
1-
[gd_scene load_steps=3 format=3 uid="uid://cp2nu4nns5vf7"]
1+
[gd_scene load_steps=3 format=3 uid="uid://d2tgjvuadohgl"]
22

3-
[ext_resource type="Script" uid="uid://chvftm4ob4x31" path="res://test/GutTests.gd" id="1_on71t"]
43
[ext_resource type="PackedScene" uid="uid://4jb53yqktyfg" path="res://addons/gut/gui/GutControl.tscn" id="1_qrxmy"]
54

5+
[sub_resource type="GDScript" id="GDScript_5bhub"]
6+
script/source = "# from https://github.com/bitwes/Gut/blob/godot_4/scripts/main.gd
7+
# and https://github.com/bitwes/Gut/blob/godot_4/scenes/main.tscn
8+
# ------------------------------------------------------------------------------
9+
# This is an example of using the GutControl (res://addons/gut/gui/GutContro.tscn)
10+
# to execute tests in a deployed game.
11+
#
12+
# Setup:
13+
# Create a scene.
14+
# Add a GutControl to your scene, name it GutControl.
15+
# Add this script to your scene.
16+
# Run it.
17+
# ------------------------------------------------------------------------------
18+
extends Node2D
19+
@onready var _gut_control = $GutControl
20+
21+
# Holds a reference to the current test script object being run. Set in
22+
# signal callbacks.
23+
var _current_script_object = null
24+
# Holds the name of the current test being run. Set in signal callbacks.
25+
var _current_test_name = null
26+
27+
28+
func _ready():
29+
simple_setup()
30+
# complex_setup()
31+
32+
33+
func simple_setup():
34+
# You must load a gut config file to use this control. Here we are loading
35+
# the default config file used by the command line. You can use any config
36+
# file you have created. Use the \"save as\" button in the Settings subpanel
37+
# to create a config file, or write your own.
38+
#
39+
# Some settings may not work. For example, the exit flags do not have any
40+
# effect.
41+
#
42+
# Settings are not saved, so any changes will be lost. The idea is that you
43+
# want to deploy the settings and users should not be able to save them. If
44+
# you want to save changes, you can call:
45+
# _gut_control.get_config().write_options(path).
46+
# Note that you cannot to write to res:// on mobile platforms, so you will
47+
# have to juggle the initial loading from res:// or user:// and save to
48+
# user://.
49+
_gut_control.load_config_file('res://.gutconfig.json')
50+
51+
# That's it. Just get a reference to the control you added to the scene and
52+
# give it a config. The rest of the stuff in this script optional.
53+
54+
55+
56+
func complex_setup():
57+
# See simple setup
58+
_gut_control.load_config_file('res://.gutconfig.json')
59+
60+
# Returns a gut_config.gd instance.
61+
var config = _gut_control.get_config()
62+
63+
# Override specific values for the purposes of this scene. You can see all
64+
# the options available in the default_options dictionary in gut_config.gd.
65+
# Changing settings AFTER _ready will not have any effect.
66+
config.options.should_exit = false
67+
config.options.should_exit_on_success = false
68+
config.options.compact_mode = false
69+
# Note that if you are exporting xml results you may want to set the path to
70+
# a file in user:// instead of an absolute path. Your game may not have
71+
# permissions to save files elsewhere when running on a mobile device.
72+
config.options.junit_xml_file = 'user://deployed_results.xml'
73+
74+
# Some actions cannot be done until after _ready has finished in all objects
75+
_post_ready_setup.call_deferred()
76+
77+
78+
79+
80+
# If you would like to connect to signals provided by gut.gd then you must do
81+
# so after _ready. This is an example of getting a reference to gut and all
82+
# of the signals it provides.
83+
func _post_ready_setup():
84+
var gut = _gut_control.get_gut()
85+
gut.start_run.connect(_on_gut_run_start)
86+
87+
gut.start_script.connect(_on_gut_start_script)
88+
gut.end_script.connect(_on_gut_end_script)
89+
90+
gut.start_test.connect(_on_gut_start_test)
91+
gut.end_test.connect(_on_gut_end_test)
92+
93+
gut.end_run.connect(_on_gut_run_end)
94+
95+
96+
# -----------------------
97+
# Events
98+
# -----------------------
99+
func _on_gut_run_start():
100+
print('Starting tests')
101+
102+
103+
# This signal passes a TestCollector.gd/TestScript instance
104+
func _on_gut_start_script(script_obj):
105+
print(script_obj.get_full_name(), ' has ', script_obj.tests.size(), ' tests')
106+
_current_script_object = script_obj
107+
108+
109+
func _on_gut_end_script():
110+
var pass_count = 0
111+
for test in _current_script_object.tests:
112+
if(test.did_pass()):
113+
pass_count += 1
114+
print(pass_count, '/', _current_script_object.tests.size(), \" passed\\n\")
115+
_current_script_object = null
116+
117+
118+
func _on_gut_start_test(test_name):
119+
_current_test_name = test_name
120+
print(' ', test_name)
121+
122+
123+
func _on_gut_end_test():
124+
# get_test_named returns a TestCollector.gd/Test instance for the name
125+
# passed in.
126+
var test_object = _current_script_object.get_test_named(_current_test_name)
127+
var status = \"failed\"
128+
if(test_object.did_pass()):
129+
status = \"passed\"
130+
elif(test_object.pending):
131+
status = \"pending\"
132+
133+
print(' ', status)
134+
_current_test_name = null
135+
136+
137+
func _on_gut_run_end():
138+
print('Tests Done')
139+
140+
141+
# You can kick of the tests via code if you want.
142+
func _on_run_gut_tests_button_pressed():
143+
_gut_control.run_tests()
144+
"
145+
6146
[node name="GutTests" type="Node2D"]
7-
script = ExtResource("1_on71t")
147+
script = SubResource("GDScript_5bhub")
8148
9149
[node name="GutControl" parent="." instance=ExtResource("1_qrxmy")]
10150
offset_right = 1171.0

0 commit comments

Comments
 (0)