Skip to content

Commit 3050f2e

Browse files
authored
Merge pull request #40 from endlessm/tests
Add tests
2 parents 5c7c992 + 108f05f commit 3050f2e

File tree

131 files changed

+15896
-24
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

131 files changed

+15896
-24
lines changed

.github/workflows/checks.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Checks
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
pre-commit:
11+
name: Linting and Formatting
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-python@v5
16+
- name: set PY
17+
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
18+
- uses: actions/cache@v4
19+
with:
20+
path: ~/.cache/pre-commit
21+
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
22+
- uses: pre-commit/action@v3.0.1
23+
24+
tests:
25+
name: Tests
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
- name: Setup Godot
31+
uses: chickensoft-games/setup-godot@v2.0.1
32+
with:
33+
version: 4.2.2
34+
use-dotnet: false
35+
- name: Initialize Godot
36+
run: |
37+
godot --path . --headless --import
38+
- name: Run tests
39+
run: |
40+
godot --path . --headless --script addons/gut/gut_cmdln.gd -gexit

.github/workflows/pre-commit.yaml

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

.gutconfig.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"dirs": [
3+
"res://tests"
4+
],
5+
"include_subdirs": true
6+
}

.pre-commit-config.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@ repos:
1515
hooks:
1616
- id: gdformat
1717
args: [--line-length=200]
18-
files:
19-
^addons/block_code/(?!lib/).*$
18+
files: ^(addons/block_code/(?!lib/).*|tests/.*)$

