Skip to content

Move units tests to GDUNIT #789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/test_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ jobs:
cd harness/tests/
chmod +x bin/godot.*
jlink --add-modules java.base,java.logging --output jvm/jre-amd64-linux
./gradlew runGutTests
./gradlew runGDTests
timeout-minutes: 30
2 changes: 1 addition & 1 deletion .github/workflows/test_linux_exports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,5 @@ jobs:
- name: Run Tests
run: |
cd harness/tests/
./gradlew runExportedGutTests
./gradlew runExportedGDTests
timeout-minutes: 30
2 changes: 1 addition & 1 deletion .github/workflows/test_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ jobs:
cd harness/tests/
chmod +x bin/godot.*
jlink --add-modules java.base,java.logging --output jvm/jre-arm64-macos
./gradlew runGutTests
./gradlew runGDTests
timeout-minutes: 30
2 changes: 1 addition & 1 deletion .github/workflows/test_macos_exports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,5 @@ jobs:
- name: Run Tests
run: |
cd harness/tests/
./gradlew runExportedGutTests
./gradlew runExportedGDTests
timeout-minutes: 30
2 changes: 1 addition & 1 deletion .github/workflows/test_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ jobs:
run: |
cd harness/tests/
jlink --add-modules java.base,java.logging --output jvm/jre-amd64-windows
./gradlew runGutTests
./gradlew runGDTests
timeout-minutes: 30
2 changes: 1 addition & 1 deletion .github/workflows/test_windows_exports.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,5 @@ jobs:
- name: Run Tests
run: |
cd harness/tests/
./gradlew runExportedGutTests
./gradlew runExportedGDTests
timeout-minutes: 30
1 change: 1 addition & 0 deletions harness/tests/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ graal/godot-kotlin-graal-jni-config.json
/.godot/
/test_output.txt
/jvm/
/reports
45 changes: 0 additions & 45 deletions harness/tests/.gut_editor_config.json

This file was deleted.

17 changes: 0 additions & 17 deletions harness/tests/.gut_editor_shortcuts.cfg

This file was deleted.

16 changes: 0 additions & 16 deletions harness/tests/.gutconfig.json

This file was deleted.

8 changes: 4 additions & 4 deletions harness/tests/Spatial.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ resource_test = SubResource("NavigationMesh_1ex3u")
jvm_id = 319061373
nav_meshes = Array[NavigationMesh]([SubResource("NavigationMesh_q3pqa")])
nullable_array = Array[NavigationMesh]([SubResource("NavigationMesh_hn8kg"), null])
nav_meshes_dictionary = {
nav_meshes_dictionary = Dictionary[String, NavigationMesh]({
"AwesomeNavmesh": SubResource("NavigationMesh_87cay")
}
nullable_dictionary = {
})
nullable_dictionary = Dictionary[String, NavigationMesh]({
"notnull": SubResource("NavigationMesh_b12lh"),
"null": null
}
})

[node name="Camera" type="Camera3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 0.974354, 0.225019, 0, -0.225019, 0.974354, 0, 1.2131, 2.47241)
Expand Down
1 change: 1 addition & 0 deletions harness/tests/addons/gdUnit4/GdUnitRunner.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"included":{"res://test":[]},"server_port":31002,"skipped":{},"version":"1.0"}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
The MIT License (MIT)
=====================
MIT License

Copyright (c) 2018 Tom "Butch" Wesley
Copyright (c) 2023 Mike Schulze

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -10,13 +9,13 @@ 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 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.
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
111 changes: 111 additions & 0 deletions harness/tests/addons/gdUnit4/bin/GdUnitBuildTool.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#!/usr/bin/env -S godot -s
extends SceneTree

enum {
INIT,
PROCESSING,
EXIT
}

const RETURN_SUCCESS = 0
const RETURN_ERROR = 100
const RETURN_WARNING = 101

var _console := CmdConsole.new()
var _cmd_options: = CmdOptions.new([
CmdOption.new(
"-scp, --src_class_path",
"-scp <source_path>",
"The full class path of the source file.",
TYPE_STRING
),
CmdOption.new(
"-scl, --src_class_line",
"-scl <line_number>",
"The selected line number to generate test case.",
TYPE_INT
)
])

var _status := INIT
var _source_file :String = ""
var _source_line :int = -1


func _init() -> void:
var cmd_parser := CmdArgumentParser.new(_cmd_options, "GdUnitBuildTool.gd")
var result := cmd_parser.parse(OS.get_cmdline_args())
if result.is_error():
show_options()
exit(RETURN_ERROR, result.error_message());
return

var cmd_options :Array[CmdCommand] = result.value()
for cmd in cmd_options:
if cmd.name() == '-scp':
_source_file = cmd.arguments()[0]
_source_file = ProjectSettings.localize_path(ProjectSettings.localize_path(_source_file))
if cmd.name() == '-scl':
_source_line = int(cmd.arguments()[0])
# verify required arguments
if _source_file == "":
exit(RETURN_ERROR, "missing required argument -scp <source>")
return
if _source_line == -1:
exit(RETURN_ERROR, "missing required argument -scl <number>")
return
_status = PROCESSING


func _idle(_delta :float) -> void:
if _status == PROCESSING:
var script := ResourceLoader.load(_source_file) as Script
if script == null:
exit(RETURN_ERROR, "Can't load source file %s!" % _source_file)
var result := GdUnitTestSuiteBuilder.create(script, _source_line)
if result.is_error():
print_json_error(result.error_message())
exit(RETURN_ERROR, result.error_message())
return
_console.prints_color("Added testcase: %s" % result.value(), Color.CORNFLOWER_BLUE)
print_json_result(result.value() as Dictionary)
exit(RETURN_SUCCESS)


func exit(code :int, message :String = "") -> void:
_status = EXIT
if code == RETURN_ERROR:
if not message.is_empty():
_console.prints_error(message)
_console.prints_error("Abnormal exit with %d" % code)
else:
_console.prints_color("Exit code: %d" % RETURN_SUCCESS, Color.DARK_SALMON)
quit(code)


func print_json_result(result :Dictionary) -> void:
# convert back to system path
var path := ProjectSettings.globalize_path(result["path"] as String)
var json := 'JSON_RESULT:{"TestCases" : [{"line":%d, "path": "%s"}]}' % [result["line"], path]
prints(json)


func print_json_error(error :String) -> void:
prints('JSON_RESULT:{"Error" : "%s"}' % error)


func show_options() -> void:
_console.prints_color(" Usage:", Color.DARK_SALMON)
_console.prints_color(" build -scp <source_path> -scl <line_number>", Color.DARK_SALMON)
_console.prints_color("-- Options ---------------------------------------------------------------------------------------",
Color.DARK_SALMON).new_line()
for option in _cmd_options.default_options():
descripe_option(option)


func descripe_option(cmd_option :CmdOption) -> void:
_console.print_color(" %-40s" % str(cmd_option.commands()), Color.CORNFLOWER_BLUE)
_console.prints_color(cmd_option.description(), Color.LIGHT_GREEN)
if not cmd_option.help().is_empty():
_console.prints_color("%-4s %s" % ["", cmd_option.help()], Color.DARK_TURQUOISE)
_console.new_line()
1 change: 1 addition & 0 deletions harness/tests/addons/gdUnit4/bin/GdUnitBuildTool.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://dsgbf01bo6e4f
Loading
Loading