Skip to content

Commit 6a3d76e

Browse files
authored
test: 🧪 Ported tests to 4.x (#434)
* test: 🧪 Ported tests to 4.x * fix: 🐛 fixed versions * fix: 🐛 fixed versions * fix: 🐛 don't use head * fix: 🐛 import before running tests * fix: 🔥 removed start and end index test * fix: 🐛 don't apply script extensions `install_script_extension` is commented out to prevent interference with the script extension sorting test. Applying script extensions causes the `.get_base_script()` call in `_ModLoaderScriptExtension.InheritanceSorting` to return an incorrect value. * revert: ♻️ reset addons
1 parent 766ee3e commit 6a3d76e

File tree

27 files changed

+589
-15
lines changed

27 files changed

+589
-15
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Inspired by https://github.com/bitbrain/beehave/blob/godot-4.x/.github/actions/godot-install/action.yml
2+
3+
name: install-godot-binary
4+
description: "Installs the Godot Runtime"
5+
6+
inputs:
7+
godot-version:
8+
description: "The Godot engine version"
9+
type: string
10+
required: true
11+
godot-status-version:
12+
description: "The Godot engine status version"
13+
type: string
14+
required: true
15+
godot-bin-name:
16+
type: string
17+
required: true
18+
godot-cache-path:
19+
type: string
20+
required: true
21+
22+
runs:
23+
using: composite
24+
steps:
25+
- name: "Set Cache Name"
26+
shell: bash
27+
run: |
28+
echo "CACHE_NAME=${{ runner.OS }}-Godot_v${{ inputs.godot-version }}-${{ inputs.godot-status-version }}" >> "$GITHUB_ENV"
29+
30+
- name: "Godot Cache Restore"
31+
uses: actions/cache/restore@v3
32+
id: godot-restore-cache
33+
with:
34+
path: ${{ inputs.godot-cache-path }}
35+
key: ${{ env.CACHE_NAME }}
36+
37+
- name: "Download and Install Godot ${{ inputs.godot-version }}"
38+
if: steps.godot-restore-cache.outputs.cache-hit != 'true'
39+
continue-on-error: false
40+
shell: bash
41+
run: |
42+
mkdir -p ${{ inputs.godot-cache-path }}
43+
chmod 770 ${{ inputs.godot-cache-path }}
44+
DIR="$HOME/.config/godot"
45+
if [ ! -d "$DIR" ]; then
46+
mkdir -p "$DIR"
47+
chmod 770 "$DIR"
48+
fi
49+
50+
DOWNLOAD_URL=https://github.com/godotengine/godot/releases/download/${{ inputs.godot-version }}-${{ inputs.godot-status-version }}
51+
GODOT_BIN=Godot_v${{ inputs.godot-version }}-${{ inputs.godot-status-version }}_${{ inputs.godot-bin-name }}
52+
53+
GODOT_PACKAGE=$GODOT_BIN.zip
54+
wget $DOWNLOAD_URL/$GODOT_PACKAGE -P ${{ inputs.godot-cache-path }}
55+
unzip ${{ inputs.godot-cache-path }}/$GODOT_PACKAGE -d ${{ inputs.godot-cache-path }}
56+
57+
mv ${{ inputs.godot-cache-path }}/$GODOT_BIN ${{ inputs.godot-cache-path }}/godot
58+
59+
chmod u+x ${{ inputs.godot-cache-path }}/godot
60+
echo "${{ inputs.godot-cache-path }}/godot"
61+
62+
- name: "Godot Cache Save"
63+
if: steps.godot-restore-cache.outputs.cache-hit != 'true'
64+
uses: actions/cache/save@v3
65+
with:
66+
path: ${{ inputs.godot-cache-path }}
67+
key: ${{ steps.godot-restore-cache.outputs.cache-primary-key }}

.github/actions/test/action.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Inspired by https://github.com/utopia-rise/fmod-gdextension/blob/godot-3.x/demo/run_tests.sh
2+
3+
name: test
4+
description: "Runs the tests via GUT CLI"
5+
6+
inputs:
7+
gut-download-path:
8+
required: true
9+
default: ~/gut_download
10+
gut-addons-path:
11+
required: true
12+
default: ${{ github.workspace }}/test/addons/gut
13+
godot-test-project:
14+
required: true
15+
default: ${{ github.workspace }}/test
16+
17+
runs:
18+
using: composite
19+
20+
steps:
21+
- name: "Set Cache Name"
22+
shell: bash
23+
run: |
24+
echo "CACHE_NAME_GUT=GUT_v9.3.0" >> "$GITHUB_ENV"
25+
26+
- name: "GUT Cache Restore"
27+
uses: actions/cache/restore@v3
28+
id: gut-restore-cache
29+
with:
30+
path: ${{ inputs.gut-download-path }}
31+
key: ${{ runner.os }}-${{ env.CACHE_NAME_GUT }}
32+
33+
- name: "Download GUT"
34+
if: steps.gut-restore-cache.outputs.cache-hit != 'true'
35+
continue-on-error: false
36+
shell: bash
37+
run: |
38+
mkdir -p ${{ inputs.gut-download-path }}
39+
chmod 770 ${{ inputs.gut-download-path }}
40+
41+
wget https://github.com/bitwes/Gut/archive/refs/tags/v9.3.0.zip -P ${{ inputs.gut-download-path }}
42+
unzip ${{ inputs.gut-download-path }}/v9.3.0.zip -d ${{ inputs.gut-download-path }}/unzip
43+
44+
- name: "GUT Cache Save"
45+
if: steps.gut-restore-cache.outputs.cache-hit != 'true'
46+
uses: actions/cache/save@v3
47+
with:
48+
path: ${{ inputs.gut-download-path }}
49+
key: ${{ steps.gut-restore-cache.outputs.cache-primary-key }}
50+
51+
- name: "Create addons Directory"
52+
if: ${{ !cancelled() }}
53+
shell: bash
54+
run: mkdir -p ${{ github.workspace }}/test/addons
55+
56+
- name: "⚔ Link GUT"
57+
if: ${{ !cancelled() }}
58+
shell: bash
59+
run: ln -s ${{ inputs.gut-download-path }}/unzip/Gut-9.3.0/addons/gut ${{ github.workspace }}/test/addons/gut
60+
61+
- name: "⚔ Link Mod Loader"
62+
if: ${{ !cancelled() }}
63+
shell: bash
64+
run: ln -s ${{ github.workspace }}/addons/mod_loader ${{ github.workspace }}/test/addons/mod_loader
65+
66+
- name: "⚔ Link JSON_Schema_Validator"
67+
if: ${{ !cancelled() }}
68+
shell: bash
69+
run: ln -s ${{ github.workspace }}/addons/JSON_Schema_Validator ${{ github.workspace }}/test/addons/JSON_Schema_Validator
70+
- name: "🔄️ Run Import"
71+
if: ${{ runner.OS == 'Linux'}} && ${{ !cancelled() }}
72+
env:
73+
TEST_PROJECT: ${{ inputs.godot-test-project }}
74+
shell: bash
75+
run: |
76+
cd "${TEST_PROJECT}"
77+
chmod +x run_import.sh
78+
./run_import.sh "$HOME/godot-linux/godot"
79+
- name: "🧪 Run Tests"
80+
if: ${{ runner.OS == 'Linux'}} && ${{ !cancelled() }}
81+
env:
82+
TEST_PROJECT: ${{ inputs.godot-test-project }}
83+
shell: bash
84+
run: |
85+
cd "${TEST_PROJECT}"
86+
chmod +x run_tests.sh
87+
./run_tests.sh "$HOME/godot-linux/godot"

.github/workflows/main.yml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
1-
on: [pull_request]
1+
# Inspired by https://github.com/bitbrain/beehave/blob/godot-4.x/.github/workflows/beehave-ci.yml
2+
3+
name: Mod Loader CI
4+
5+
on:
6+
push:
7+
paths-ignore:
8+
- "**.jpg"
9+
- "**.png"
10+
- "**.svg"
11+
- "**.md"
12+
- "**plugin.cfg"
13+
pull_request:
14+
paths-ignore:
15+
- "**.jpg"
16+
- "**.png"
17+
- "**.svg"
18+
- "**.md"
19+
- "**plugin.cfg"
20+
21+
concurrency:
22+
group: ${{ github.workflow }}-${{ github.ref }}
23+
cancel-in-progress: true
24+
225
jobs:
326
check_dependencies:
427
runs-on: ubuntu-latest
@@ -7,3 +30,8 @@ jobs:
730
- uses: gregsdennis/dependencies-action@main
831
env:
932
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
tests:
34+
name: "Running GUT tests on Godot 4.3"
35+
uses: ./.github/workflows/tests.yml
36+
with:
37+
godot-version: "4.3"

.github/workflows/tests.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Inspired by https://github.com/bitbrain/beehave/blob/godot-4.x/.github/workflows/unit-tests.yml
2+
3+
name: tests
4+
run-name: ${{ github.head_ref || github.ref_name }}-tests
5+
6+
on:
7+
workflow_call:
8+
inputs:
9+
os:
10+
required: false
11+
type: string
12+
default: "ubuntu-22.04"
13+
godot-version:
14+
required: true
15+
type: string
16+
default: "4.3"
17+
18+
workflow_dispatch:
19+
inputs:
20+
os:
21+
required: false
22+
type: string
23+
default: "ubuntu-22.04"
24+
godot-version:
25+
required: true
26+
type: string
27+
28+
concurrency:
29+
group: tests-${{ github.head_ref || github.ref_name }}-${{ inputs.godot-version }}
30+
cancel-in-progress: true
31+
32+
jobs:
33+
test:
34+
name: "Tests"
35+
runs-on: ${{ inputs.os }}
36+
timeout-minutes: 15
37+
38+
steps:
39+
- name: "📦 Checkout Mod Loader Repository"
40+
uses: actions/checkout@v4
41+
with:
42+
lfs: true
43+
submodules: "recursive"
44+
45+
- name: "🤖 Install Godot ${{ inputs.godot-version }}"
46+
uses: ./.github/actions/godot-install
47+
with:
48+
godot-version: ${{ inputs.godot-version }}
49+
godot-status-version: "stable"
50+
godot-bin-name: "linux.x86_64"
51+
godot-cache-path: "~/godot-linux"
52+
53+
- name: "🧪 Run Tests"
54+
if: ${{ !cancelled() }}
55+
timeout-minutes: 4
56+
uses: ./.github/actions/test
57+
with:
58+
godot-test-project: ${{ github.workspace }}/test

test/.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.godot/
2+
*.import
3+
addons/
4+
icon.png
5+
6+
# Gut stuff in root dir
7+
asset_lib_icon.png
8+
gut_panel.png
9+
.gut_editor_shortcuts.cfg
10+
BigFont.tres
11+
BigFontTheme.tres

test/.gutconfig.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"dirs":["res://Unit/"],
3+
"double_strategy":"partial",
4+
"ignore_pause":false,
5+
"include_subdirs":true,
6+
"inner_class":"",
7+
"log_level":3,
8+
"opacity":100,
9+
"prefix":"test_",
10+
"selected":"",
11+
"should_exit":true,
12+
"should_maximize":true,
13+
"suffix":".gd",
14+
"tests":[],
15+
"unit_test_name":""
16+
}

