Skip to content
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions trimsock.gd/addons/vest/_generated-mixins/1-8182042.gd
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,18 @@ func _get_suite() -> VestDefs.Suite:
await call(method["name"])

for method in case_methods:
test(method["name"].trim_prefix("test").capitalize(), func(): await call(method["name"]))
var method_name := method["name"] as String
var test_name := method_name.trim_prefix("test").trim_suffix("__only").capitalize()
var callback := func(): await call(method["name"])
var is_only := _is_only(method_name)

test(test_name, callback, is_only, method_name)

for method in parametric_methods:
var method_name := method["name"] as String
var test_name := method_name.trim_prefix("test").trim_suffix("__only").capitalize()
var is_only := _is_only(method_name)

var param_provider_name := method["default_args"][0] as String
if not has_method(param_provider_name):
push_warning(
Expand All @@ -80,7 +89,12 @@ func _get_suite() -> VestDefs.Suite:

for i in range(params.size()):
test(
"%s#%d %s" % [method["name"].trim_prefix("test").capitalize(), i+1, params[i]],
func(): await callv(method["name"], params[i])
"%s#%d %s" % [test_name, i+1, params[i]],
func(): await callv(method["name"], params[i]),
is_only,
method_name
)
)

func _is_only(name: String) -> bool:
return name.ends_with("__only")
2 changes: 1 addition & 1 deletion trimsock.gd/addons/vest/_generated-mixins/1-8182042.gd.uid
Original file line number Diff line number Diff line change
@@ -1 +1 @@
uid://cg53q8t5aibti
uid://mm20mdmsc5ii
Original file line number Diff line number Diff line change
@@ -1 +1 @@
uid://d168ndvsqupun
uid://caf7owv25i7op
Original file line number Diff line number Diff line change
@@ -1 +1 @@
uid://8ojcq7eq3de3
uid://d3mmot6r5ycm6
Original file line number Diff line number Diff line change
@@ -1 +1 @@
uid://hlpirirrosh8
uid://v3npn3goh4em
Original file line number Diff line number Diff line change
@@ -1 +1 @@
uid://hgh0houeje1w
uid://c8oa5ooaqwi11
Original file line number Diff line number Diff line change
@@ -1 +1 @@
uid://bki88xn3pwurs
uid://dqqt1ecooeqdd
93 changes: 93 additions & 0 deletions trimsock.gd/addons/vest/cli/vest-cli-runner.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
extends RefCounted
class_name VestCLIRunner

## Implements functionality to run tests

var _peer: StreamPeerTCP = null

## Run tests with [Params]
func run(params: VestCLI.Params) -> int:
var validation_errors := params.validate()
if not validation_errors.is_empty():
for error in validation_errors:
OS.alert(error)
push_error(error)
return 1

await _connect(params)

var results := await _run_tests(params)
_report(params, results)
_send_results_over_network(params, results)

_disconnect()

if results.get_aggregate_status() == VestResult.TEST_PASS:
print_rich("All tests [color=green]passed[/color]!")
return 0
else:
print_rich("There are test [color=red]failures[/color]!")
return 1

func _run_tests(params: VestCLI.Params) -> VestResult.Suite:
var runner := VestLocalRunner.new()
runner.on_partial_result.connect(func(result: VestResult.Suite):
if _peer != null:
if result != null:
_peer.put_var(result._to_wire(), true)
else:
_peer.put_var(result, true)
)

var results: VestResult.Suite
if params.run_file:
results = await runner.run_script_at(params.run_file, params.only_mode)
elif params.run_glob:
results = await runner.run_glob(params.run_glob, params.only_mode)

return results

func _report(params: VestCLI.Params, results: VestResult.Suite):
var report := TAPReporter.report(results)

if params.report_format:
if params.report_file in ["", "-"]:
print(report)
else:
var fa := FileAccess.open(params.report_file, FileAccess.WRITE)
fa.store_string(report)
fa.close()

func _connect(params: VestCLI.Params):
if not params.host and params.port == -1:
return

var host := params.host
var port := params.port

if not host: host = "0.0.0.0"
if port == -1: port = 54932

var peer := StreamPeerTCP.new()
var err := peer.connect_to_host(host, port)
if err != OK:
push_warning("Couldn't connect on port %d! %s" % [port, error_string(err)])
return

