Skip to content
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

GD-607: Fix discovery of root test suites #604

Merged
merged 8 commits into from
Dec 10, 2024
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions addons/gdUnit4/src/core/GdUnitRunner.gd
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func _process(_delta :float) -> void:
if _client.is_client_connected():
var time := LocalTime.now()
prints("Scan for test suites.")
_test_suites_to_process = load_test_suits()
_test_suites_to_process = load_test_suites()
prints("Scanning of %d test suites took" % _test_suites_to_process.size(), time.elapsed_since())
gdUnitInit()
_state = RUN
Expand Down Expand Up @@ -95,7 +95,7 @@ func _process(_delta :float) -> void:
get_tree().quit(0)


func load_test_suits() -> Array[Node]:
func load_test_suites() -> Array[Node]:
var to_execute := _config.to_execute()
if to_execute.is_empty():
prints("No tests selected to execute!")
Expand Down
2 changes: 1 addition & 1 deletion addons/gdUnit4/src/core/GdUnitSettings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ static func migrate_property(old_property :String, new_property :String, default
ProjectSettings.set_initial_value(new_property, default_value)
set_help(new_property, value, help)
ProjectSettings.clear(old_property)
prints("Succesfull migrated property '%s' -> '%s' value: %s" % [old_property, new_property, value])
prints("Successfully migrated property '%s' -> '%s' value: %s" % [old_property, new_property, value])


static func dump_to_tmp() -> void:
Expand Down
12 changes: 9 additions & 3 deletions addons/gdUnit4/src/core/command/GdUnitCommandHandler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func cmd_run_test_case(test_suite_resource_path: String, test_case: String, test


func cmd_run_overall(debug: bool) -> void:
var test_suite_paths: PackedStringArray = GdUnitCommandHandler.scan_test_directorys("res://" , GdUnitSettings.test_root_folder(), [])
var test_suite_paths: PackedStringArray = GdUnitCommandHandler.scan_all_test_directories(GdUnitSettings.test_root_folder())
var result := _runner_config.clear()\
.add_test_suites(test_suite_paths)\
.save_config()
Expand Down Expand Up @@ -273,8 +273,14 @@ func cmd_create_test() -> void:
func cmd_discover_tests() -> void:
await GdUnitTestDiscoverer.run()

static func scan_all_test_directories(root: String) -> PackedStringArray:
var base_directory := "res://"
# If the test root folder is configured as blank, "/", or "res://", use the root folder as described in the settings panel
if root.is_empty() or root == "/" or root == base_directory:
esainane marked this conversation as resolved.
Show resolved Hide resolved
return [base_directory]
return scan_test_directories(base_directory, root, [])

static func scan_test_directorys(base_directory: String, test_directory: String, test_suite_paths: PackedStringArray) -> PackedStringArray:
static func scan_test_directories(base_directory: String, test_directory: String, test_suite_paths: PackedStringArray) -> PackedStringArray:
print_verbose("Scannning for test directory '%s' at %s" % [test_directory, base_directory])
for directory in DirAccess.get_directories_at(base_directory):
if directory.begins_with("."):
Expand All @@ -287,7 +293,7 @@ static func scan_test_directorys(base_directory: String, test_directory: String,
test_suite_paths.append(current_directory)
else:
@warning_ignore("return_value_discarded")
scan_test_directorys(current_directory, test_directory, test_suite_paths)
scan_test_directories(current_directory, test_directory, test_suite_paths)
return test_suite_paths


Expand Down
2 changes: 1 addition & 1 deletion addons/gdUnit4/src/core/discovery/GdUnitTestDiscoverer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static func run() -> void:
var t:= Thread.new()
@warning_ignore("return_value_discarded")
t.start(func () -> void:
var test_suite_directories :PackedStringArray = GdUnitCommandHandler.scan_test_directorys("res://" , GdUnitSettings.test_root_folder(), [])
var test_suite_directories :PackedStringArray = GdUnitCommandHandler.scan_all_test_directories(GdUnitSettings.test_root_folder())
var scanner := GdUnitTestSuiteScanner.new()
var _test_suites_to_process :Array[Node] = []

Expand Down
3 changes: 2 additions & 1 deletion addons/gdUnit4/src/ui/parts/InspectorTreeMainPanel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,8 @@ func create_tree_item(test_suite: GdUnitTestSuiteDto) -> TreeItem:
var elements := test_relative_path.split("/")
if elements[0] == "res://" or elements[0] == "":
elements.remove_at(0)
elements.remove_at(elements.size() - 1)
if elements.size() > 0:
elements.remove_at(elements.size() - 1)
for element in elements:
test_base_path += "/" + element
parent = create_or_find_item(parent, test_base_path, element)
Expand Down
29 changes: 23 additions & 6 deletions addons/gdUnit4/test/core/command/GdUnitCommandHandlerTest.gd
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,36 @@ func _test__check_test_run_stopped_manually() -> void:
verify(inspector, 1).cmd_stop(inspector._client_id)


func test_scan_test_directorys() -> void:
assert_array(GdUnitCommandHandler.scan_test_directorys("res://", "test", [])).contains_exactly([
func test_scan_test_directories() -> void:
assert_array(GdUnitCommandHandler.scan_test_directories("res://", "test", [])).contains_exactly([
"res://addons/gdUnit4/test"
])
# for root folders
assert_array(GdUnitCommandHandler.scan_test_directorys("res://", "", [])).contains_exactly([
assert_array(GdUnitCommandHandler.scan_test_directories("res://", "", [])).contains_exactly([
"res://addons", "res://assets", "res://gdUnit3-examples"
])
assert_array(GdUnitCommandHandler.scan_test_directorys("res://", "/", [])).contains_exactly([
assert_array(GdUnitCommandHandler.scan_test_directories("res://", "/", [])).contains_exactly([
"res://addons", "res://assets", "res://gdUnit3-examples"
])
assert_array(GdUnitCommandHandler.scan_test_directorys("res://", "res://", [])).contains_exactly([
assert_array(GdUnitCommandHandler.scan_test_directories("res://", "res://", [])).contains_exactly([
"res://addons", "res://assets", "res://gdUnit3-examples"
])
# a test folder not exists
assert_array(GdUnitCommandHandler.scan_test_directorys("res://", "notest", [])).is_empty()
assert_array(GdUnitCommandHandler.scan_test_directories("res://", "notest", [])).is_empty()


func test_scan_all_test_directories() -> void:
# Test when test_root_folder is empty
assert_array(GdUnitCommandHandler.scan_all_test_directories("")).contains_exactly(["res://"])

# Test when test_root_folder is "/"
assert_array(GdUnitCommandHandler.scan_all_test_directories("/")).contains_exactly(["res://"])

# Test when test_root_folder is "res://"
assert_array(GdUnitCommandHandler.scan_all_test_directories("res://")).contains_exactly(["res://"])

# Test when test_root_folder is set to a specific folder
assert_array(GdUnitCommandHandler.scan_all_test_directories("test")).contains_exactly(["res://addons/gdUnit4/test"])

# Test when test_root_folder is set to something which doesn't exist
assert_array(GdUnitCommandHandler.scan_all_test_directories("notest")).is_empty()
10 changes: 5 additions & 5 deletions addons/gdUnit4/test/ui/parts/resources/tree/tree_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -12530,7 +12530,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down Expand Up @@ -77439,7 +77439,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down Expand Up @@ -91204,7 +91204,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down Expand Up @@ -91440,7 +91440,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down Expand Up @@ -91823,7 +91823,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5770,7 +5770,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down Expand Up @@ -40771,7 +40771,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down Expand Up @@ -67760,7 +67760,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down Expand Up @@ -67996,7 +67996,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down Expand Up @@ -68379,7 +68379,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12530,7 +12530,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down Expand Up @@ -77439,7 +77439,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down Expand Up @@ -91204,7 +91204,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down Expand Up @@ -91440,7 +91440,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down Expand Up @@ -91823,7 +91823,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14111,7 +14111,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down Expand Up @@ -66602,7 +66602,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down Expand Up @@ -94261,7 +94261,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down Expand Up @@ -94497,7 +94497,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down Expand Up @@ -94710,7 +94710,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12530,7 +12530,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down Expand Up @@ -77439,7 +77439,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down Expand Up @@ -91204,7 +91204,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down Expand Up @@ -91440,7 +91440,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down Expand Up @@ -91823,7 +91823,7 @@
"disable_folding": false,
"metadata/__focus_rect": "[P: (471, 276), S: (100, 28)]",
"metadata/gdUnit_execution_time": 21,
"metadata/gdUnit_name": "test_scan_test_directorys",
"metadata/gdUnit_name": "test_scan_test_directories",
"metadata/gdUnit_state": 2,
"metadata/gdUnit_suite_success_tests": 0,
"metadata/gdUnit_suite_total_tests": 0,
Expand Down