test/TestRunner.tscn

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[gd_scene format=3 uid="uid://dkea2wjvdowwf"]
2+
3+
[node name="TestRunner" type="Control"]
4+
custom_minimum_size = Vector2(740, 250)
5+
layout_mode = 3
6+
anchors_preset = 0
7+
offset_right = 740.0
8+
offset_bottom = 250.0

test/Unit/test_mod_hook_preprocessor.gd

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ func test_get_closing_paren_index(params: Array = use_parameters(test_get_closin
3535

3636

3737
var test_match_func_with_whitespace_params = [
38-
["abc", FUNCTIONS_SAMPLE1, 0, ["func abc(", 0, 9]],
39-
["test", FUNCTIONS_SAMPLE1, 0, ["func test(", 19, 29]],
40-
["_ready", FUNCTIONS_SAMPLE2, 0, ["func _ready(", 70, 82]],
41-
["_on_hit_detector_body_entered", FUNCTIONS_SAMPLE2, 0, ["func _on_hit_detector_body_entered(", 155, 190]],
38+
["abc", FUNCTIONS_SAMPLE1, 0, ["func abc("]],
39+
["test", FUNCTIONS_SAMPLE1, 0, ["func test("]],
40+
["_ready", FUNCTIONS_SAMPLE2, 0, ["func _ready("]],
41+
["_on_hit_detector_body_entered", FUNCTIONS_SAMPLE2, 0, ["func _on_hit_detector_body_entered("]],
4242
]
4343

4444
const FUNCTIONS_SAMPLE1 := """\
@@ -69,15 +69,15 @@ func _on_hit_detector_body_entered(body: Node3D) -> void:
6969
Global.reset_game()
7070
"""
7171

72+
73+
# We can't (easily) test for start and end indices due to different line endings between Windows and Linux.
7274
func test_match_func_with_whitespace(params: Array = use_parameters(test_match_func_with_whitespace_params)) -> void:
7375
# prepare
7476
var method_name: String = params[0]
7577
var text: String = params[1]
7678
var offset: int = params[2]
7779

7880
var expected_string: String = params.back()[0]
79-
var expected_start: int = params.back()[1]
80-
var expected_end: int = params.back()[2]
8181

8282
# test
8383
var result := _ModLoaderModHookPreProcessor.match_func_with_whitespace(method_name, text, offset)
@@ -89,11 +89,3 @@ func test_match_func_with_whitespace(params: Array = use_parameters(test_match_f
8989
result.get_string(), expected_string,
9090
"expected %s, got %s" % [expected_string, result.get_string()]
9191
)
92-
assert_eq(
93-
result.get_start(), expected_start,
94-
"expected %s, got %s" % [expected_start, result.get_start()]
95-
)
96-
assert_eq(
97-
result.get_end(), expected_end,
98-
"expected %s, got %s" % [expected_end, result.get_end()]
99-
)
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
extends GutTest
2+
3+
4+
#var order_before_357_correct := [
5+
# "res://mods-unpacked/test-mod3/extensions/script_extension_sorting/script_b.gd",
6+
# "res://mods-unpacked/test-mod2/extensions/script_extension_sorting/script_c.gd",
7+
# "res://mods-unpacked/test-mod1/extensions/script_extension_sorting/script_c.gd",
8+
# "res://mods-unpacked/test-mod3/extensions/script_extension_sorting/script_d.gd"
9+
#]
10+
11+
# https://github.com/GodotModding/godot-mod-loader/pull/357
12+
var order_after_357_correct := [
13+
"res://mods-unpacked/test-mod3/extensions/script_extension_sorting/script_b.gd",
14+
"res://mods-unpacked/test-mod1/extensions/script_extension_sorting/script_c.gd",
15+
"res://mods-unpacked/test-mod2/extensions/script_extension_sorting/script_c.gd",
16+
"res://mods-unpacked/test-mod3/extensions/script_extension_sorting/script_d.gd"
17+
]
18+
19+
20+
func test_handle_script_extensions():
21+
var extension_paths := [
22+
"res://mods-unpacked/test-mod1/extensions/script_extension_sorting/script_c.gd",
23+
"res://mods-unpacked/test-mod2/extensions/script_extension_sorting/script_c.gd",
24+
"res://mods-unpacked/test-mod3/extensions/script_extension_sorting/script_b.gd",
25+
"res://mods-unpacked/test-mod3/extensions/script_extension_sorting/script_d.gd"
26+
]
27+
28+
_ModLoaderScriptExtension.InheritanceSorting.new(extension_paths)
29+
30+
assert_true(extension_paths == order_after_357_correct, "Expected %s but was %s instead" % [JSON.stringify(order_after_357_correct, "\t"), JSON.stringify(extension_paths, "\t")])

test/default_env.tres

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[gd_resource type="Environment" load_steps=2 format=3 uid="uid://dhpbuhssb7uh"]
2+
3+
[sub_resource type="Sky" id="1"]
4+
5+
[resource]
6+
background_mode = 2
7+
sky = SubResource("1")

0 commit comments

Comments
 (0)