-
Notifications
You must be signed in to change notification settings - Fork 90
Add GaeaNodeResource tests
#400
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
c5d0cbc
Add warning check
BenjaTK 24c84ce
Add to workflow
BenjaTK 5014cb0
Move into subfolder
BenjaTK a77e8e2
Update gd-unit.yml
BenjaTK cb853f8
Separate workflows
BenjaTK 7d547aa
Add unnamed test
BenjaTK a1a465d
Merge tests into one script
BenjaTK b10f409
Add type and output checks
BenjaTK 517f8a6
Add description check
BenjaTK 3d98461
Rename script
BenjaTK c8365a3
Add scene check
BenjaTK 9a8f8ee
Add comment to scene test
BenjaTK ebd4325
Remove GdUnitRunner.cfg
BenjaTK 1d9738e
Fix failure messages
BenjaTK 33f5aa1
Add script compilation and tool testing
BenjaTK 10805ab
Add empty check to unnamed.
BenjaTK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| name: GHA | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths-ignore: | ||
| - '**.yml' | ||
| - '**.md' | ||
| workflow_dispatch: | ||
|
|
||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}|${{ github.ref_name }} | ||
| cancel-in-progress: true | ||
|
|
||
|
|
||
| jobs: | ||
| warning_check: | ||
| name: "Node Testing" | ||
| runs-on: 'ubuntu-22.04' | ||
| timeout-minutes: 10 # The overall timeout | ||
| permissions: | ||
| actions: write | ||
| checks: write | ||
| contents: write | ||
| pull-requests: write | ||
| statuses: write | ||
|
|
||
| steps: | ||
| # checkout your repository | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| lfs: true | ||
| # run tests by using the gdUnit4-action with Godot version 4.2.1 and the latest GdUnit4 release | ||
| - uses: MikeSchulze/gdUnit4-action@v1.1.6 | ||
| with: | ||
| godot-version: '4.4.1' | ||
| paths: | | ||
| res://testing/graph_nodes | ||
| timeout: 5 | ||
| publish-report: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,3 +18,5 @@ scenes/test/* | |
|
|
||
| # Editor-specific ignores | ||
| .vscode/* | ||
|
|
||
| GdUnitRunner.cfg | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| class_name GenerateTest | ||
| extends GdUnitTestSuite | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| extends GdUnitTestSuite | ||
|
|
||
|
|
||
| const NODES_PATH := "res://addons/gaea/graph/graph_nodes/root/" | ||
|
|
||
| var nodes_in_root: Array[GaeaNodeResource] | ||
|
|
||
|
|
||
|
|
||
|
|
||
| func _get_nodes_in_folder(folder_path: String) -> Array[GaeaNodeResource]: | ||
| var dir := DirAccess.open(folder_path) | ||
| var array: Array[GaeaNodeResource] = [] | ||
|
|
||
| dir.list_dir_begin() | ||
| var file_name := dir.get_next() | ||
| while file_name != "": | ||
| if not dir.current_is_dir() and not file_name.ends_with(".gd"): | ||
| file_name = dir.get_next() | ||
| continue | ||
|
|
||
| var file_path = folder_path + file_name | ||
| if dir.current_is_dir(): | ||
| array.append_array(_get_nodes_in_folder(file_path + "/")) | ||
|
|
||
| if file_name.ends_with(".gd"): | ||
| var script := load(file_path) | ||
| assert_bool(script.can_instantiate())\ | ||
| .override_failure_message("Script at [b]%s[/b] couldn't compile." % _get_node_path(script))\ | ||
| .is_true() | ||
|
|
||
| assert_bool(script.is_tool())\ | ||
| .override_failure_message("Script at [b]%s[/b] isn't a tool script." % _get_node_path(script))\ | ||
| .is_true() | ||
|
|
||
| if script is GDScript and script.is_tool(): | ||
| var is_valid_node_resource := false | ||
| var base_script: GDScript = script | ||
| while is_instance_valid(base_script): | ||
| base_script = base_script.get_base_script() | ||
| if base_script == GaeaNodeResource: | ||
| is_valid_node_resource = true | ||
| break | ||
| if is_valid_node_resource: | ||
| var resource: GaeaNodeResource = script.new() | ||
| if resource.is_available(): | ||
| for item in resource.get_tree_items(): | ||
| array.append(item) | ||
| file_name = dir.get_next() | ||
|
|
||
| return array | ||
|
|
||
|
|
||
| func _get_node_path(object: Object) -> String: | ||
| if object is Script: | ||
| return object.resource_path.trim_prefix(NODES_PATH) | ||
| return object.get_script().resource_path.trim_prefix(NODES_PATH) | ||
|
|
||
|
|
||
| ## Tests that all nodes' scripts can be instantiated and are tool. | ||
| ## Also populates the [member nodes_in_root] array. | ||
| func test_script_compilation() -> void: | ||
| nodes_in_root = _get_nodes_in_folder(NODES_PATH) | ||
|
|
||
|
|
||
| ## Tests that no `GaeaNodeResource`s in the root push the `_get_arguments_list` warning. | ||
| func test_is_arguments_list_overriden() -> void: | ||
| for node in nodes_in_root: | ||
| await assert_failure_await(func(): assert_error(node.get_arguments_list)\ | ||
| .is_push_warning(("_get_arguments_list wasn't overridden in %s, node will have no arguments." % node.get_script().resource_path)) | ||
| ) | ||
|
|
||
| ## Tests that no `GaeaNodeResource`s in the root are unnamed. | ||
| func test_for_untitled() -> void: | ||
| for node in nodes_in_root: | ||
| await assert_str(node.get_title())\ | ||
| .override_failure_message("Node at [b]%s[/b] is unnamed" % _get_node_path(node))\ | ||
| .is_not_equal("Unnamed").is_not_equal("") | ||
|
|
||
| ## Tests that all nodes have outputs. | ||
| func test_has_outputs() -> void: | ||
| for node in nodes_in_root: | ||
| assert_array(node.get_output_ports_list())\ | ||
| .override_failure_message("Node at [b]%s[/b] has no outputs." % _get_node_path(node))\ | ||
| .is_not_empty() | ||
|
|
||
|
|
||
| ## Tests that no `GaeaNodeResource`s in the root have an invalid or null type. | ||
| func test_null_type() -> void: | ||
| for node in nodes_in_root: | ||
| await assert_int(node.get_type())\ | ||
| .override_failure_message("Type of node at [b]%s[/b] is not a valid type." % _get_node_path(node))\ | ||
| .is_in(GaeaValue.Type.values())\ | ||
| .override_failure_message("Type of node at [b]%s[/b] is null." % _get_node_path(node))\ | ||
| .is_not_equal(GaeaValue.Type.NULL) | ||
| for argument in node.get_arguments_list(): | ||
| await assert_int(node.get_argument_type(argument))\ | ||
| .override_failure_message("Type of argument [b]%s[/b] is invalid." % argument)\ | ||
| .append_failure_message("Node at [b]%s[/b]." % _get_node_path(node))\ | ||
| .is_in(GaeaValue.Type.values())\ | ||
| .override_failure_message("Type of argument [b]%s[/b] is null." % argument)\ | ||
| .append_failure_message("Node at [b]%s[/b]." % _get_node_path(node))\ | ||
| .is_not_equal(GaeaValue.Type.NULL) | ||
| for output in node.get_output_ports_list(): | ||
| await assert_int(node.get_output_port_type(output))\ | ||
| .override_failure_message("Type of output [b]%s[/b] is invalid." % output)\ | ||
| .append_failure_message("Node at [b]%s[/b]." % _get_node_path(node))\ | ||
| .is_in(GaeaValue.Type.values())\ | ||
| .override_failure_message("Type of output [b]%s[/b] is null." % output)\ | ||
| .append_failure_message("Node at [b]%s[/b]." % _get_node_path(node))\ | ||
| .is_not_equal(GaeaValue.Type.NULL) | ||
|
|
||
|
|
||
| ## Check that all nodes have descriptions. | ||
| func test_has_description() -> void: | ||
| for node in nodes_in_root: | ||
| await assert_str(node.get_description())\ | ||
| .override_failure_message("Description of node at [b]%s[/b] is empty." % _get_node_path(node))\ | ||
| .is_not_empty() | ||
|
|
||
|
|
||
| ## Check that all nodes have a valid scene. | ||
| func test_node_scene() -> void: | ||
| for node in nodes_in_root: | ||
| await assert_object(node.get_scene())\ | ||
BenjaTK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .override_failure_message("_get_scene at [b]%s[/b] returns null." % _get_node_path(node))\ | ||
| .is_not_null()\ | ||
| .override_failure_message("_get_scene at [b]%s[/b] isn't a PackedScene." % _get_node_path(node))\ | ||
| .is_instanceof(PackedScene) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| uid://irnmsmbitacb |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.