addons/block_code/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,9 @@ pre-commit install
3838
```
3939

4040
Now `pre-commit` will run automatically on `git commit`!
41+
42+
## Testing
43+
44+
This plugin uses the [Godot Unit Test](https://gut.readthedocs.io/en/latest/)
45+
(GUT) plugin for testing. In the editor, click on the GUT tab in the bottom
46+
panel to open the test panel. Then click Run All to run the tests.

addons/gut/GutScene.gd

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
extends Node2D
2+
# ##############################################################################
3+
# This is a wrapper around the normal and compact gui controls and serves as
4+
# the interface between gut.gd and the gui. The GutRunner creates an instance
5+
# of this and then this takes care of managing the different GUI controls.
6+
# ##############################################################################
7+
@onready var _normal_gui = $Normal
8+
@onready var _compact_gui = $Compact
9+
10+
var gut = null :
11+
set(val):
12+
gut = val
13+
_set_gut(val)
14+
15+
16+
func _ready():
17+
_normal_gui.switch_modes.connect(use_compact_mode.bind(true))
18+
_compact_gui.switch_modes.connect(use_compact_mode.bind(false))
19+
20+
_normal_gui.set_title("GUT")
21+
_compact_gui.set_title("GUT")
22+
23+
_normal_gui.align_right()
24+
_compact_gui.to_bottom_right()
25+
26+
use_compact_mode(false)
27+
28+
if(get_parent() == get_tree().root):
29+
_test_running_setup()
30+
31+
func _test_running_setup():
32+
set_font_size(100)
33+
_normal_gui.get_textbox().text = "hello world, how are you doing?"
34+
35+
# ------------------------
36+
# Private
37+
# ------------------------
38+
func _set_gut(val):
39+
if(_normal_gui.get_gut() == val):
40+
return
41+
_normal_gui.set_gut(val)
42+
_compact_gui.set_gut(val)
43+
44+
val.start_run.connect(_on_gut_start_run)
45+
val.end_run.connect(_on_gut_end_run)
46+
val.start_pause_before_teardown.connect(_on_gut_pause)
47+
val.end_pause_before_teardown.connect(_on_pause_end)
48+
49+
func _set_both_titles(text):
50+
_normal_gui.set_title(text)
51+
_compact_gui.set_title(text)
52+
53+
54+
# ------------------------
55+
# Events
56+
# ------------------------
57+
func _on_gut_start_run():
58+
_set_both_titles('Running')
59+
60+
func _on_gut_end_run():
61+
_set_both_titles('Finished')
62+
63+
func _on_gut_pause():
64+
_set_both_titles('-- Paused --')
65+
66+
func _on_pause_end():
67+
_set_both_titles('Running')
68+
69+
70+
# ------------------------
71+
# Public
72+
# ------------------------
73+
func get_textbox():
74+
return _normal_gui.get_textbox()
75+
76+
77+
func set_font_size(new_size):
78+
var rtl = _normal_gui.get_textbox()
79+
80+
rtl.set('theme_override_font_sizes/bold_italics_font_size', new_size)
81+
rtl.set('theme_override_font_sizes/bold_font_size', new_size)
82+
rtl.set('theme_override_font_sizes/italics_font_size', new_size)
83+
rtl.set('theme_override_font_sizes/normal_font_size', new_size)
84+
85+
86+
func set_font(font_name):
87+
_set_all_fonts_in_rtl(_normal_gui.get_textbox(), font_name)
88+
89+
90+
func _set_font(rtl, font_name, custom_name):
91+
if(font_name == null):
92+
rtl.remove_theme_font_override(custom_name)
93+
else:
94+
var dyn_font = FontFile.new()
95+
dyn_font.load_dynamic_font('res://addons/gut/fonts/' + font_name + '.ttf')
96+
rtl.add_theme_font_override(custom_name, dyn_font)
97+
98+
99+
func _set_all_fonts_in_rtl(rtl, base_name):
100+
if(base_name == 'Default'):
101+
_set_font(rtl, null, 'normal_font')
102+
_set_font(rtl, null, 'bold_font')
103+
_set_font(rtl, null, 'italics_font')
104+
_set_font(rtl, null, 'bold_italics_font')
105+
else:
106+
_set_font(rtl, base_name + '-Regular', 'normal_font')
107+
_set_font(rtl, base_name + '-Bold', 'bold_font')
108+
_set_font(rtl, base_name + '-Italic', 'italics_font')
109+
_set_font(rtl, base_name + '-BoldItalic', 'bold_italics_font')
110+
111+
112+
func set_default_font_color(color):
113+
_normal_gui.get_textbox().set('custom_colors/default_color', color)
114+
115+
116+
func set_background_color(color):
117+
_normal_gui.set_bg_color(color)
118+
119+
120+
func use_compact_mode(should=true):
121+
_compact_gui.visible = should
122+
_normal_gui.visible = !should
123+
124+
125+
func set_opacity(val):
126+
_normal_gui.modulate.a = val
127+
_compact_gui.modulate.a = val

addons/gut/GutScene.tscn

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[gd_scene load_steps=4 format=3 uid="uid://m28heqtswbuq"]
2+
3+
[ext_resource type="Script" path="res://addons/gut/GutScene.gd" id="1_b4m8y"]
4+
[ext_resource type="PackedScene" uid="uid://duxblir3vu8x7" path="res://addons/gut/gui/NormalGui.tscn" id="2_j6ywb"]
5+
[ext_resource type="PackedScene" uid="uid://cnqqdfsn80ise" path="res://addons/gut/gui/MinGui.tscn" id="3_3glw1"]
6+
7+
[node name="GutScene" type="Node2D"]
8+
script = ExtResource("1_b4m8y")
9+
10+
[node name="Normal" parent="." instance=ExtResource("2_j6ywb")]
11+
12+
[node name="Compact" parent="." instance=ExtResource("3_3glw1")]
13+
offset_left = 5.0
14+
offset_top = 273.0
15+
offset_right = 265.0
16+
offset_bottom = 403.0

addons/gut/LICENSE.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
=====================
3+
4+
Copyright (c) 2018 Tom "Butch" Wesley
5+
6+
Permission is hereby granted, free of charge, to any person obtaining a copy
7+
of this software and associated documentation files (the "Software"), to deal
8+
in the Software without restriction, including without limitation the rights
9+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
copies of the Software, and to permit persons to whom the Software is
11+
furnished to do so, subject to the following conditions:
12+
13+
The above copyright notice and this permission notice shall be included in
14+
all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
THE SOFTWARE.

addons/gut/UserFileViewer.gd

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
extends Window
2+
3+
@onready var rtl = $TextDisplay/RichTextLabel
4+
5+
func _get_file_as_text(path):
6+
var to_return = null
7+
var f = FileAccess.open(path, FileAccess.READ)
8+
if(f != null):
9+
to_return = f.get_as_text()
10+
else:
11+
to_return = str('ERROR: Could not open file. Error code ', FileAccess.get_open_error())
12+
return to_return
13+
14+
func _ready():
15+
rtl.clear()
16+
17+
func _on_OpenFile_pressed():
18+
$FileDialog.popup_centered()
19+
20+
func _on_FileDialog_file_selected(path):
21+
show_file(path)
22+
23+
func _on_Close_pressed():
24+
self.hide()
25+
26+
func show_file(path):
27+
var text = _get_file_as_text(path)
28+
if(text == ''):
29+
text = '<Empty File>'
30+
rtl.set_text(text)
31+
self.window_title = path
32+
33+
func show_open():
34+
self.popup_centered()
35+
$FileDialog.popup_centered()
36+
37+
func get_rich_text_label():
38+
return $TextDisplay/RichTextLabel
39+
40+
func _on_Home_pressed():
41+
rtl.scroll_to_line(0)
42+
43+
func _on_End_pressed():
44+
rtl.scroll_to_line(rtl.get_line_count() -1)
45+
46+
func _on_Copy_pressed():
47+
return
48+
# OS.clipboard = rtl.text
49+
50+
func _on_file_dialog_visibility_changed():
51+
if rtl.text.length() == 0 and not $FileDialog.visible:
52+
self.hide()

0 commit comments

Comments
 (0)