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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
21 changes: 21 additions & 0 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Unit tests

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "**" ]

jobs:
run_tests:
name: Run Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: lihop/setup-godot@v3
with:
version: 4.7-stable
- run: |
cd src
godot --import --headless --path "$PWD"
godot --headless -d -s --path "$PWD" addons/gut/gut_cmdln.gd -gdir "tests" --quit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ mono_crash.*.json
*.blend1
*.tmp
src/Calibration.json
dev_config.json
27 changes: 27 additions & 0 deletions check_code_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

import subprocess
import json


def _run_and_print(command: list[str]) -> None:
Expand Down Expand Up @@ -36,9 +37,35 @@ def run_linter() -> None: # pragma: no cover
_run_and_print(["gdlint", "src"])


def run_tests() -> None: # pragma: no cover
"""Run unit tests (GUT)."""
print("========================================")
print("Running unit tests (GUT)")
print(" If a file dialog window opens, select your Godot executable.")
print(" Now running the tests...")
_run_and_print(["python", "dev_config.py"])
with open("dev_config.json", "r") as fid:
dev_config = json.load(fid)
_run_and_print(
[
dev_config["godot_executable"],
"-d",
"-s",
# "--headless",
"--path",
"./src",
"addons/gut/gut_cmdln.gd",
"-gdir",
"tests",
"-gexit_on_success",
]
)


if __name__ == "__main__": # pragma: no cover
run_style_formatter()
run_linter()
run_tests()
print("========================================")
print("Completed.")
print("Do not forget to merge main into your")
Expand Down
21 changes: 21 additions & 0 deletions dev_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from tkinter import filedialog
import json

if __name__ == "__main__": # pragma: no cover
try:
with open("dev_config.json", "r") as fid:
dev_config = json.load(fid)
except FileNotFoundError:
dev_config = {}

if (
"godot_executable" not in dev_config
or dev_config["godot_executable"] is None
):
print("Select Godot executable")
dev_config["godot_executable"] = filedialog.askopenfilename()
if dev_config["godot_executable"].endswith(".app"):
# macOS
dev_config["godot_executable"] += "/Contents/MacOS/Godot"
with open("dev_config.json", "w") as fid:
json.dump(dev_config, fid)
6 changes: 6 additions & 0 deletions gdformatrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
excluded_directories: !!set
.git: null
addons: null
line_length: 100
safety_checks: null
use_spaces: null
48 changes: 48 additions & 0 deletions gdlintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
class-definitions-order:
- tools
- classnames
- extends
- docstrings
- signals
- enums
- consts
- staticvars
- exports
- pubvars
- prvvars
- onreadypubvars
- onreadyprvvars
- others
class-load-variable-name: (([A-Z][a-z0-9]*)+|_?[a-z][a-z0-9]*(_[a-z0-9]+)*)
class-name: ([A-Z][a-z0-9]*)+
class-variable-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)*
comparison-with-itself: null
constant-name: _?[A-Z][A-Z0-9]*(_[A-Z0-9]+)*
disable: []
duplicated-load: null
enum-element-name: '[A-Z][A-Z0-9]*(_[A-Z0-9]+)*'
enum-name: ([A-Z][a-z0-9]*)+
excluded_directories: !!set
.git: null
addons: null
expression-not-assigned: null
function-argument-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)*
function-arguments-number: 10
function-name: (_on_([A-Z][a-z0-9]*)+(_[a-z0-9]+)*|_?[a-z][a-z0-9]*(_[a-z0-9]+)*)
function-preload-variable-name: ([A-Z][a-z0-9]*)+
function-variable-name: '[a-z][a-z0-9]*(_[a-z0-9]+)*'
load-constant-name: (([A-Z][a-z0-9]*)+|_?[A-Z][A-Z0-9]*(_[A-Z0-9]+)*)
loop-variable-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)*
max-file-lines: 1000
max-line-length: 100
max-public-methods: 20
max-returns: 6
mixed-tabs-and-spaces: null
no-elif-return: null
no-else-return: null
signal-name: '[a-z][a-z0-9]*(_[a-z0-9]+)*'
sub-class-name: _?([A-Z][a-z0-9]*)+
tab-characters: 1
trailing-whitespace: null
unnecessary-pass: null
unused-argument: null
132 changes: 132 additions & 0 deletions src/addons/gut/GutScene.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
extends Node2D
# ##############################################################################
# This is a wrapper around the normal and compact gui controls and serves as
# the interface between gut.gd and the gui. The GutRunner creates an instance
# of this and then this takes care of managing the different GUI controls.
# ##############################################################################
@onready var _normal_gui = $Normal
@onready var _compact_gui = $Compact

var gut = null :
set(val):
gut = val
_set_gut(val)


func _ready():
_normal_gui.switch_modes.connect(use_compact_mode.bind(true))
_compact_gui.switch_modes.connect(use_compact_mode.bind(false))

_normal_gui.set_title("GUT")
_compact_gui.set_title("GUT")

_normal_gui.align_right()
_compact_gui.to_bottom_right()

use_compact_mode(false)

if(get_parent() == get_tree().root):
_test_running_setup()

func _test_running_setup():
set_font_size(100)
_normal_gui.get_textbox().text = "hello world, how are you doing?"

# ------------------------
# Private
# ------------------------
func _set_gut(val):
if(_normal_gui.get_gut() == val):
return
_normal_gui.set_gut(val)
_compact_gui.set_gut(val)

