Skip to content

Commit

Permalink
GD-596: Fix skipping tests via CMD line
Browse files Browse the repository at this point in the history
# Why
Running test via command line tools was crashed when using argument `-i <testsuite|testcase>`.

# What
- fixed the invalid array cast where was the root cause of the crash.
- fixed skipped status in the test explorer
- fixed skipped counting on CMD console
- fixed and added missing skip dtate to HTML report to visualize skipped state
  • Loading branch information
MikeSchulze committed Nov 19, 2024
1 parent 1af7935 commit 3d2bd55
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 18 deletions.
12 changes: 6 additions & 6 deletions addons/gdUnit4/bin/GdUnitCmdTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ class CLIRunner:
var skipped := config.skipped()
if skipped.is_empty():
return
_console.prints_warning("Found excluded test suite's configured at '%s'" % _runner_config_file)

for test_suite in test_suites:
# skipp c# testsuites for now
if test_suite.get_script() == null:
Expand All @@ -407,23 +407,23 @@ class CLIRunner:

# Dictionary[String, PackedStringArray]
func skip_suite(test_suite: Node, skipped: Dictionary) -> void:
var skipped_suites :Array[String] = skipped.keys()
var skipped_suites :Array = skipped.keys()
var suite_name := test_suite.get_name()
var test_suite_path: String = (
test_suite.get_meta("ResourcePath") if test_suite.get_script() == null
else test_suite.get_script().resource_path
)
for suite_to_skip in skipped_suites:
for suite_to_skip: String in skipped_suites:
# if suite skipped by path or name
if (
suite_to_skip == test_suite_path
or (suite_to_skip.is_valid_filename() and suite_to_skip == suite_name)
):
var skipped_tests: Array[String] = skipped.get(suite_to_skip)
var skip_reason := "Excluded by config '%s'" % _runner_config_file
var skipped_tests: PackedStringArray = skipped.get(suite_to_skip)
var skip_reason := "Excluded by configuration"
# if no tests skipped test the complete suite is skipped
if skipped_tests.is_empty():
_console.prints_warning("Mark test suite '%s' as skipped!" % suite_to_skip)
_console.prints_warning("Mark the entire test suite '%s' as skipped!" % test_suite_path)
@warning_ignore("unsafe_property_access")
test_suite.__is_skipped = true
@warning_ignore("unsafe_property_access")
Expand Down
4 changes: 2 additions & 2 deletions addons/gdUnit4/src/asserts/GdAssertMessages.gd
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ static func test_timeout(timeout :int) -> String:
static func test_suite_skipped(hint :String, skip_count :int) -> String:
return """
%s
Tests skipped: %s
Skipped %s tests
Reason: %s
""".dedent().trim_prefix("\n")\
% [_error("Entire test-suite is skipped!"), _colored_value(skip_count), _colored_value(hint)]
% [_error("The Entire test-suite is skipped!"), _colored_value(skip_count), _colored_value(hint)]


static func test_skipped(hint :String) -> String:
Expand Down
11 changes: 6 additions & 5 deletions addons/gdUnit4/src/core/GdUnitFileAccess.gd
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,12 @@ static func resource_as_string(resource_path :String) -> String:


static func make_qualified_path(path :String) -> String:
if not path.begins_with("res://"):
if path.begins_with("//"):
return path.replace("//", "res://")
if path.begins_with("/"):
return "res:/" + path
if path.begins_with("res://"):
return path
if path.begins_with("//"):
return path.replace("//", "res://")
if path.begins_with("/"):
return "res:/" + path
return path


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ func fire_test_suite_skipped(context :GdUnitExecutionContext) -> void:
var skip_count := test_suite.get_child_count()
fire_event(GdUnitEvent.new()\
.suite_before(context.get_test_suite_path(), test_suite.get_name(), skip_count))


for test_case_index in context.test_suite.get_child_count():
# iterate only over test cases
var test_case := context.test_suite.get_child(test_case_index) as _TestCase
if not is_instance_valid(test_case):
continue
var test_case_context := GdUnitExecutionContext.of_test_case(context, test_case)
fire_event(GdUnitEvent.new()\
.test_before(test_case_context.get_test_suite_path(), test_case_context.get_test_suite_name(), test_case_context.get_test_case_name()))
fire_test_skipped(test_case_context)


