From cacb527dc21bad506767b511c21c92b5ee7a662d Mon Sep 17 00:00:00 2001 From: Nullpointer Date: Tue, 19 Nov 2024 17:45:40 +0100 Subject: [PATCH] GD-596: Fixed run test via CMD line is broken when use skipp command option (#597) # Why Running test via command line tools was crashed when using argument `-i `. # 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 state to HTML report to visualize skipped state ![image](https://github.com/user-attachments/assets/f1ee3c06-bc3d-4e45-8567-5b5127cd465c) --- addons/gdUnit4/bin/GdUnitCmdTool.gd | 12 +++--- .../gdUnit4/src/asserts/GdAssertMessages.gd | 4 +- addons/gdUnit4/src/core/GdUnitFileAccess.gd | 11 ++--- .../stages/GdUnitTestSuiteExecutionStage.gd | 42 +++++++++++++++++++ .../gdUnit4/src/report/GdUnitHtmlPatterns.gd | 5 +++ .../gdUnit4/src/report/GdUnitReportSummary.gd | 8 ++-- .../src/report/template/css/styles.css | 4 ++ .../src/report/template/folder_report.html | 3 ++ addons/gdUnit4/src/report/template/index.html | 3 ++ .../src/report/template/suite_report.html | 3 ++ addons/gdUnit4/test/cmd/runtestDebug.tscn | 3 +- .../test/core/GdUnitRunnerConfigTest.gd | 6 ++- .../execution/GdUnitTestSuiteExecutorTest.gd | 18 +++++++- 13 files changed, 102 insertions(+), 20 deletions(-) diff --git a/addons/gdUnit4/bin/GdUnitCmdTool.gd b/addons/gdUnit4/bin/GdUnitCmdTool.gd index 07d0926b..e540a5ec 100644 --- a/addons/gdUnit4/bin/GdUnitCmdTool.gd +++ b/addons/gdUnit4/bin/GdUnitCmdTool.gd @@ -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: @@ -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") diff --git a/addons/gdUnit4/src/asserts/GdAssertMessages.gd b/addons/gdUnit4/src/asserts/GdAssertMessages.gd index 83c2892c..2be8c117 100644 --- a/addons/gdUnit4/src/asserts/GdAssertMessages.gd +++ b/addons/gdUnit4/src/asserts/GdAssertMessages.gd @@ -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: diff --git a/addons/gdUnit4/src/core/GdUnitFileAccess.gd b/addons/gdUnit4/src/core/GdUnitFileAccess.gd index e73216d0..cf8663c0 100644 --- a/addons/gdUnit4/src/core/GdUnitFileAccess.gd +++ b/addons/gdUnit4/src/core/GdUnitFileAccess.gd @@ -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 diff --git a/addons/gdUnit4/src/core/execution/stages/GdUnitTestSuiteExecutionStage.gd b/addons/gdUnit4/src/core/execution/stages/GdUnitTestSuiteExecutionStage.gd index 5aad57d7..b62d27e0 100644 --- a/addons/gdUnit4/src/core/execution/stages/GdUnitTestSuiteExecutionStage.gd +++ b/addons/gdUnit4/src/core/execution/stages/GdUnitTestSuiteExecutionStage.gd @@ -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, @@ -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) diff --git a/addons/gdUnit4/src/report/GdUnitHtmlPatterns.gd b/addons/gdUnit4/src/report/GdUnitHtmlPatterns.gd index 722c528f..a9da106c 100644 --- a/addons/gdUnit4/src/report/GdUnitHtmlPatterns.gd +++ b/addons/gdUnit4/src/report/GdUnitHtmlPatterns.gd @@ -13,6 +13,7 @@ const TABLE_RECORD_TESTSUITE = """ ${duration}
+
@@ -35,6 +36,7 @@ const TABLE_RECORD_PATH = """ ${duration}
+
@@ -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}" @@ -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()))\ diff --git a/addons/gdUnit4/src/report/GdUnitReportSummary.gd b/addons/gdUnit4/src/report/GdUnitReportSummary.gd index e702491e..20a24e7a 100644 --- a/addons/gdUnit4/src/report/GdUnitReportSummary.gd +++ b/addons/gdUnit4/src/report/GdUnitReportSummary.gd @@ -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: @@ -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: diff --git a/addons/gdUnit4/src/report/template/css/styles.css b/addons/gdUnit4/src/report/template/css/styles.css index a1b0ed91..e92d59b7 100644 --- a/addons/gdUnit4/src/report/template/css/styles.css +++ b/addons/gdUnit4/src/report/template/css/styles.css @@ -330,6 +330,10 @@ th.report-column { transition: width 0.3s ease; } +.status-skipped { + background-color: #888888; +} + .status-passed { background-color: #63bb38; } diff --git a/addons/gdUnit4/src/report/template/folder_report.html b/addons/gdUnit4/src/report/template/folder_report.html index c6df9810..2cdca675 100644 --- a/addons/gdUnit4/src/report/template/folder_report.html +++ b/addons/gdUnit4/src/report/template/folder_report.html @@ -97,6 +97,9 @@

Report by Paths