val.start_run.connect(_on_gut_start_run)
val.end_run.connect(_on_gut_end_run)
val.start_pause_before_teardown.connect(_on_gut_pause)
val.end_pause_before_teardown.connect(_on_pause_end)

func _set_both_titles(text):
_normal_gui.set_title(text)
_compact_gui.set_title(text)


# ------------------------
# Events
# ------------------------
func _on_gut_start_run():
_set_both_titles('Running')

func _on_gut_end_run():
_set_both_titles('Finished')

func _on_gut_pause():
_set_both_titles('-- Paused --')

func _on_pause_end():
_set_both_titles('Running')


# ------------------------
# Public
# ------------------------
func get_textbox():
return _normal_gui.get_textbox()


func set_font_size(new_size):
var rtl = _normal_gui.get_textbox()

rtl.set('theme_override_font_sizes/bold_italics_font_size', new_size)
rtl.set('theme_override_font_sizes/bold_font_size', new_size)
rtl.set('theme_override_font_sizes/italics_font_size', new_size)
rtl.set('theme_override_font_sizes/normal_font_size', new_size)


func set_font(font_name):
_set_all_fonts_in_rtl(_normal_gui.get_textbox(), font_name)


func _set_font(rtl, font_name, custom_name):
if(font_name == null):
rtl.remove_theme_font_override(custom_name)
else:
var font_path = 'res://addons/gut/fonts/' + font_name + '.ttf'
if(FileAccess.file_exists(font_path)):
var dyn_font = FontFile.new()
dyn_font.load_dynamic_font('res://addons/gut/fonts/' + font_name + '.ttf')
rtl.add_theme_font_override(custom_name, dyn_font)


func _set_all_fonts_in_rtl(rtl, base_name):
if(base_name == 'Default'):
_set_font(rtl, null, 'normal_font')
_set_font(rtl, null, 'bold_font')
_set_font(rtl, null, 'italics_font')
_set_font(rtl, null, 'bold_italics_font')
else:
_set_font(rtl, base_name + '-Regular', 'normal_font')
_set_font(rtl, base_name + '-Bold', 'bold_font')
_set_font(rtl, base_name + '-Italic', 'italics_font')
_set_font(rtl, base_name + '-BoldItalic', 'bold_italics_font')


func set_default_font_color(color):
_normal_gui.get_textbox().set('custom_colors/default_color', color)


func set_background_color(color):
_normal_gui.set_bg_color(color)


func use_compact_mode(should=true):
_compact_gui.visible = should
_normal_gui.visible = !should


func set_opacity(val):
_normal_gui.modulate.a = val
_compact_gui.modulate.a = val

func set_title(text):
_set_both_titles(text)
1 change: 1 addition & 0 deletions src/addons/gut/GutScene.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://bw7tukh738kw1
16 changes: 16 additions & 0 deletions src/addons/gut/GutScene.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[gd_scene load_steps=4 format=3 uid="uid://m28heqtswbuq"]

[ext_resource type="Script" uid="uid://bw7tukh738kw1" path="res://addons/gut/GutScene.gd" id="1_b4m8y"]
[ext_resource type="PackedScene" uid="uid://duxblir3vu8x7" path="res://addons/gut/gui/NormalGui.tscn" id="2_j6ywb"]
[ext_resource type="PackedScene" uid="uid://cnqqdfsn80ise" path="res://addons/gut/gui/MinGui.tscn" id="3_3glw1"]

[node name="GutScene" type="Node2D"]
script = ExtResource("1_b4m8y")

[node name="Normal" parent="." instance=ExtResource("2_j6ywb")]

[node name="Compact" parent="." instance=ExtResource("3_3glw1")]
offset_left = 5.0
offset_top = 273.0
offset_right = 265.0
offset_bottom = 403.0
22 changes: 22 additions & 0 deletions src/addons/gut/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)
=====================

Copyright (c) 2018 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.
52 changes: 52 additions & 0 deletions src/addons/gut/UserFileViewer.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
extends Window

@onready var rtl = $TextDisplay/RichTextLabel

func _get_file_as_text(path):
var to_return = null
var f = FileAccess.open(path, FileAccess.READ)
if(f != null):
to_return = f.get_as_text()
else:
to_return = str('ERROR: Could not open file. Error code ', FileAccess.get_open_error())
return to_return

func _ready():
rtl.clear()

func _on_OpenFile_pressed():
$FileDialog.popup_centered()

func _on_FileDialog_file_selected(path):
show_file(path)

func _on_Close_pressed():
self.hide()

func show_file(path):
var text = _get_file_as_text(path)
if(text == ''):
text = '<Empty File>'
rtl.set_text(text)
self.window_title = path

func show_open():
self.popup_centered()
$FileDialog.popup_centered()

func get_rich_text_label():
return $TextDisplay/RichTextLabel

func _on_Home_pressed():
rtl.scroll_to_line(0)

func _on_End_pressed():
rtl.scroll_to_line(rtl.get_line_count() -1)

func _on_Copy_pressed():
return
# OS.clipboard = rtl.text

func _on_file_dialog_visibility_changed():
if rtl.text.length() == 0 and not $FileDialog.visible:
self.hide()
1 change: 1 addition & 0 deletions src/addons/gut/UserFileViewer.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://x51wilphva3d
Loading
Loading