Skip to content

Commit

Permalink
GD-146: Add shortcut support to run/debug/create tests (#148)
Browse files Browse the repository at this point in the history
# Why
Some users want to use shortcuts instead of using context menues

# What
Added os specific shortcuts:
**Windows**:
  CTRL+F5 - ReRun Tests
  CTRL+F6 - ReRun Tests (Debug)
  CTRL+F7 - Run overall Tests
  CTRL+F8 - Stop test execution

  CTRL+ALT+F5 - Run Testcase
  CTRL+ALT+F6 - Debug Testcase
  CTRL+ALT+F10 - Create Testcase
  **MacOs**:
  COMMAND+F5 - ReRun Tests
  COMMAND+F6 - ReRun Tests (Debug)
  COMMAND+F7 - Run overall Tests
  COMMAND+F8 - Stop test execution

  COMMAND+ALT+F5 - Run Testcase
  COMMAND+ALT+F6 - Debug Testcase
  COMMAND+ALT+F10 - Create Testcase


  Added new settings to configure shortcuts

![image](https://user-images.githubusercontent.com/347037/227728029-7db56238-97de-4458-ab1f-69048e93126c.png)
  • Loading branch information
MikeSchulze authored Mar 25, 2023
1 parent 1b803c0 commit 41813b2
Show file tree
Hide file tree
Showing 24 changed files with 711 additions and 142 deletions.
3 changes: 1 addition & 2 deletions addons/gdUnit4/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ func _exit_tree():
if is_instance_valid(_server_node):
remove_child(_server_node)
_server_node.free()
GdUnitTools.dispose_all()
if Engine.has_meta("GdUnitEditorPlugin"):
Engine.remove_meta("GdUnitEditorPlugin")
prints("Unload GdUnit4 Plugin success")
GdUnitSignals.dispose()
GdUnitSingleton.dispose()
14 changes: 7 additions & 7 deletions addons/gdUnit4/src/core/GdObjects.gd
Original file line number Diff line number Diff line change
Expand Up @@ -713,25 +713,25 @@ static func array_erase_value(array :Array, value) -> void:
array.erase(element)


static func find_nodes_by_class(root: Node, cls: String, recursive: bool = false) -> Array:
static func find_nodes_by_class(root: Node, cls: String, recursive: bool = false) -> Array[Node]:
if not recursive:
return _find_nodes_by_class_no_rec(root, cls)
return _find_nodes_by_class(root, cls)


static func _find_nodes_by_class_no_rec(parent: Node, cls: String) -> Array:
var result = []
static func _find_nodes_by_class_no_rec(parent: Node, cls: String) -> Array[Node]:
var result :Array[Node] = []
for ch in parent.get_children():
if ch.get_class() == cls:
result.append(ch)
return result


static func _find_nodes_by_class(root: Node, cls: String) -> Array:
var result = []
var stack = [root]
static func _find_nodes_by_class(root: Node, cls: String) -> Array[Node]:
var result :Array[Node] = []
var stack :Array[Node] = [root]
while stack:
var node = stack.pop_back()
var node :Node = stack.pop_back()
if node.get_class() == cls:
result.append(node)
for ch in node.get_children():
Expand Down
4 changes: 3 additions & 1 deletion addons/gdUnit4/src/core/GdUnitProperty.gd
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func is_selectable_value() -> bool:
return not _value_set.is_empty()


func set_value(p_value) -> void:
func set_value(p_value :Variant) -> void:
match _type:
TYPE_STRING:
_value = str(p_value)
Expand All @@ -48,6 +48,8 @@ func set_value(p_value) -> void:
_value = int(p_value)
TYPE_FLOAT:
_value = float(p_value)
_:
_value = p_value


func default():
Expand Down
43 changes: 39 additions & 4 deletions addons/gdUnit4/src/core/GdUnitSettings.gd
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,30 @@ const TEMPLATE_TS_GD = TEMPLATES_TS + "/GDScript"
const TEMPLATE_TS_CS = TEMPLATES_TS + "/CSharpScript"



# UI Setiings
const UI_SETTINGS = MAIN_CATEGORY + "/ui"
const GROUP_UI_INSPECTOR = UI_SETTINGS + "/inspector"
const INSPECTOR_NODE_COLLAPSE = GROUP_UI_INSPECTOR + "/node_collapse"


# Shortcut Setiings
const SHORTCUT_SETTINGS = MAIN_CATEGORY + "/Shortcuts"
const GROUP_SHORTCUT_INSPECTOR = SHORTCUT_SETTINGS + "/inspector"
const SHORTCUT_INSPECTOR_RERUN_TEST = GROUP_SHORTCUT_INSPECTOR + "/rerun_test"
const SHORTCUT_INSPECTOR_RERUN_TEST_DEBUG = GROUP_SHORTCUT_INSPECTOR + "/rerun_test_debug"
const SHORTCUT_INSPECTOR_RUN_TEST_OVERALL = GROUP_SHORTCUT_INSPECTOR + "/run_test_overall"
const SHORTCUT_INSPECTOR_RUN_TEST_STOP = GROUP_SHORTCUT_INSPECTOR + "/run_test_stop"

const GROUP_SHORTCUT_EDITOR = SHORTCUT_SETTINGS + "/editor"
const SHORTCUT_EDITOR_RUN_TEST = GROUP_SHORTCUT_EDITOR + "/run_test"
const SHORTCUT_EDITOR_RUN_TEST_DEBUG = GROUP_SHORTCUT_EDITOR + "/run_test_debug"
const SHORTCUT_EDITOR_CREATE_TEST = GROUP_SHORTCUT_EDITOR + "/create_test"

const GROUP_SHORTCUT_FILESYSTEM = SHORTCUT_SETTINGS + "/filesystem"
const SHORTCUT_FILESYSTEM_RUN_TEST = GROUP_SHORTCUT_FILESYSTEM + "/run_test"
const SHORTCUT_FILESYSTEM_RUN_TEST_DEBUG = GROUP_SHORTCUT_FILESYSTEM + "/run_test_debug"


# Toolbar Setiings
const GROUP_UI_TOOLBAR = UI_SETTINGS + "/toolbar"
const INSPECTOR_TOOLBAR_BUTTON_RUN_OVERALL = GROUP_UI_TOOLBAR + "/run_overall"
Expand Down Expand Up @@ -80,6 +98,22 @@ static func setup():
create_property_if_need(INSPECTOR_NODE_COLLAPSE, true, "Enables/Disables that the testsuite node is closed after a successful test run.")
create_property_if_need(INSPECTOR_TOOLBAR_BUTTON_RUN_OVERALL, false, "Shows/Hides the 'Run overall Tests' button in the inspector toolbar.")
create_property_if_need(TEMPLATE_TS_GD, GdUnitTestSuiteTemplate.default_GD_template(), "Defines the test suite template")
create_shortcut_properties_if_need()


static func create_shortcut_properties_if_need() -> void:
# inspector
create_property_if_need(SHORTCUT_INSPECTOR_RERUN_TEST, GdUnitShortcut.default_keys(GdUnitShortcut.ShortCut.RERUN_TESTS), "Rerun of the last tests performed.")
create_property_if_need(SHORTCUT_INSPECTOR_RERUN_TEST_DEBUG, GdUnitShortcut.default_keys(GdUnitShortcut.ShortCut.RERUN_TESTS_DEBUG), "Rerun of the last tests performed (Debug).")
create_property_if_need(SHORTCUT_INSPECTOR_RUN_TEST_OVERALL, GdUnitShortcut.default_keys(GdUnitShortcut.ShortCut.RUN_TESTS_OVERALL), "Runs all tests (Debug).")
create_property_if_need(SHORTCUT_INSPECTOR_RUN_TEST_STOP, GdUnitShortcut.default_keys(GdUnitShortcut.ShortCut.STOP_TEST_RUN), "Stops the current test execution.")
# script editor
create_property_if_need(SHORTCUT_EDITOR_RUN_TEST, GdUnitShortcut.default_keys(GdUnitShortcut.ShortCut.RUN_TESTCASE), "Runs the currently selected test.")
create_property_if_need(SHORTCUT_EDITOR_RUN_TEST_DEBUG, GdUnitShortcut.default_keys(GdUnitShortcut.ShortCut.RUN_TESTCASE_DEBUG), "Runs the currently selected test (Debug).")
create_property_if_need(SHORTCUT_EDITOR_CREATE_TEST, GdUnitShortcut.default_keys(GdUnitShortcut.ShortCut.CREATE_TEST), "Creates a new test case for the currently selected function.")
# filesystem
create_property_if_need(SHORTCUT_FILESYSTEM_RUN_TEST, GdUnitShortcut.default_keys(GdUnitShortcut.ShortCut.NONE), "Runs all test suites on the selected folder or file.")
create_property_if_need(SHORTCUT_FILESYSTEM_RUN_TEST_DEBUG, GdUnitShortcut.default_keys(GdUnitShortcut.ShortCut.NONE), "Runs all test suites on the selected folder or file (Debug).")


static func create_property_if_need(name :String, default :Variant, help :="", value_set := PackedStringArray()) -> void:
Expand Down Expand Up @@ -200,9 +234,10 @@ static func extract_value_set_from_help(value :String) -> PackedStringArray:


static func update_property(property :GdUnitProperty) -> void:
ProjectSettings.set_setting(property.name(), property.value())
GdUnitSignals.instance().gdunit_settings_changed.emit(property)
save()
if get_property(property.name()).value() != property.value():
ProjectSettings.set_setting(property.name(), property.value())
GdUnitSignals.instance().gdunit_settings_changed.emit(property)
save()


static func reset_property(property :GdUnitProperty) -> void:
Expand Down
5 changes: 5 additions & 0 deletions addons/gdUnit4/src/core/GdUnitSignals.gd
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ static func instance() -> GdUnitSignals:


static func dispose() -> void:
var signals := instance()
# cleanup connected signals
for signal_ in signals.get_signal_list():
for connection in signals.get_signal_connection_list(signal_["name"]):
connection["signal"].disconnect(connection["callable"])
Engine.remove_meta(META_KEY)
41 changes: 41 additions & 0 deletions addons/gdUnit4/src/core/command/GdUnitCommand.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
class_name GdUnitCommand
extends RefCounted


func _init(p_name :String, p_is_enabled: Callable, p_runnable: Callable, p_shortcut :GdUnitShortcut.ShortCut = GdUnitShortcut.ShortCut.NONE):
assert(p_name != null, "(%s) missing parameter 'name'" % p_name)
assert(p_is_enabled != null, "(%s) missing parameter 'is_enabled'" % p_name)
assert(p_runnable != null, "(%s) missing parameter 'runnable'" % p_name)
assert(p_shortcut != null, "(%s) missing parameter 'shortcut'" % p_name)
self.name = p_name
self.is_enabled = p_is_enabled
self.shortcut = p_shortcut
self.runnable = p_runnable


var name: String:
set(value):
name = value
get:
return name


var shortcut: GdUnitShortcut.ShortCut:
set(value):
shortcut = value
get:
return shortcut


var is_enabled: Callable:
set(value):
is_enabled = value
get:
return is_enabled


var runnable: Callable:
set(value):
runnable = value
get:
return runnable
Loading

0 comments on commit 41813b2

Please sign in to comment.