Skip to content

Commit

Permalink
GD-259: Respect the configured test folder to scan for overall test (#…
Browse files Browse the repository at this point in the history
…261)

# Why
The test folder under settings was not used to check which folders are
included scan for the overall tests.


# What
- exclude gdunit source folders from test scanning
- use configured test folder to scan overall tests
- allow to define root folder for tests by using "/" or "res://" or
empty
  • Loading branch information
Nullpointer committed Sep 20, 2023
1 parent 16ee0f1 commit 51dc812
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 30 deletions.
10 changes: 10 additions & 0 deletions addons/gdUnit4/src/core/GdUnitTestSuiteScanner.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ func test_${func_name}() -> void:
assert_not_yet_implemented()
"""


# we exclude the gdunit source directorys by default
const exclude_scan_directories = [
"res://addons/gdUnit4/bin",
"res://addons/gdUnit4/src",
"res://reports"]


var _script_parser := GdScriptParser.new()
var _extends_test_suite_classes := Array()
var _expression_runner := GdUnitExpressionRunner.new()
Expand Down Expand Up @@ -39,6 +47,8 @@ func scan(resource_path :String) -> Array[Node]:


func _scan_test_suites(dir :DirAccess, collected_suites :Array[Node]) -> Array[Node]:
if exclude_scan_directories.has(dir.get_current_dir()):
return collected_suites
prints("Scanning for test suites in:", dir.get_current_dir())
dir.list_dir_begin() # TODOGODOT4 fill missing arguments https://github.com/godotengine/godot/pull/40547
var file_name := dir.get_next()
Expand Down
24 changes: 17 additions & 7 deletions addons/gdUnit4/src/core/command/GdUnitCommandHandler.gd
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,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://", [])
var test_suite_paths :PackedStringArray = GdUnitCommandHandler.scan_test_directorys("res://" , GdUnitSettings.test_root_folder(), [])
var result := _runner_config.clear()\
.add_test_suites(test_suite_paths)\
.save_config()
Expand Down Expand Up @@ -261,20 +261,30 @@ func cmd_create_test() -> void:
ScriptEditorControls.edit_script(info.get("path"), info.get("line"))


static func scan_test_directorys(base_directory :String, test_suite_paths :PackedStringArray) -> PackedStringArray:
prints("Scannning for test directories", base_directory)
static func scan_test_directorys(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("."):
continue
var current_directory := base_directory + "/" + directory
if directory == "test":
prints(".. ", current_directory)
var current_directory := normalize_path(base_directory + "/" + directory)
if GdUnitTestSuiteScanner.exclude_scan_directories.has(current_directory):
continue
if match_test_directory(directory, test_directory):
prints("Collect tests at:", current_directory)
test_suite_paths.append(current_directory)
else:
scan_test_directorys(current_directory, test_suite_paths)
scan_test_directorys(current_directory, test_directory, test_suite_paths)
return test_suite_paths


static func normalize_path(path :String) -> String:
return path.replace("///", "//")


static func match_test_directory(directory :String, test_directory: String) -> bool:
return directory == test_directory or test_directory.is_empty() or test_directory == "/" or test_directory == "res://"


func run_debug_mode():
_editor_interface.play_custom_scene("res://addons/gdUnit4/src/core/GdUnitRunner.tscn")
_is_running = true
Expand Down
21 changes: 0 additions & 21 deletions addons/gdUnit4/test/core/GdUnitCommandHandlerTest.gd

This file was deleted.

33 changes: 33 additions & 0 deletions addons/gdUnit4/test/core/command/GdUnitCommandHandlerTest.gd
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,36 @@ func test_create_shortcuts_defaults(shortcut :GdUnitShortcut.ShortCut, expected
var action := _handler.get_shortcut_action(shortcut)
assert_that(str(action)).is_equal(expected)
func test__check_test_run_stopped_manually() -> void:
var inspector :GdUnitCommandHandler = mock(GdUnitCommandHandler, CALL_REAL_FUNC)
inspector._client_id = 1
# simulate no test is running
do_return(false).on(inspector).is_test_running_but_stop_pressed()
inspector.check_test_run_stopped_manually()
verify(inspector, 0).cmd_stop(any_int())
# simulate the test runner was manually stopped by the editor
do_return(true).on(inspector).is_test_running_but_stop_pressed()
inspector.check_test_run_stopped_manually()
verify(inspector, 1).cmd_stop(inspector._client_id)
func test_scan_test_directorys() -> void:
assert_array(GdUnitCommandHandler.scan_test_directorys("res://", "test", [])).contains_exactly([
"res://addons/gdUnit4/test"
])
# for root folders
assert_array(GdUnitCommandHandler.scan_test_directorys("res://", "", [])).contains_exactly([
"res://addons", "res://assets", "res://gdUnit3-examples"
])
assert_array(GdUnitCommandHandler.scan_test_directorys("res://", "/", [])).contains_exactly([
"res://addons", "res://assets", "res://gdUnit3-examples"
])
assert_array(GdUnitCommandHandler.scan_test_directorys("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()
3 changes: 1 addition & 2 deletions project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ config_version=5
[application]

config/name="gdUnit4"
config/tags=PackedStringArray("addon", "godot4", "testing")
config/features=PackedStringArray("4.1")
config/icon="res://icon.png"

Expand All @@ -31,8 +32,6 @@ enabled=PackedStringArray("res://addons/gdUnit4/plugin.cfg")
[gdunit4]

settings/common/update_notification_enabled=false
report/assert/verbose_errors=false
report/assert/verbose_warnings=false

[importer_defaults]

Expand Down

0 comments on commit 51dc812

Please sign in to comment.