await Vest.until(func(): peer.poll(); return peer.get_status() != StreamPeerTCP.STATUS_CONNECTING)
if peer.get_status() != StreamPeerTCP.STATUS_CONNECTED:
push_warning("Connection failed! Socket status: %d" % [peer.get_status()])
return

peer.set_no_delay(true)
_peer = peer

func _disconnect():
if _peer != null:
_peer.disconnect_from_host()

func _send_results_over_network(params: VestCLI.Params, results: VestResult.Suite):
if not _peer:
return

_peer.put_var(results._to_wire(), true)
1 change: 1 addition & 0 deletions trimsock.gd/addons/vest/cli/vest-cli-runner.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://bw0ajf5t50wi0
4 changes: 3 additions & 1 deletion trimsock.gd/addons/vest/cli/vest-cli-scene.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
[sub_resource type="GDScript" id="GDScript_de1pc"]
script/source = "extends Node

# Used to run tests in debug mode

func _ready():
Vest._register_scene_tree(get_tree())
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_MINIMIZED)

var params := Vest.__.LocalSettings.run_params

var runner := VestCLI.Runner.new()
var runner := VestCLIRunner.new()
var exit_code := await runner.run(params)

get_tree().quit(exit_code)
Expand Down
82 changes: 12 additions & 70 deletions trimsock.gd/addons/vest/cli/vest-cli.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class Params:
## Path for saving the report
var report_file: String = ""

## How to handle tests marked as `only`
var only_mode: int = Vest.__.ONLY_DISABLED

## Host to connect to for sending results
var host: String = ""

Expand Down Expand Up @@ -50,6 +53,11 @@ class Params:
if host: result.append_array(["--vest-host", host])
if port != -1: result.append_array(["--vest-port", str(port)])

match only_mode:
Vest.__.ONLY_DISABLED: result.append("--no-only")
Vest.__.ONLY_AUTO: result.append("--auto-only")
Vest.__.ONLY_ENABLED: result.append("--only")

return result

## Parse an array of CLI parameters.
Expand All @@ -68,78 +76,12 @@ class Params:
elif arg == "--vest-report-format": result.report_format = val
elif arg == "--vest-port": result.port = val.to_int()
elif arg == "--vest-host": result.host = val
elif arg == "--no-only": result.only_mode = Vest.__.ONLY_DISABLED
elif arg == "--only": result.only_mode = Vest.__.ONLY_ENABLED
elif arg == "--auto-only": result.only_mode = Vest.__.ONLY_AUTO

return result

## Implements functionality to run tests
class Runner:
## Run tests with [Params]
func run(params: Params) -> int:
var validation_errors := params.validate()
if not validation_errors.is_empty():
for error in validation_errors:
OS.alert(error)
push_error(error)
return 1

var results := await _run_tests(params)
_report(params, results)
await _send_results_over_network(params, results)

if results.get_aggregate_status() == VestResult.TEST_PASS:
print_rich("All tests [color=green]passed[/color]!")
return 0
else:
print_rich("There are test [color=red]failures[/color]!")
return 1

func _run_tests(params: Params) -> VestResult.Suite:
var runner := VestLocalRunner.new()

var results: VestResult.Suite
if params.run_file:
results = await runner.run_script_at(params.run_file)
elif params.run_glob:
results = await runner.run_glob(params.run_glob)

return results

func _report(params: Params, results: VestResult.Suite):
var report := TAPReporter.report(results)

if params.report_format:
if params.report_file in ["", "-"]:
print(report)
else:
var fa := FileAccess.open(params.report_file, FileAccess.WRITE)
fa.store_string(report)
fa.close()

func _send_results_over_network(params: Params, results: VestResult.Suite):
if not params.host and params.port == -1:
return

var host := params.host
var port := params.port

if not host: host = "0.0.0.0"
if port == -1: port = 54932

var peer := StreamPeerTCP.new()
var err := peer.connect_to_host(host, port)
if err != OK:
push_warning("Couldn't connect on port %d! %s" % [port, error_string(err)])
return

await Vest.until(func(): peer.poll(); return peer.get_status() != StreamPeerTCP.STATUS_CONNECTING)
if peer.get_status() != StreamPeerTCP.STATUS_CONNECTED:
push_warning("Connection failed! Socket status: %d" % [peer.get_status()])
return