var statistics := {
GdUnitEvent.ORPHAN_NODES: 0,
GdUnitEvent.ELAPSED_TIME: 0,
Expand All @@ -105,6 +118,35 @@ func fire_test_suite_skipped(context :GdUnitExecutionContext) -> void:
await (Engine.get_main_loop() as SceneTree).process_frame


func fire_test_skipped(context: GdUnitExecutionContext) -> void:
var test_case := context.test_case
var statistics := {
GdUnitEvent.ORPHAN_NODES: 0,
GdUnitEvent.ELAPSED_TIME: 0,
GdUnitEvent.WARNINGS: false,
GdUnitEvent.ERRORS: false,
GdUnitEvent.ERROR_COUNT: 0,
GdUnitEvent.FAILED: false,
GdUnitEvent.FAILED_COUNT: 0,
GdUnitEvent.SKIPPED: true,
GdUnitEvent.SKIPPED_COUNT: 1,
}
var report := GdUnitReport.new() \
.create(GdUnitReport.SKIPPED, test_case.line_number(), GdAssertMessages.test_skipped("Skipped from the entire test suite"))
fire_event(GdUnitEvent.new() \
.test_after(context.get_test_suite_path(),
context.get_test_suite_name(),
context.get_test_case_name(),
statistics,
[report]))
# finally fire test statistics report
fire_event(GdUnitEvent.new()\
.test_statistics(context.get_test_suite_path(),
context.get_test_suite_name(),
context.get_test_case_name(),
statistics))


func set_debug_mode(debug_mode :bool = false) -> void:
super.set_debug_mode(debug_mode)
_stage_before.set_debug_mode(debug_mode)
Expand Down
5 changes: 5 additions & 0 deletions addons/gdUnit4/src/report/GdUnitHtmlPatterns.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const TABLE_RECORD_TESTSUITE = """
<td>${duration}</td>
<td>
<div class="status-bar">
<div class="status-bar-column status-skipped" style="width: ${skipped-percent};"></div>
<div class="status-bar-column status-passed" style="width: ${passed-percent};"></div>
<div class="status-bar-column status-flaky" style="width: ${flaky-percent};"></div>
<div class="status-bar-column status-error" style="width: ${error-percent};"></div>
Expand All @@ -35,6 +36,7 @@ const TABLE_RECORD_PATH = """
<td>${duration}</td>
<td>
<div class="status-bar">
<div class="status-bar-column status-skipped" style="width: ${passed-skipped};"></div>
<div class="status-bar-column status-passed" style="width: ${passed-percent};"></div>
<div class="status-bar-column status-flaky" style="width: ${flaky-percent};"></div>
<div class="status-bar-column status-error" style="width: ${error-percent};"></div>
Expand Down Expand Up @@ -95,6 +97,8 @@ const DURATION = "${duration}"
const FAILURE_REPORT = "${failure-report}"
const SUCCESS_PERCENT = "${success_percent}"


const QUICK_STATE_SKIPPED = "${skipped-percent}"
const QUICK_STATE_PASSED = "${passed-percent}"
const QUICK_STATE_FLAKY = "${flaky-percent}"
const QUICK_STATE_ERROR = "${error-percent}"
Expand Down Expand Up @@ -128,6 +132,7 @@ static func build(template: String, report: GdUnitReportSummary, report_link: St
.replace(SUCCESS_PERCENT, report.calculate_succes_rate(report.test_count(), report.error_count(), report.failure_count()))\
.replace(REPORT_STATE, report.report_state().to_lower())\
.replace(REPORT_STATE_LABEL, report.report_state())\
.replace(QUICK_STATE_SKIPPED, calculate_percentage(report.test_count(), report.skipped_count()))\
.replace(QUICK_STATE_PASSED, calculate_percentage(report.test_count(), report.success_count()))\
.replace(QUICK_STATE_FLAKY, calculate_percentage(report.test_count(), report.flaky_count()))\
.replace(QUICK_STATE_ERROR, calculate_percentage(report.test_count(), report.error_count()))\
Expand Down
8 changes: 5 additions & 3 deletions addons/gdUnit4/src/report/GdUnitReportSummary.gd
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func test_executed_count() -> int:


func success_count() -> int:
return test_count() - error_count() - failure_count() - flaky_count()
return test_count() - error_count() - failure_count() - flaky_count() - skipped_count()


func error_count() -> int:
Expand Down Expand Up @@ -95,14 +95,16 @@ func add_report(report :GdUnitReportSummary) -> void:


func report_state() -> String:
return calculate_state(error_count(), failure_count(), orphan_count(), flaky_count())
return calculate_state(error_count(), failure_count(), orphan_count(), flaky_count(), skipped_count())


func succes_rate() -> String:
return calculate_succes_rate(test_count(), error_count(), failure_count())


func calculate_state(p_error_count :int, p_failure_count :int, p_orphan_count :int, p_flaky_count: int) -> String:
func calculate_state(p_error_count :int, p_failure_count :int, p_orphan_count :int, p_flaky_count: int, p_skipped_count: int) -> String:
if p_skipped_count > 0:
return "SKIPPED"
if p_error_count > 0:
return "ERROR"
if p_failure_count > 0:
Expand Down
4 changes: 4 additions & 0 deletions addons/gdUnit4/src/report/template/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ th.report-column {
transition: width 0.3s ease;
}

.status-skipped {
background-color: #888888;
}

.status-passed {
background-color: #63bb38;
}
Expand Down
3 changes: 3 additions & 0 deletions addons/gdUnit4/src/report/template/folder_report.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ <h1>Report by Paths</h1>
<footer>
<p>Generated by <a href="https://github.com/MikeSchulze/gdUnit4">GdUnit4</a> at ${buid_date}</p>
<div class="status-legend">
<span class="status-legend-item">
<span class="status-box status-skipped"></span> Skipped
</span>
<span class="status-legend-item">
<span class="status-box status-passed"></span> Passed
</span>
Expand Down
3 changes: 3 additions & 0 deletions addons/gdUnit4/src/report/template/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ <h1>Summary Report</h1>
<footer>
<p>Generated by <a href="https://github.com/MikeSchulze/gdUnit4">GdUnit4</a> at ${buid_date}</p>
<div class="status-legend">
<span class="status-legend-item">
<span class="status-box status-skipped"></span> Skipped
</span>
<span class="status-legend-item">
<span class="status-box status-passed"></span> Passed
</span>
Expand Down
3 changes: 3 additions & 0 deletions addons/gdUnit4/src/report/template/suite_report.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ <h4>Failure Report</h4>
<footer>
<p>Generated by <a href="https://github.com/MikeSchulze/gdUnit4">GdUnit4</a> at ${buid_date}</p>
<div class="status-legend">
<span class="status-legend-item">
<span class="status-box status-skipped"></span> Skipped
</span>
<span class="status-legend-item">
<span class="status-box status-passed"></span> Passed
</span>
Expand Down
3 changes: 2 additions & 1 deletion addons/gdUnit4/test/cmd/runtestDebug.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ func _ready() -> void:
#var tool := CmdTool.new()

var runner := CmdTool.CLIRunner.new()
runner._debug_cmd_args = [\"GdUnitCmdTool.gd\", \"--add\", \"res://addons/gdUnit4/test/asserts\", \"--continue\", \"-rc\", \"1\"]
runner._debug_cmd_args = [\"GdUnitCmdTool.gd\", \"--add\", \"res://addons/gdUnit4/test/cmd\", \"-i\", \"CmdArgumentParserTest\", \"--continue\", \"-rc\", \"1\"]

add_child(runner)


Expand Down
6 changes: 5 additions & 1 deletion addons/gdUnit4/test/core/GdUnitRunnerConfigTest.gd
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,14 @@ func test_skip_test_suite() -> void:
# add two more
config.skip_test_suite("res://foo2")
config.skip_test_suite("res://bar/foo1")
config.skip_test_suite("res://bar/foo2/")
config.skip_test_suite("bar/foo3/")
assert_dict(config.skipped())\
.contains_key_value("res://foo1", PackedStringArray())\
.contains_key_value("res://foo2", PackedStringArray())\
.contains_key_value("res://bar/foo1", PackedStringArray())
.contains_key_value("res://bar/foo1", PackedStringArray())\
.contains_key_value("res://bar/foo2/", PackedStringArray())\
.contains_key_value("bar/foo3/", PackedStringArray())


func test_skip_test_suite_and_test_case() -> void:
Expand Down

0 comments on commit 3d2bd55

Please sign in to comment.