peer.put_var(results._to_wire(), true)
peer.disconnect_from_host()


## Run vest CLI with parameters.
## [br][br]
## Returns the spawned process' ID.
Expand All @@ -161,7 +103,7 @@ func _init():
await process_frame

var params := Params.parse(OS.get_cmdline_args())
var runner := Runner.new()
var runner := VestCLIRunner.new()

var exit_code := await runner.run(params)

Expand Down
20 changes: 4 additions & 16 deletions trimsock.gd/addons/vest/commands/run-test-command.gd
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
@tool
extends Node

static var _instance = null

static func find():
return _instance

static func execute() -> void:
if _instance:
_instance.create_test()
else:
push_warning("No instance of Create Test command found!")

func run_test():
_run(false)
_run(false, Vest.__.ONLY_AUTO)

func debug_test():
_run(true)
_run(true, Vest.__.ONLY_AUTO)

func _run(is_debug: bool) -> void:
func _run(is_debug: bool, only_mode: int) -> void:
var editor_interface := Vest._get_editor_interface()
var script_editor := editor_interface.get_script_editor() as ScriptEditor

Expand All @@ -34,7 +23,7 @@ func _run(is_debug: bool) -> void:

print_verbose("Running test \"%s\"" % [edited_script.resource_path])
var vest_ui := VestUI._get_ui()
vest_ui.run_script(edited_script, is_debug)
vest_ui.run_script(edited_script, is_debug, only_mode)

func _is_ancestor_of(base_script: Script, script: Script) -> bool:
for i in range(128): # Prevent runaway loops
Expand All @@ -45,7 +34,6 @@ func _is_ancestor_of(base_script: Script, script: Script) -> bool:
return false

func _ready():
_instance = self
var editor := Vest._get_editor_interface()
editor.get_command_palette().add_command("Run test", "vest/run-test", run_test, "F7")
editor.get_command_palette().add_command("Debug test", "vest/debug-test", debug_test, "Ctrl+F7")
Expand Down
5 changes: 3 additions & 2 deletions trimsock.gd/addons/vest/icons/benchmark-fail.svg.import
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type="CompressedTexture2D"
uid="uid://c1cdr1khuiy2f"
path="res://.godot/imported/benchmark-fail.svg-b20a3c22c391ea7bcebd7f59f83ca9d5.ctex"
metadata={
"has_editor_variant": true,
"vram_texture": false
}

Expand Down Expand Up @@ -33,5 +34,5 @@ process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=2.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
editor/scale_with_editor_scale=true
editor/convert_colors_with_editor_theme=true
5 changes: 3 additions & 2 deletions trimsock.gd/addons/vest/icons/benchmark-pass.svg.import
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type="CompressedTexture2D"
uid="uid://bt8iem8l0pq4s"
path="res://.godot/imported/benchmark-pass.svg-7479ef55a95006e5fb1a614e003877eb.ctex"
metadata={
"has_editor_variant": true,
"vram_texture": false
}

Expand Down Expand Up @@ -33,5 +34,5 @@ process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=2.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
editor/scale_with_editor_scale=true
editor/convert_colors_with_editor_theme=true
5 changes: 3 additions & 2 deletions trimsock.gd/addons/vest/icons/benchmark.svg.import
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type="CompressedTexture2D"
uid="uid://b6yh8aylojfgt"
path="res://.godot/imported/benchmark.svg-b9f24369bdd89bc588a152cef6f09c00.ctex"
metadata={
"has_editor_variant": true,
"vram_texture": false
}

Expand Down Expand Up @@ -33,5 +34,5 @@ process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=2.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
editor/scale_with_editor_scale=true
editor/convert_colors_with_editor_theme=true
5 changes: 3 additions & 2 deletions trimsock.gd/addons/vest/icons/clear.svg.import
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type="CompressedTexture2D"
uid="uid://ctdipwc8sklwo"
path="res://.godot/imported/clear.svg-c74aed6190d9cab6b3b5d7c8ad724085.ctex"
metadata={
"has_editor_variant": true,
"vram_texture": false
}

Expand Down Expand Up @@ -33,5 +34,5 @@ process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
svg/scale=2.0
editor/scale_with_editor_scale=false
editor/convert_colors_with_editor_theme=false
editor/scale_with_editor_scale=true
editor/convert_colors_with_editor_theme=true
Loading
Loading