diff --git a/addons/gdUnit4/bin/GdUnitBuildTool.gd b/addons/gdUnit4/bin/GdUnitBuildTool.gd index 51f78f5e..21eeb5a1 100644 --- a/addons/gdUnit4/bin/GdUnitBuildTool.gd +++ b/addons/gdUnit4/bin/GdUnitBuildTool.gd @@ -19,6 +19,7 @@ var _status := INIT var _source_file :String = "" var _source_line :int = -1 + func _init(): var cmd_parser := CmdArgumentParser.new(_cmd_options, "GdUnitBuildTool.gd") var result := cmd_parser.parse(OS.get_cmdline_args()) @@ -42,13 +43,14 @@ func _init(): return _status = PROCESSING + func _idle(_delta): if _status == PROCESSING: var script := ResourceLoader.load(_source_file) as Script if script == null: exit(RETURN_ERROR, "Can't load source file %s!" % _source_file) - var result := GdUnitTestSuiteBuilder.new().create(script, _source_line) + var result := GdUnitTestSuiteBuilder.create(script, _source_line) if result.is_error(): print_json_error(result.error_message()) exit(RETURN_ERROR, result.error_message()) @@ -58,6 +60,7 @@ func _idle(_delta): print_json_result(result.value()) exit(RETURN_SUCCESS) + func exit(code :int, message :String = "") -> void: _status = EXIT if code == RETURN_ERROR: @@ -68,22 +71,26 @@ func exit(code :int, message :String = "") -> void: _console.prints_color("Exit code: %d" % RETURN_SUCCESS, Color.DARK_SALMON) quit(code) + func print_json_result(result :Dictionary) -> void: # convert back to system path var path = ProjectSettings.globalize_path(result["path"]); var json = 'JSON_RESULT:{"TestCases" : [{"line":%d, "path": "%s"}]}' % [result["line"], path] prints(json) + func print_json_error(error :String) -> void: prints('JSON_RESULT:{"Error" : "%s"}' % error) -func show_options(show_advanced :bool = false) -> void: + +func show_options() -> void: _console.prints_color(" Usage:", Color.DARK_SALMON) _console.prints_color(" build -scp -scl ", Color.DARK_SALMON) _console.prints_color("-- Options ---------------------------------------------------------------------------------------", Color.DARK_SALMON).new_line() for option in _cmd_options.default_options(): descripe_option(option) + func descripe_option(cmd_option :CmdOption) -> void: _console.print_color(" %-40s" % str(cmd_option.commands()), Color.CORNFLOWER_BLUE) _console.prints_color(cmd_option.description(), Color.LIGHT_GREEN) diff --git a/addons/gdUnit4/bin/GdUnitCmdTool.gd b/addons/gdUnit4/bin/GdUnitCmdTool.gd index 27f84b37..6ddfd5f4 100644 --- a/addons/gdUnit4/bin/GdUnitCmdTool.gd +++ b/addons/gdUnit4/bin/GdUnitCmdTool.gd @@ -157,7 +157,7 @@ class CLIRunner extends Node: func load_test_config(path := GdUnitRunnerConfig.CONFIG_FILE) -> void: _console.print_color("Loading test configuration %s\n" % path, Color.CORNFLOWER_BLUE) - _runner_config.load(path) + _runner_config.load_config(path) func show_help() -> void: @@ -233,9 +233,9 @@ class CLIRunner extends Node: var to_execute := config.to_execute() # scan for the requested test suites var _scanner := GdUnitTestSuiteScanner.new() - for resource_path in to_execute.keys(): - var selected_tests :PackedStringArray = to_execute.get(resource_path) - var scaned_suites := _scanner.scan(resource_path) + for resource_path_ in to_execute.keys(): + var selected_tests :PackedStringArray = to_execute.get(resource_path_) + var scaned_suites := _scanner.scan(resource_path_) skip_test_case(scaned_suites, selected_tests) test_suites_to_process.append_array(scaned_suites) skip_suites(test_suites_to_process, config) diff --git a/addons/gdUnit4/bin/ProjectScanner.gd b/addons/gdUnit4/bin/ProjectScanner.gd index 64bf7752..4d57a388 100644 --- a/addons/gdUnit4/bin/ProjectScanner.gd +++ b/addons/gdUnit4/bin/ProjectScanner.gd @@ -61,7 +61,7 @@ class ProjectScanner extends Node: await get_tree().process_frame while fs.is_scanning(): await get_tree().process_frame - _console.progressBar(fs.get_scanning_progress() * 100) + _console.progressBar(fs.get_scanning_progress() * 100 as int) _console.progressBar(100) _console.new_line() @@ -71,7 +71,7 @@ class ProjectScanner extends Node: await get_tree().process_frame while fs.is_scanning(): await get_tree().process_frame - _console.progressBar(fs.get_scanning_progress() * 100) + _console.progressBar(fs.get_scanning_progress() * 100 as int) _console.progressBar(100) _console.new_line() plugin.free() diff --git a/addons/gdUnit4/src/Fuzzers.gd b/addons/gdUnit4/src/Fuzzers.gd index 0d208a6b..cd53d20a 100644 --- a/addons/gdUnit4/src/Fuzzers.gd +++ b/addons/gdUnit4/src/Fuzzers.gd @@ -1,25 +1,30 @@ +## A fuzzer implementation to provide default implementation class_name Fuzzers extends Resource +## Generates an random string with min/max length and given charset static func rand_str(min_length :int, max_length, charset := StringFuzzer.DEFAULT_CHARSET) -> Fuzzer: return StringFuzzer.new(min_length, max_length, charset) -# Generates an random integer in a range form to + +## Generates an random integer in a range form to static func rangei(from: int, to: int) -> Fuzzer: return IntFuzzer.new(from, to) -# Generates an random Vector2 in a range form to + +## Generates an random Vector2 in a range form to static func rangev2(from: Vector2, to: Vector2) -> Fuzzer: return Vector2Fuzzer.new(from, to) -# Generates an random Vector3 in a range form to + +## Generates an random Vector3 in a range form to static func rangev3(from: Vector3, to: Vector3) -> Fuzzer: return Vector3Fuzzer.new(from, to) -# Generates an integer in a range form to that can be divided exactly by 2 +## Generates an integer in a range form to that can be divided exactly by 2 static func eveni(from: int, to: int) -> Fuzzer: return IntFuzzer.new(from, to, IntFuzzer.EVEN) -# Generates an integer in a range form to that cannot be divided exactly by 2 +## Generates an integer in a range form to that cannot be divided exactly by 2 static func oddi(from: int, to: int) -> Fuzzer: return IntFuzzer.new(from, to, IntFuzzer.ODD) diff --git a/addons/gdUnit4/src/GdUnitArrayAssert.gd b/addons/gdUnit4/src/GdUnitArrayAssert.gd index e3356e9c..53d79537 100644 --- a/addons/gdUnit4/src/GdUnitArrayAssert.gd +++ b/addons/gdUnit4/src/GdUnitArrayAssert.gd @@ -1,63 +1,86 @@ -# An Assertion Tool to verify array values +## An Assertion Tool to verify array values class_name GdUnitArrayAssert extends GdUnitAssert -# Verifies that the current value is null. +## Verifies that the current value is null. func is_null() -> GdUnitArrayAssert: return self -# Verifies that the current value is not null. + +## Verifies that the current value is not null. func is_not_null() -> GdUnitArrayAssert: return self -# Verifies that the current Array is equal to the given one. + +## Verifies that the current Array is equal to the given one. +@warning_ignore("unused_parameter") func is_equal(expected) -> GdUnitArrayAssert: return self -# Verifies that the current Array is equal to the given one, ignoring case considerations. + +## Verifies that the current Array is equal to the given one, ignoring case considerations. +@warning_ignore("unused_parameter") func is_equal_ignoring_case(expected) -> GdUnitArrayAssert: return self -# Verifies that the current Array is not equal to the given one. + +## Verifies that the current Array is not equal to the given one. +@warning_ignore("unused_parameter") func is_not_equal(expected) -> GdUnitArrayAssert: return self -# Verifies that the current Array is not equal to the given one, ignoring case considerations. + +## Verifies that the current Array is not equal to the given one, ignoring case considerations. +@warning_ignore("unused_parameter") func is_not_equal_ignoring_case(expected) -> GdUnitArrayAssert: return self -# Verifies that the current Array is empty, it has a size of 0. + +## Verifies that the current Array is empty, it has a size of 0. func is_empty() -> GdUnitArrayAssert: return self -# Verifies that the current Array is not empty, it has a size of minimum 1. + +## Verifies that the current Array is not empty, it has a size of minimum 1. func is_not_empty() -> GdUnitArrayAssert: return self -# Verifies that the current Array has a size of given value. + +## Verifies that the current Array has a size of given value. +@warning_ignore("unused_parameter") func has_size(expectd: int) -> GdUnitArrayAssert: return self -# Verifies that the current Array contains the given values, in any order. + +## Verifies that the current Array contains the given values, in any order. +@warning_ignore("unused_parameter") func contains(expected) -> GdUnitArrayAssert: return self -# Verifies that the current Array contains exactly only the given values and nothing else, in same order. + +## Verifies that the current Array contains exactly only the given values and nothing else, in same order. +@warning_ignore("unused_parameter") func contains_exactly(expected) -> GdUnitArrayAssert: return self -# Verifies that the current Array contains exactly only the given values and nothing else, in any order. + +## Verifies that the current Array contains exactly only the given values and nothing else, in any order. +@warning_ignore("unused_parameter") func contains_exactly_in_any_order(expected) -> GdUnitArrayAssert: return self -# Extracts all values by given function name and optional arguments into a new ArrayAssert -# If the elements not accessible by `func_name` the value is converted to `"n.a"`, expecting null values + +## Extracts all values by given function name and optional arguments into a new ArrayAssert. +## If the elements not accessible by `func_name` the value is converted to `"n.a"`, expecting null values +@warning_ignore("unused_parameter") func extract(func_name: String, args := Array()) -> GdUnitArrayAssert: return self -# Extracts all values by given extractor's into a new ArrayAssert -# If the elements not extractable than the value is converted to `"n.a"`, expecting null values + +## Extracts all values by given extractor's into a new ArrayAssert. +## If the elements not extractable than the value is converted to `"n.a"`, expecting null values +@warning_ignore("unused_parameter") func extractv( extractor0 :GdUnitValueExtractor, extractor1 :GdUnitValueExtractor = null, diff --git a/addons/gdUnit4/src/GdUnitAssert.gd b/addons/gdUnit4/src/GdUnitAssert.gd index fb0141d9..1cdae567 100644 --- a/addons/gdUnit4/src/GdUnitAssert.gd +++ b/addons/gdUnit4/src/GdUnitAssert.gd @@ -1,4 +1,4 @@ -# Base interface of all GdUnit asserts +## Base interface of all GdUnit asserts class_name GdUnitAssert extends RefCounted @@ -8,33 +8,45 @@ const EXPECT_SUCCESS:int = 0 const EXPECT_FAIL:int = 1 -# Verifies that the current value is null. +## Verifies that the current value is null. func is_null(): return self -# Verifies that the current value is not null. + +## Verifies that the current value is not null. func is_not_null(): return self -# Verifies that the current value is equal to expected one. + +## Verifies that the current value is equal to expected one. +@warning_ignore("unused_parameter") func is_equal(expected): return self -# Verifies that the current value is not equal to expected one. + +## Verifies that the current value is not equal to expected one. +@warning_ignore("unused_parameter") func is_not_equal(expected): return self + func test_fail(): return self -# Verifies the failure message is equal to expected one. + +## Verifies the failure message is equal to expected one. +@warning_ignore("unused_parameter") func has_failure_message(expected: String): return self -# Verifies that the failure starts with the given prefix. + +## Verifies that the failure starts with the given prefix. +@warning_ignore("unused_parameter") func starts_with_failure_message(expected: String): return self -# Overrides the default failure message by given custom message. + +## Overrides the default failure message by given custom message. +@warning_ignore("unused_parameter") func override_failure_message(message :String): return self diff --git a/addons/gdUnit4/src/GdUnitBoolAssert.gd b/addons/gdUnit4/src/GdUnitBoolAssert.gd index 05cd8700..7e62dbe4 100644 --- a/addons/gdUnit4/src/GdUnitBoolAssert.gd +++ b/addons/gdUnit4/src/GdUnitBoolAssert.gd @@ -1,31 +1,41 @@ -# An Assertion Tool to verify boolean values +## An Assertion Tool to verify boolean values class_name GdUnitBoolAssert extends GdUnitAssert -# Verifies that the current value is null. +## Verifies that the current value is null. func is_null() -> GdUnitBoolAssert: return self -# Verifies that the current value is not null. + +## Verifies that the current value is not null. func is_not_null() -> GdUnitBoolAssert: return self -# Verifies that the current value is equal to the given one. + +## Verifies that the current value is equal to the given one. +@warning_ignore("unused_parameter") func is_equal(expected) -> GdUnitBoolAssert: return self -# Verifies that the current value is not equal to the given one. + +## Verifies that the current value is not equal to the given one. +@warning_ignore("unused_parameter") func is_not_equal(expected) -> GdUnitBoolAssert: return self -# Verifies that the current value is true. + +## Verifies that the current value is true. func is_true() -> GdUnitBoolAssert: return self -# Verifies that the current value is false. + +## Verifies that the current value is false. func is_false() -> GdUnitBoolAssert: return self + +## Overrides the default failure message by given custom message. +@warning_ignore("unused_parameter") func override_failure_message(message :String) -> GdUnitBoolAssert: return self diff --git a/addons/gdUnit4/src/GdUnitDictionaryAssert.gd b/addons/gdUnit4/src/GdUnitDictionaryAssert.gd index ca2f4362..8d8406e9 100644 --- a/addons/gdUnit4/src/GdUnitDictionaryAssert.gd +++ b/addons/gdUnit4/src/GdUnitDictionaryAssert.gd @@ -1,44 +1,59 @@ -# An Assertion Tool to verify dictionary +## An Assertion Tool to verify dictionary class_name GdUnitDictionaryAssert extends GdUnitAssert -# Verifies that the current value is null. +## Verifies that the current value is null. func is_null() -> GdUnitDictionaryAssert: return self -# Verifies that the current value is not null. + +## Verifies that the current value is not null. func is_not_null() -> GdUnitDictionaryAssert: return self -# Verifies that the current dictionary is equal to the given one, ignoring order. + +## Verifies that the current dictionary is equal to the given one, ignoring order. +@warning_ignore("unused_parameter") func is_equal(expected) -> GdUnitDictionaryAssert: return self -# Verifies that the current dictionary is not equal to the given one, ignoring order. + +## Verifies that the current dictionary is not equal to the given one, ignoring order. +@warning_ignore("unused_parameter") func is_not_equal(expected) -> GdUnitDictionaryAssert: return self -# Verifies that the current dictionary is empty, it has a size of 0. + +## Verifies that the current dictionary is empty, it has a size of 0. func is_empty() -> GdUnitDictionaryAssert: return self -# Verifies that the current dictionary is not empty, it has a size of minimum 1. + +## Verifies that the current dictionary is not empty, it has a size of minimum 1. func is_not_empty() -> GdUnitDictionaryAssert: return self -# Verifies that the current dictionary has a size of given value. + +## Verifies that the current dictionary has a size of given value. +@warning_ignore("unused_parameter") func has_size(expected: int) -> GdUnitDictionaryAssert: return self -# Verifies that the current dictionary contains the given key(s). + +## Verifies that the current dictionary contains the given key(s). +@warning_ignore("unused_parameter") func contains_keys(expected :Array) -> GdUnitDictionaryAssert: return self -# Verifies that the current dictionary not contains the given key(s). + +## Verifies that the current dictionary not contains the given key(s). +@warning_ignore("unused_parameter") func contains_not_keys(expected :Array) -> GdUnitDictionaryAssert: return self -# Verifies that the current dictionary contains the given key and value. + +## Verifies that the current dictionary contains the given key and value. +@warning_ignore("unused_parameter") func contains_key_value(key, value) -> GdUnitDictionaryAssert: return self diff --git a/addons/gdUnit4/src/GdUnitFileAssert.gd b/addons/gdUnit4/src/GdUnitFileAssert.gd index b5fb3223..21bf21a6 100644 --- a/addons/gdUnit4/src/GdUnitFileAssert.gd +++ b/addons/gdUnit4/src/GdUnitFileAssert.gd @@ -5,11 +5,15 @@ extends GdUnitAssert func is_file() -> GdUnitFileAssert: return self + func exists() -> GdUnitFileAssert: return self + func is_script() -> GdUnitFileAssert: return self + +@warning_ignore("unused_parameter") func contains_exactly(expected_rows :Array) -> GdUnitFileAssert: return self diff --git a/addons/gdUnit4/src/GdUnitFloatAssert.gd b/addons/gdUnit4/src/GdUnitFloatAssert.gd index aaa9f7cc..8f24f561 100644 --- a/addons/gdUnit4/src/GdUnitFloatAssert.gd +++ b/addons/gdUnit4/src/GdUnitFloatAssert.gd @@ -1,60 +1,83 @@ -# An Assertion Tool to verify float values +## An Assertion Tool to verify float values class_name GdUnitFloatAssert extends GdUnitAssert -# Verifies that the current value is equal to expected one. + +## Verifies that the current value is equal to expected one. +@warning_ignore("unused_parameter") func is_equal(expected :float) -> GdUnitFloatAssert: return self -# Verifies that the current value is not equal to expected one. + +## Verifies that the current value is not equal to expected one. +@warning_ignore("unused_parameter") func is_not_equal(expected :float) -> GdUnitFloatAssert: return self -# Verifies that the current and expected value are approximately equal. + +## Verifies that the current and expected value are approximately equal. +@warning_ignore("unused_parameter", "shadowed_global_identifier") func is_equal_approx(expected :float, approx :float) -> GdUnitFloatAssert: return self -# Verifies that the current value is less than the given one. + +## Verifies that the current value is less than the given one. +@warning_ignore("unused_parameter") func is_less(expected :float) -> GdUnitFloatAssert: return self -# Verifies that the current value is less than or equal the given one. + +## Verifies that the current value is less than or equal the given one. +@warning_ignore("unused_parameter") func is_less_equal(expected :float) -> GdUnitFloatAssert: return self -# Verifies that the current value is greater than the given one. + +## Verifies that the current value is greater than the given one. +@warning_ignore("unused_parameter") func is_greater(expected :float) -> GdUnitFloatAssert: return self -# Verifies that the current value is greater than or equal the given one. + +## Verifies that the current value is greater than or equal the given one. +@warning_ignore("unused_parameter") func is_greater_equal(expected :float) -> GdUnitFloatAssert: return self -# Verifies that the current value is negative. + +## Verifies that the current value is negative. func is_negative() -> GdUnitFloatAssert: return self -# Verifies that the current value is not negative. + +## Verifies that the current value is not negative. func is_not_negative() -> GdUnitFloatAssert: return self -# Verifies that the current value is equal to zero. + +## Verifies that the current value is equal to zero. func is_zero() -> GdUnitFloatAssert: return self - -# Verifies that the current value is not equal to zero. + + +## Verifies that the current value is not equal to zero. func is_not_zero() -> GdUnitFloatAssert: return self -# Verifies that the current value is in the given set of values. + +## Verifies that the current value is in the given set of values. +@warning_ignore("unused_parameter") func is_in(expected :Array) -> GdUnitFloatAssert: return self -# Verifies that the current value is not in the given set of values. + +## Verifies that the current value is not in the given set of values. +@warning_ignore("unused_parameter") func is_not_in(expected :Array) -> GdUnitFloatAssert: return self -# Verifies that the current value is between the given boundaries (inclusive). + +## Verifies that the current value is between the given boundaries (inclusive). +@warning_ignore("unused_parameter") func is_between(from :float, to :float) -> GdUnitFloatAssert: return self - diff --git a/addons/gdUnit4/src/GdUnitFuncAssert.gd b/addons/gdUnit4/src/GdUnitFuncAssert.gd index 435b1007..0d4c9819 100644 --- a/addons/gdUnit4/src/GdUnitFuncAssert.gd +++ b/addons/gdUnit4/src/GdUnitFuncAssert.gd @@ -1,47 +1,68 @@ -# An Assertion Tool to verify function callback values +## An Assertion Tool to verify function callback values class_name GdUnitFuncAssert extends GdUnitAssert -# Verifies that the current value is null. -func is_null() -> GdUnitAssert: +## Verifies that the current value is null. +func is_null() -> GdUnitFuncAssert: + await Engine.get_main_loop().process_frame return self -# Verifies that the current value is not null. -func is_not_null() -> GdUnitAssert: + +## Verifies that the current value is not null. +func is_not_null() -> GdUnitFuncAssert: + await Engine.get_main_loop().process_frame return self -# Verifies that the current value is equal to the given one. -func is_equal(expected) -> GdUnitAssert: + +## Verifies that the current value is equal to the given one. +@warning_ignore("unused_parameter") +func is_equal(expected) -> GdUnitFuncAssert: + await Engine.get_main_loop().process_frame return self -# Verifies that the current value is not equal to the given one. -func is_not_equal(expected) -> GdUnitAssert: + +## Verifies that the current value is not equal to the given one. +@warning_ignore("unused_parameter") +func is_not_equal(expected) -> GdUnitFuncAssert: + await Engine.get_main_loop().process_frame return self -# Verifies that the current value is true. -func is_true() -> GdUnitAssert: + +## Verifies that the current value is true. +func is_true() -> GdUnitFuncAssert: + await Engine.get_main_loop().process_frame return self -# Verifies that the current value is false. -func is_false() -> GdUnitAssert: + +## Verifies that the current value is false. +func is_false() -> GdUnitFuncAssert: + await Engine.get_main_loop().process_frame return self -# Verifies the failure message is equal to expected one. -func has_failure_message(expected: String): + +## Verifies the failure message is equal to expected one. +@warning_ignore("unused_parameter") +func has_failure_message(expected: String) -> GdUnitFuncAssert: return self -# Verifies that the failure starts with the given prefix. -func starts_with_failure_message(expected: String): + +## Verifies that the failure starts with the given prefix. +@warning_ignore("unused_parameter") +func starts_with_failure_message(expected: String) -> GdUnitFuncAssert: return self -# Overrides the default failure message by given custom message. -func override_failure_message(message :String): + +## Overrides the default failure message by given custom message. +@warning_ignore("unused_parameter") +func override_failure_message(message :String) -> GdUnitFuncAssert: return self -# Sets the timeout in ms to wait the function returnd the expected value, if the time over a failure is emitted -# e.g. -# do wait until 5s the function `is_state` is returns 10 -# assert_func(instance, "is_state").wait_until(5000).is_equal(10) -func wait_until(timeout :int) -> GdUnitAssert: + +## Sets the timeout in ms to wait the function returnd the expected value, if the time over a failure is emitted.[br] +## e.g.[br] +## do wait until 5s the function `is_state` is returns 10 [br] +## [code]assert_func(instance, "is_state").wait_until(5000).is_equal(10)[/code] +@warning_ignore("unused_parameter") +func wait_until(timeout :int) -> GdUnitFuncAssert: return self diff --git a/addons/gdUnit4/src/GdUnitIntAssert.gd b/addons/gdUnit4/src/GdUnitIntAssert.gd index d448b1d2..584788fc 100644 --- a/addons/gdUnit4/src/GdUnitIntAssert.gd +++ b/addons/gdUnit4/src/GdUnitIntAssert.gd @@ -1,64 +1,87 @@ -# An Assertion Tool to verify integer values +## An Assertion Tool to verify integer values class_name GdUnitIntAssert extends GdUnitAssert -# Verifies that the current value is equal to expected one. + +## Verifies that the current value is equal to expected one. +@warning_ignore("unused_parameter") func is_equal(expected :int) -> GdUnitIntAssert: return self -# Verifies that the current value is not equal to expected one. + +## Verifies that the current value is not equal to expected one. +@warning_ignore("unused_parameter") func is_not_equal(expected :int) -> GdUnitIntAssert: return self -# Verifies that the current value is less than the given one. + +## Verifies that the current value is less than the given one. +@warning_ignore("unused_parameter") func is_less(expected :int) -> GdUnitIntAssert: return self -# Verifies that the current value is less than or equal the given one. + +## Verifies that the current value is less than or equal the given one. +@warning_ignore("unused_parameter") func is_less_equal(expected :int) -> GdUnitIntAssert: return self -# Verifies that the current value is greater than the given one. + +## Verifies that the current value is greater than the given one. +@warning_ignore("unused_parameter") func is_greater(expected :int) -> GdUnitIntAssert: return self -# Verifies that the current value is greater than or equal the given one. + +## Verifies that the current value is greater than or equal the given one. +@warning_ignore("unused_parameter") func is_greater_equal(expected :int) -> GdUnitIntAssert: return self -# Verifies that the current value is even. + +## Verifies that the current value is even. func is_even() -> GdUnitIntAssert: return self -# Verifies that the current value is odd. + +## Verifies that the current value is odd. func is_odd() -> GdUnitIntAssert: return self -# Verifies that the current value is negative. + +## Verifies that the current value is negative. func is_negative() -> GdUnitIntAssert: return self -# Verifies that the current value is not negative. + +## Verifies that the current value is not negative. func is_not_negative() -> GdUnitIntAssert: return self -# Verifies that the current value is equal to zero. + +## Verifies that the current value is equal to zero. func is_zero() -> GdUnitIntAssert: return self - -# Verifies that the current value is not equal to zero. + + +## Verifies that the current value is not equal to zero. func is_not_zero() -> GdUnitIntAssert: return self -# Verifies that the current value is in the given set of values. + +## Verifies that the current value is in the given set of values. +@warning_ignore("unused_parameter") func is_in(expected :Array) -> GdUnitIntAssert: return self -# Verifies that the current value is not in the given set of values. + +## Verifies that the current value is not in the given set of values. +@warning_ignore("unused_parameter") func is_not_in(expected :Array) -> GdUnitIntAssert: return self -# Verifies that the current value is between the given boundaries (inclusive). + +## Verifies that the current value is between the given boundaries (inclusive). +@warning_ignore("unused_parameter") func is_between(from :int, to :int) -> GdUnitIntAssert: return self - diff --git a/addons/gdUnit4/src/GdUnitObjectAssert.gd b/addons/gdUnit4/src/GdUnitObjectAssert.gd index c72c5fa1..d73bfd5a 100644 --- a/addons/gdUnit4/src/GdUnitObjectAssert.gd +++ b/addons/gdUnit4/src/GdUnitObjectAssert.gd @@ -1,35 +1,49 @@ -# An Assertion Tool to verify Object values +## An Assertion Tool to verify Object values class_name GdUnitObjectAssert extends GdUnitAssert -# Verifies that the current value is equal to expected one. + +## Verifies that the current value is equal to expected one. +@warning_ignore("unused_parameter") func is_equal(expected) -> GdUnitObjectAssert: return self -# Verifies that the current value is not equal to expected one. + +## Verifies that the current value is not equal to expected one. +@warning_ignore("unused_parameter") func is_not_equal(expected) -> GdUnitObjectAssert: return self -# Verifies that the current value is null. + +## Verifies that the current value is null. func is_null() -> GdUnitObjectAssert: return self -# Verifies that the current value is not null. + +## Verifies that the current value is not null. func is_not_null() -> GdUnitObjectAssert: return self -# Verifies that the current value is the same as the given one. + +## Verifies that the current value is the same as the given one. +@warning_ignore("unused_parameter", "shadowed_global_identifier") func is_same(expected) -> GdUnitObjectAssert: return self -# Verifies that the current value is not the same as the given one. + +## Verifies that the current value is not the same as the given one. +@warning_ignore("unused_parameter") func is_not_same(expected) -> GdUnitObjectAssert: return self -# Verifies that the current value is an instance of the given type. + +## Verifies that the current value is an instance of the given type. +@warning_ignore("unused_parameter") func is_instanceof(expected :Object) -> GdUnitObjectAssert: return self -# Verifies that the current value is not an instance of the given type. + +## Verifies that the current value is not an instance of the given type. +@warning_ignore("unused_parameter") func is_not_instanceof(expected) -> GdUnitObjectAssert: return self diff --git a/addons/gdUnit4/src/GdUnitResultAssert.gd b/addons/gdUnit4/src/GdUnitResultAssert.gd index 271b8203..dc33d5f7 100644 --- a/addons/gdUnit4/src/GdUnitResultAssert.gd +++ b/addons/gdUnit4/src/GdUnitResultAssert.gd @@ -1,35 +1,45 @@ -# An Assertion Tool to verify Results +## An Assertion Tool to verify Results class_name GdUnitResultAssert extends GdUnitAssert -# Verifies that the current value is null. + +## Verifies that the current value is null. func is_null() -> GdUnitResultAssert: return self -# Verifies that the current value is not null. + +## Verifies that the current value is not null. func is_not_null() -> GdUnitResultAssert: return self -# Verifies that the result is ends up with empty + +## Verifies that the result is ends up with empty func is_empty() -> GdUnitResultAssert: return self -# Verifies that the result is ends up with success + +## Verifies that the result is ends up with success func is_success() -> GdUnitResultAssert: return self -# Verifies that the result is ends up with warning + +## Verifies that the result is ends up with warning func is_warning() -> GdUnitResultAssert: return self -# Verifies that the result is ends up with error + +## Verifies that the result is ends up with error func is_error() -> GdUnitResultAssert: return self -# Verifies that the result contains the given message + +## Verifies that the result contains the given message +@warning_ignore("unused_parameter") func contains_message(expected :String) -> GdUnitResultAssert: return self -# Verifies that the result contains the given value + +## Verifies that the result contains the given value +@warning_ignore("unused_parameter") func is_value(expected) -> GdUnitResultAssert: return self diff --git a/addons/gdUnit4/src/GdUnitSceneRunner.gd b/addons/gdUnit4/src/GdUnitSceneRunner.gd index 1fc8d815..f414dd73 100644 --- a/addons/gdUnit4/src/GdUnitSceneRunner.gd +++ b/addons/gdUnit4/src/GdUnitSceneRunner.gd @@ -1,157 +1,192 @@ +## The scene runner for GdUnit to simmulate scene interactions class_name GdUnitSceneRunner extends RefCounted const NO_ARG = GdUnitConstants.NO_ARG -func simulate(frames: int, delta_peer_frame :float) -> GdUnitSceneRunner: - push_warning("DEPRECATED!: 'simulate(, )' is deprecated. Use 'simulate_frames(, ) instead.'") - return simulate_frames(frames, delta_peer_frame * 1000) -func wait_emit_signal(instance :Object, signal_name :String, args := [], timeout := 2000, expeced := GdUnitAssert.EXPECT_SUCCESS): - push_warning("DEPRECATED!: 'wait_emit_signal(, , )' is deprecated. Use 'await_signal_on(, , ) instead.'") - return await await_signal_on(instance, signal_name, args, timeout).completed - -func wait_func(source :Object, func_name :String, args := [], expeced := GdUnitAssert.EXPECT_SUCCESS) -> GdUnitFuncAssert: - push_warning("DEPRECATED!: 'wait_func(, , )' is deprecated. Use 'await_func(, )' or 'await_func_on(, , )' instead.") - return await_func_on(source, func_name, args, expeced) - -# Sets the mouse cursor to given position relative to the viewport. +## Sets the mouse cursor to given position relative to the viewport. +@warning_ignore("unused_parameter") func set_mouse_pos(pos :Vector2) -> GdUnitSceneRunner: return self -# Gets the current mouse position of the current viewport + +## Gets the current mouse position of the current viewport func get_mouse_position() -> Vector2: return Vector2.ZERO -# Gets the current global mouse position of the current window +## Gets the current global mouse position of the current window func get_global_mouse_position() -> Vector2: return Vector2.ZERO -# Simulates that a key has been pressed -# key_code : the key code e.g. 'KEY_ENTER' -# shift_pressed : false by default set to true if simmulate shift is press -# ctrl_pressed : false by default set to true if simmulate control is press +## Simulates that a key has been pressed.[br] +## [member key_code] : the key code e.g. [constant KEY_ENTER][br] +## [member shift_pressed] : false by default set to true if simmulate shift is press[br] +## [member ctrl_pressed] : false by default set to true if simmulate control is press[br] +@warning_ignore("unused_parameter") func simulate_key_pressed(key_code :int, shift_pressed := false, ctrl_pressed := false) -> GdUnitSceneRunner: return self -# Simulates that a key is pressed -# key_code : the key code e.g. 'KEY_ENTER' -# shift_pressed : false by default set to true if simmulate shift is press -# ctrl_pressed : false by default set to true if simmulate control is press + +## Simulates that a key is pressed.[br] +## [member key_code] : the key code e.g. [constant KEY_ENTER][br] +## [member shift_pressed] : false by default set to true if simmulate shift is press[br] +## [member ctrl_pressed] : false by default set to true if simmulate control is press[br] +@warning_ignore("unused_parameter") func simulate_key_press(key_code :int, shift_pressed := false, ctrl_pressed := false) -> GdUnitSceneRunner: return self -# Simulates that a key has been released -# key_code : the key code e.g. 'KEY_ENTER' -# shift_pressed : false by default set to true if simmulate shift is press -# ctrl_pressed : false by default set to true if simmulate control is press + +## Simulates that a key has been released.[br] +## [member key_code] : the key code e.g. [constant KEY_ENTER][br] +## [member shift_pressed] : false by default set to true if simmulate shift is press[br] +## [member ctrl_pressed] : false by default set to true if simmulate control is press[br] +@warning_ignore("unused_parameter") func simulate_key_release(key_code :int, shift_pressed := false, ctrl_pressed := false) -> GdUnitSceneRunner: return self -# Simulates a mouse moved to final position -# pos: The final mouse position + +## Simulates a mouse moved to final position.[br] +## [member pos] : The final mouse position +@warning_ignore("unused_parameter") func simulate_mouse_move(pos :Vector2) -> GdUnitSceneRunner: return self -# Simulates a mouse move to the relative coordinates (offset) -# relative: The relative position, e.g. the mouse position offset -# speed : The mouse speed in pixels per second.‚ + +## Simulates a mouse move to the relative coordinates (offset).[br] +## [member relative] : The relative position, e.g. the mouse position offset[br] +## [member speed] : The mouse speed in pixels per second.[br] +@warning_ignore("unused_parameter") func simulate_mouse_move_relative(relative :Vector2, speed :Vector2 = Vector2.ONE) -> GdUnitSceneRunner: + await Engine.get_main_loop().process_frame return self -# Simulates a mouse button pressed -# buttonIndex: The mouse button identifier, one of the ButtonList button or button wheel constants. -func simulate_mouse_button_pressed(buttonIndex :int, double_click := false) -> GdUnitSceneRunner: + +## Simulates a mouse button pressed.[br] +## [member buttonIndex] : The mouse button identifier, one of the [enum MouseButton] or button wheel constants. +@warning_ignore("unused_parameter") +func simulate_mouse_button_pressed(buttonIndex :MouseButton, double_click := false) -> GdUnitSceneRunner: return self -# Simulates a mouse button press (holding) -# buttonIndex: The mouse button identifier, one of the ButtonList button or button wheel constants. -func simulate_mouse_button_press(buttonIndex :int, double_click := false) -> GdUnitSceneRunner: + +## Simulates a mouse button press (holding)[br] +## [member buttonIndex] : The mouse button identifier, one of the [enum MouseButton] or button wheel constants. +@warning_ignore("unused_parameter") +func simulate_mouse_button_press(buttonIndex :MouseButton, double_click := false) -> GdUnitSceneRunner: return self -# Simulates a mouse button released -# buttonIndex: The mouse button identifier, one of the ButtonList button or button wheel constants. -func simulate_mouse_button_release(buttonIndex :int) -> GdUnitSceneRunner: + +## Simulates a mouse button released.[br] +## [member buttonIndex] : The mouse button identifier, one of the [enum MouseButton] or button wheel constants. +@warning_ignore("unused_parameter") +func simulate_mouse_button_release(buttonIndex :MouseButton) -> GdUnitSceneRunner: return self -# Sets how fast or slow the scene simulation is processed (clock ticks versus the real). -# It defaults to 1.0. A value of 2.0 means the game moves twice as fast as real life, -# whilst a value of 0.5 means the game moves at half the regular speed. + +## Sets how fast or slow the scene simulation is processed (clock ticks versus the real).[br] +## It defaults to 1.0. A value of 2.0 means the game moves twice as fast as real life, +## whilst a value of 0.5 means the game moves at half the regular speed. +@warning_ignore("unused_parameter") func set_time_factor(time_factor := 1.0) -> GdUnitSceneRunner: return self -# Simulates scene processing for a certain number of frames -# frames: amount of frames to process -# delta_milli: the time delta between a frame in milliseconds + +## Simulates scene processing for a certain number of frames.[br] +## [member frames] : amount of frames to process[br] +## [member delta_milli] : the time delta between a frame in milliseconds +@warning_ignore("unused_parameter") func simulate_frames(frames: int, delta_milli :int = -1) -> GdUnitSceneRunner: + await Engine.get_main_loop().process_frame return self -# Simulates scene processing until the given signal is emitted by the scene -# signal_name: the signal to stop the simulation -# arg..: optional signal arguments to be matched for stop + +## Simulates scene processing until the given signal is emitted by the scene.[br] +## [member signal_name] : the signal to stop the simulation[br] +## [member args] : optional signal arguments to be matched for stop[br] +@warning_ignore("unused_parameter") func simulate_until_signal(signal_name :String, arg0=NO_ARG, arg1=NO_ARG, arg2=NO_ARG, arg3=NO_ARG, arg4=NO_ARG, arg5=NO_ARG, arg6=NO_ARG, arg7=NO_ARG, arg8=NO_ARG, arg9=NO_ARG) -> GdUnitSceneRunner: + await Engine.get_main_loop().process_frame return self -# Simulates scene processing until the given signal is emitted by the given object -# source: the object that should emit the signal -# signal_name: the signal to stop the simulation -# arg..: optional signal arguments to be matched for stop + +## Simulates scene processing until the given signal is emitted by the given object.[br] +## [member source] : the object that should emit the signal[br] +## [member signal_name] : the signal to stop the simulation[br] +## [member args] : optional signal arguments to be matched for stop +@warning_ignore("unused_parameter") func simulate_until_object_signal(source :Object, signal_name :String, arg0=NO_ARG, arg1=NO_ARG, arg2=NO_ARG, arg3=NO_ARG, arg4=NO_ARG, arg5=NO_ARG, arg6=NO_ARG, arg7=NO_ARG, arg8=NO_ARG, arg9=NO_ARG) -> GdUnitSceneRunner: + await Engine.get_main_loop().process_frame return self -# Waits for the function return value until specified timeout or fails -# args : optional function arguments + +## Waits for the function return value until specified timeout or fails.[br] +## [member args] : optional function arguments +@warning_ignore("unused_parameter") func await_func(func_name :String, args := [], expeced := GdUnitAssert.EXPECT_SUCCESS) -> GdUnitFuncAssert: return null -# Waits for the function return value of specified source until specified timeout or fails -# source: the object where implements the function -# args : optional function arguments + +## Waits for the function return value of specified source until specified timeout or fails.[br] +## [member source : the object where implements the function[br] +## [member args] : optional function arguments +@warning_ignore("unused_parameter") func await_func_on(source :Object, func_name :String, args := [], expeced := GdUnitAssert.EXPECT_SUCCESS) -> GdUnitFuncAssert: return null -# Waits for given signal is emited by the scene until a specified timeout to fail -# signal_name: signal name -# args: the expected signal arguments as an array -# timeout: the timeout in ms, default is set to 2000ms + +## Waits for given signal is emited by the scene until a specified timeout to fail.[br] +## [member signal_name] : signal name[br] +## [member args] : the expected signal arguments as an array[br] +## [member timeout] : the timeout in ms, default is set to 2000ms +@warning_ignore("unused_parameter") func await_signal(signal_name :String, args := [], timeout := 2000 ): + await Engine.get_main_loop().process_frame pass -# Waits for given signal is emited by the until a specified timeout to fail -# source: the object from which the signal is emitted -# signal_name: signal name -# args: the expected signal arguments as an array -# timeout: the timeout in ms, default is set to 2000ms + +## Waits for given signal is emited by the until a specified timeout to fail.[br] +## [member source] : the object from which the signal is emitted[br] +## [member signal_name] : signal name[br] +## [member args] : the expected signal arguments as an array[br] +## [member timeout] : the timeout in ms, default is set to 2000ms +@warning_ignore("unused_parameter") func await_signal_on(source :Object, signal_name :String, args := [], timeout := 2000 ): pass -# maximizes the window to bring the scene visible + +## maximizes the window to bring the scene visible func maximize_view() -> GdUnitSceneRunner: return self -# Return the current value of the property with the name . -# name: name of property -# retuen: the value of the property -func get_property(name :String): - pass -# executes the function specified by in the scene and returns the result -# name: the name of the function to execute -# optional function args 0..9 -# return: the function result +## Return the current value of the property with the name .[br] +## [member name] : name of property[br] +## [member return] : the value of the property +@warning_ignore("unused_parameter") +func get_property(name :String) -> Variant: + return null + + +## executes the function specified by in the scene and returns the result.[br] +## [member name] : the name of the function to execute[br] +## [member args] : optional function arguments[br] +## [member return] : the function result +@warning_ignore("unused_parameter") func invoke(name :String, arg0=NO_ARG, arg1=NO_ARG, arg2=NO_ARG, arg3=NO_ARG, arg4=NO_ARG, arg5=NO_ARG, arg6=NO_ARG, arg7=NO_ARG, arg8=NO_ARG, arg9=NO_ARG): pass -# Searches for the specified node with the name in the current scene and returns it, otherwise null -# name: the name of the node to find -# recursive: enables/disables seraching recursive -# return: the node if find otherwise null + +## Searches for the specified node with the name in the current scene and returns it, otherwise null.[br] +## [member name] : the name of the node to find[br] +## [member recursive] : enables/disables seraching recursive[br] +## [member return] : the node if find otherwise null +@warning_ignore("unused_parameter") func find_child(name :String, recursive :bool = true, owned :bool = false) -> Node: return null -# Access to current running scene + +## Access to current running scene func scene() -> Node: return null - diff --git a/addons/gdUnit4/src/GdUnitSignalAssert.gd b/addons/gdUnit4/src/GdUnitSignalAssert.gd index ce182b86..35cb6e25 100644 --- a/addons/gdUnit4/src/GdUnitSignalAssert.gd +++ b/addons/gdUnit4/src/GdUnitSignalAssert.gd @@ -1,34 +1,50 @@ -# An Assertion Tool to verify for emitted signals until a waiting time +## An Assertion Tool to verify for emitted signals until a waiting time class_name GdUnitSignalAssert extends GdUnitAssert -# Verifies that given signal is emitted until waiting time + +## Verifies that given signal is emitted until waiting time +@warning_ignore("unused_parameter") func is_emitted(name :String, args := []) -> GdUnitSignalAssert: + await Engine.get_main_loop().process_frame return self -# Verifies that given signal is NOT emitted until waiting time + +## Verifies that given signal is NOT emitted until waiting time +@warning_ignore("unused_parameter") func is_not_emitted(name :String, args := []) -> GdUnitSignalAssert: + await Engine.get_main_loop().process_frame return self -# Verifies the signal exists checked the emitter + +## Verifies the signal exists checked the emitter +@warning_ignore("unused_parameter") func is_signal_exists(name :String) -> GdUnitSignalAssert: return self -# Verifies the failure message is equal to expected one. + +## Verifies the failure message is equal to expected one. +@warning_ignore("unused_parameter") func has_failure_message(expected: String) -> GdUnitSignalAssert: return self -# Verifies that the failure starts with the given prefix. + +## Verifies that the failure starts with the given prefix. +@warning_ignore("unused_parameter") func starts_with_failure_message(expected: String) -> GdUnitSignalAssert: return self -# Overrides the default failure message by given custom message. + +## Overrides the default failure message by given custom message. +@warning_ignore("unused_parameter") func override_failure_message(message :String) -> GdUnitSignalAssert: return self -# Sets the assert signal timeout in ms, if the time over a failure is reported -# e.g. -# do wait until 5s the instance has emitted the signal `signal_a` -# assert_signal(instance).wait_until(5000).is_emitted("signal_a") + +## Sets the assert signal timeout in ms, if the time over a failure is reported.[br] +## e.g.[br] +## do wait until 5s the instance has emitted the signal `signal_a`[br] +## [code]assert_signal(instance).wait_until(5000).is_emitted("signal_a")[/code] +@warning_ignore("unused_parameter") func wait_until(timeout :int) -> GdUnitSignalAssert: return self diff --git a/addons/gdUnit4/src/GdUnitStringAssert.gd b/addons/gdUnit4/src/GdUnitStringAssert.gd index ce5fecc3..91e5bf0a 100644 --- a/addons/gdUnit4/src/GdUnitStringAssert.gd +++ b/addons/gdUnit4/src/GdUnitStringAssert.gd @@ -1,55 +1,79 @@ -# An Assertion Tool to verify String values +## An Assertion Tool to verify String values class_name GdUnitStringAssert extends GdUnitAssert -# Verifies that the current String is equal to the given one. + +## Verifies that the current String is equal to the given one. +@warning_ignore("unused_parameter") func is_equal(expected) -> GdUnitStringAssert: return self -# Verifies that the current String is equal to the given one, ignoring case considerations. + +## Verifies that the current String is equal to the given one, ignoring case considerations. +@warning_ignore("unused_parameter") func is_equal_ignoring_case(expected) -> GdUnitStringAssert: return self -# Verifies that the current String is not equal to the given one. + +## Verifies that the current String is not equal to the given one. +@warning_ignore("unused_parameter") func is_not_equal(expected) -> GdUnitStringAssert: return self -# Verifies that the current String is not equal to the given one, ignoring case considerations. + +## Verifies that the current String is not equal to the given one, ignoring case considerations. +@warning_ignore("unused_parameter") func is_not_equal_ignoring_case(expected) -> GdUnitStringAssert: return self -# Verifies that the current String is empty, it has a length of 0. + +## Verifies that the current String is empty, it has a length of 0. func is_empty() -> GdUnitStringAssert: return self -# Verifies that the current String is not empty, it has a length of minimum 1. + +## Verifies that the current String is not empty, it has a length of minimum 1. func is_not_empty() -> GdUnitStringAssert: return self -# Verifies that the current String contains the given String. + +## Verifies that the current String contains the given String. +@warning_ignore("unused_parameter") func contains(expected: String) -> GdUnitStringAssert: return self -# Verifies that the current String does not contain the given String. + +## Verifies that the current String does not contain the given String. +@warning_ignore("unused_parameter") func not_contains(expected: String) -> GdUnitStringAssert: return self -# Verifies that the current String does not contain the given String, ignoring case considerations. + +## Verifies that the current String does not contain the given String, ignoring case considerations. +@warning_ignore("unused_parameter") func contains_ignoring_case(expected: String) -> GdUnitStringAssert: return self -# Verifies that the current String does not contain the given String, ignoring case considerations. + +## Verifies that the current String does not contain the given String, ignoring case considerations. +@warning_ignore("unused_parameter") func not_contains_ignoring_case(expected: String) -> GdUnitStringAssert: return self -# Verifies that the current String starts with the given prefix. + +## Verifies that the current String starts with the given prefix. +@warning_ignore("unused_parameter") func starts_with(expected: String) -> GdUnitStringAssert: return self -# Verifies that the current String ends with the given suffix. + +## Verifies that the current String ends with the given suffix. +@warning_ignore("unused_parameter") func ends_with(expected: String) -> GdUnitStringAssert: return self -# Verifies that the current String has the expected length by used comparator. + +## Verifies that the current String has the expected length by used comparator. +@warning_ignore("unused_parameter") func has_length(lenght: int, comparator: int = Comparator.EQUAL) -> GdUnitStringAssert: return self diff --git a/addons/gdUnit4/src/GdUnitTestSuite.gd b/addons/gdUnit4/src/GdUnitTestSuite.gd index 216d5122..75ea46ed 100644 --- a/addons/gdUnit4/src/GdUnitTestSuite.gd +++ b/addons/gdUnit4/src/GdUnitTestSuite.gd @@ -1,19 +1,15 @@ +## The main class for all GdUnit test suites[br] +## This class is the main class to implement your unit tests[br] +## You have to extend and implement your test cases as described[br] +## e.g MyTests.gd [br] +## [codeblock] +## extends GdUnitTestSuite +## # +## func test_testCaseA(): +## assert_that("value").is_equal("value") +## [/codeblock][br] +## @tutorial: https://mikeschulze.github.io/gdUnit3/faq/test-suite/ -## Main class for all GdUnit test suites - -################################################################################# -# This class is the main class to implement your unit tests -# You have to extend and implement your test cases as described -# e.g -# --- MyTests.gd---------------------------------------------------------------- -# extends GdUnitTestSuite -# -# func test_testCaseA(): -# assert_that("value").is_equal("value") -# -#------------------------------------------------------------------------------- -# For detailed instructions show http://gdUnit/plapla -################################################################################ @icon("res://addons/gdUnit4/src/ui/assets/TestSuite.svg") class_name GdUnitTestSuite extends Node @@ -21,96 +17,113 @@ extends Node const NO_ARG = GdUnitConstants.NO_ARG -# This function is called before a test suite starts -# You can overwrite to prepare test data or initalizize necessary variables +## This function is called before a test suite starts[br] +## You can overwrite to prepare test data or initalizize necessary variables func before() -> void: pass -# This function is called at least when a test suite is finished -# You can overwrite to cleanup data created during test running + +## This function is called at least when a test suite is finished[br] +## You can overwrite to cleanup data created during test running func after() -> void: pass -# This function is called before a test case starts -# You can overwrite to prepare test case specific data + +## This function is called before a test case starts[br] +## You can overwrite to prepare test case specific data func before_test() -> void: pass -# This function is called after the test case is finished -# You can overwrite to cleanup your test case specific data + +## This function is called after the test case is finished[br] +## You can overwrite to cleanup your test case specific data func after_test() -> void: pass -# Skip the test-suite from execution, it will be ignored + +## Skip the test-suite from execution, it will be ignored func skip(skipped :bool) -> void: set_meta("gd_skipped", skipped) + func is_failure(_expected_failure :String = NO_ARG) -> bool: return Engine.get_meta("GD_TEST_FAILURE") if Engine.has_meta("GD_TEST_FAILURE") else false + func is_skipped() -> bool: return get_meta("gd_skipped") if has_meta("gd_skipped") else false + var __active_test_case :String func set_active_test_case(test_case :String) -> void: __active_test_case = test_case + # === Tools ==================================================================== # Mapps Godot error number to a readable error message. See at ERROR # https://docs.godotengine.org/de/stable/classes/class_@globalscope.html#enum-globalscope-error func error_as_string(error_number :int) -> String: return GdUnitTools.error_as_string(error_number) -# A litle helper to auto freeing your created objects after test execution + +## A litle helper to auto freeing your created objects after test execution func auto_free(obj) -> Variant: return GdUnitMemoryPool.register_auto_free(obj, get_meta(GdUnitMemoryPool.META_PARAM)) -# Discard the error message triggered by a timeout (interruption). -# By default, an interrupted test is reported as an error. -# This function allows you to change the message to Success when an interrupted error is reported. + +## Discard the error message triggered by a timeout (interruption).[br] +## By default, an interrupted test is reported as an error.[br] +## This function allows you to change the message to Success when an interrupted error is reported. func discard_error_interupted_by_timeout() -> void: GdUnitTools.register_expect_interupted_by_timeout(self, __active_test_case) -# Creates a new directory under the temporary directory *user://tmp* -# Useful for storing data during test execution. -# The directory is automatically deleted after test suite execution + +## Creates a new directory under the temporary directory *user://tmp*[br] +## Useful for storing data during test execution. [br] +## The directory is automatically deleted after test suite execution func create_temp_dir(relative_path :String) -> String: return GdUnitTools.create_temp_dir(relative_path) -# Deletes the temporary base directory -# Is called automatically after each execution of the test suite + +## Deletes the temporary base directory[br] +## Is called automatically after each execution of the test suite func clean_temp_dir(): GdUnitTools.clear_tmp() - -# Creates a new file under the temporary directory *user://tmp* + -# with given name and given file (default = File.WRITE) -# If success the returned File is automatically closed after the execution of the test suite + + +## Creates a new file under the temporary directory *user://tmp* + [br] +## with given name and given file (default = File.WRITE)[br] +## If success the returned File is automatically closed after the execution of the test suite func create_temp_file(relative_path :String, file_name :String, mode := FileAccess.WRITE) -> FileAccess: return GdUnitTools.create_temp_file(relative_path, file_name, mode) -# Reads a resource by given path into a PackedStringArray. + +## Reads a resource by given path into a PackedStringArray. func resource_as_array(resource_path :String) -> PackedStringArray: return GdUnitTools.resource_as_array(resource_path) -# Reads a resource by given path and returned the content as String. + +## Reads a resource by given path and returned the content as String. func resource_as_string(resource_path :String) -> String: return GdUnitTools.resource_as_string(resource_path) -# Reads a resource by given path and return Variand translated by str_to_var + +## Reads a resource by given path and return Variand translated by str_to_var func resource_as_var(resource_path :String): return str_to_var(GdUnitTools.resource_as_string(resource_path)) -# clears the debuger error list -# PROTOTYPE!!!! Don't use it for now + +## clears the debuger error list[br] +## PROTOTYPE!!!! Don't use it for now func clear_push_errors() -> void: GdUnitTools.clear_push_errors() -# Waits for given signal is emited by the until a specified timeout to fail -# source: the object from which the signal is emitted -# signal_name: signal name -# args: the expected signal arguments as an array -# timeout: the timeout in ms, default is set to 2000ms +## Waits for given signal is emited by the until a specified timeout to fail[br] +## source: the object from which the signal is emitted[br] +## signal_name: signal name[br] +## args: the expected signal arguments as an array[br] +## timeout: the timeout in ms, default is set to 2000ms func await_signal_on(source :Object, signal_name :String, args :Array = [], timeout :int = 2000) -> Variant: # fail fast if the given source instance invalid if not is_instance_valid(source): @@ -120,191 +133,235 @@ func await_signal_on(source :Object, signal_name :String, args :Array = [], time return await GdUnitAwaiter.await_signal_on(source, signal_name, args, timeout) -# Waits until the next idle frame +## Waits until the next idle frame func await_idle_frame(): await GdUnitAwaiter.await_idle_frame() -# Waits for for a given amount of milliseconds -# example: -# # waits for 100ms -# await await_millis(myNode, 100).completed -# use this waiter and not `await get_tree().create_timer().timeout to prevent errors when a test case is timed out + +## Waits for for a given amount of milliseconds[br] +## example:[br] +## [codeblock] +## # waits for 100ms +## await await_millis(myNode, 100).completed +## [/codeblock][br] +## use this waiter and not `await get_tree().create_timer().timeout to prevent errors when a test case is timed out func await_millis(timeout :int): await GdUnitAwaiter.await_millis(timeout) -# Creates a new scene runner to allow simulate interactions checked a scene. -# The runner will manage the scene instance and release after the runner is released -# example: -# # creates a runner by using a instanciated scene -# var scene = load("res://foo/my_scne.tscn").instantiate() -# var runner := scene_runner(scene) -# -# # or simply creates a runner by using the scene resource path -# var runner := scene_runner("res://foo/my_scne.tscn") + +## Creates a new scene runner to allow simulate interactions checked a scene.[br] +## The runner will manage the scene instance and release after the runner is released[br] +## example:[br] +## [codeblock] +## # creates a runner by using a instanciated scene +## var scene = load("res://foo/my_scne.tscn").instantiate() +## var runner := scene_runner(scene) +## +## # or simply creates a runner by using the scene resource path +## var runner := scene_runner("res://foo/my_scne.tscn") +## [/codeblock] func scene_runner(scene, verbose := false) -> GdUnitSceneRunner: return auto_free(GdUnitSceneRunnerImpl.new(scene, verbose)) + # === Mocking & Spy =========================================================== -# do return a default value for primitive types or null +## do return a default value for primitive types or null const RETURN_DEFAULTS = GdUnitMock.RETURN_DEFAULTS -# do call the real implementation +## do call the real implementation const CALL_REAL_FUNC = GdUnitMock.CALL_REAL_FUNC -# do return a default value for primitive types and a fully mocked value for Object types -# builds full deep mocked object +## do return a default value for primitive types and a fully mocked value for Object types +## builds full deep mocked object const RETURN_DEEP_STUB = GdUnitMock.RETURN_DEEP_STUB -# Creates a mock for given class name + +## Creates a mock for given class name func mock(clazz, mock_mode := RETURN_DEFAULTS) -> Object: return GdUnitMockBuilder.build(self, clazz, mock_mode) -# Creates a spy checked given object instance + +## Creates a spy checked given object instance func spy(instance): return GdUnitSpyBuilder.build(self, instance) -# Configures a return value for the specified function and used arguments. + +## Configures a return value for the specified function and used arguments. func do_return(value) -> GdUnitMock: return GdUnitMock.new(value) -# Verifies certain behavior happened at least once or exact number of times + +## Verifies certain behavior happened at least once or exact number of times func verify(obj, times := 1, expect_result :int = GdUnitAssert.EXPECT_SUCCESS): return GdUnitObjectInteractions.verify(obj, times, expect_result) -# Verifies no interactions is happen checked this mock or spy + +## Verifies no interactions is happen checked this mock or spy func verify_no_interactions(obj, expect_result :int = GdUnitAssert.EXPECT_SUCCESS) -> GdUnitAssert: return GdUnitObjectInteractions.verify_no_interactions(obj, expect_result) -# Verifies the given mock or spy has any unverified interaction. + +## Verifies the given mock or spy has any unverified interaction. func verify_no_more_interactions(obj, expect_result :int = GdUnitAssert.EXPECT_SUCCESS) -> GdUnitAssert: return GdUnitObjectInteractions.verify_no_more_interactions(obj, expect_result) -# Resets the saved function call counters checked a mock or spy + +## Resets the saved function call counters checked a mock or spy func reset(obj) -> void: GdUnitObjectInteractions.reset(obj) + # === Argument matchers ======================================================== -# Argument matcher to match any argument -static func any() -> GdUnitArgumentMatcher: +## Argument matcher to match any argument +func any() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.any() -# Argument matcher to match any boolean value -static func any_bool() -> GdUnitArgumentMatcher: + +## Argument matcher to match any boolean value +func any_bool() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_BOOL) -# Argument matcher to match any integer value -static func any_int() -> GdUnitArgumentMatcher: + +## Argument matcher to match any integer value +func any_int() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_INT) -# Argument matcher to match any float value -static func any_float() -> GdUnitArgumentMatcher: + +## Argument matcher to match any float value +func any_float() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_FLOAT) -# Argument matcher to match any string value -static func any_string() -> GdUnitArgumentMatcher: + +## Argument matcher to match any string value +func any_string() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_STRING) -# Argument matcher to match any Color value -static func any_color() -> GdUnitArgumentMatcher: + +## Argument matcher to match any Color value +func any_color() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_COLOR) -# Argument matcher to match any Vector2 value -static func any_vector2() -> GdUnitArgumentMatcher: + +## Argument matcher to match any Vector2 value +func any_vector2() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_VECTOR2) -# Argument matcher to match any Vector3 value -static func any_vector3() -> GdUnitArgumentMatcher: + +## Argument matcher to match any Vector3 value +func any_vector3() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_VECTOR3) -# Argument matcher to match any Rect2 value -static func any_rect2() -> GdUnitArgumentMatcher: + +## Argument matcher to match any Rect2 value +func any_rect2() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_RECT2) -# Argument matcher to match any Plane value -static func any_plane() -> GdUnitArgumentMatcher: + +## Argument matcher to match any Plane value +func any_plane() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_PLANE) -# Argument matcher to match any Quaternion value -static func any_quat() -> GdUnitArgumentMatcher: + +## Argument matcher to match any Quaternion value +func any_quat() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_QUATERNION) -# Argument matcher to match any AABB value -static func any_aabb() -> GdUnitArgumentMatcher: + +## Argument matcher to match any AABB value +func any_aabb() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_AABB) -# Argument matcher to match any Basis value -static func any_basis() -> GdUnitArgumentMatcher: + +## Argument matcher to match any Basis value +func any_basis() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_BASIS) -# Argument matcher to match any Transform3D value -static func any_transform() -> GdUnitArgumentMatcher: + +## Argument matcher to match any Transform3D value +func any_transform() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_TRANSFORM3D) -# Argument matcher to match any Transform2D value -static func any_transform_2d() -> GdUnitArgumentMatcher: + +## Argument matcher to match any Transform2D value +func any_transform_2d() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_TRANSFORM2D) -# Argument matcher to match any NodePath value -static func any_node_path() -> GdUnitArgumentMatcher: + +## Argument matcher to match any NodePath value +func any_node_path() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_NODE_PATH) -# Argument matcher to match any RID value -static func any_rid() -> GdUnitArgumentMatcher: + +## Argument matcher to match any RID value +func any_rid() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_RID) -# Argument matcher to match any Object value -static func any_object() -> GdUnitArgumentMatcher: + +## Argument matcher to match any Object value +func any_object() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_OBJECT) -# Argument matcher to match any Dictionary value -static func any_dictionary() -> GdUnitArgumentMatcher: + +## Argument matcher to match any Dictionary value +func any_dictionary() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_DICTIONARY) -# Argument matcher to match any Array value -static func any_array() -> GdUnitArgumentMatcher: + +## Argument matcher to match any Array value +func any_array() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_ARRAY) -# Argument matcher to match any PackedByteArray value -static func any_pool_byte_array() -> GdUnitArgumentMatcher: + +## Argument matcher to match any PackedByteArray value +func any_pool_byte_array() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_PACKED_BYTE_ARRAY) -# Argument matcher to match any PackedInt32Array value -static func any_pool_int_array() -> GdUnitArgumentMatcher: + +## Argument matcher to match any PackedInt32Array value +func any_pool_int_array() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_PACKED_INT32_ARRAY) -# Argument matcher to match any PackedFloat32Array value -static func any_pool_float_array() -> GdUnitArgumentMatcher: + +## Argument matcher to match any PackedFloat32Array value +func any_pool_float_array() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_PACKED_FLOAT32_ARRAY) -# Argument matcher to match any PackedStringArray value -static func any_pool_string_array() -> GdUnitArgumentMatcher: + +## Argument matcher to match any PackedStringArray value +func any_pool_string_array() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_PACKED_STRING_ARRAY) -# Argument matcher to match any PackedVector2Array value -static func any_pool_vector2_array() -> GdUnitArgumentMatcher: + +## Argument matcher to match any PackedVector2Array value +func any_pool_vector2_array() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_PACKED_VECTOR2_ARRAY) -# Argument matcher to match any PackedVector3Array value -static func any_pool_vector3_array() -> GdUnitArgumentMatcher: + +## Argument matcher to match any PackedVector3Array value +func any_pool_vector3_array() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_PACKED_VECTOR3_ARRAY) -# Argument matcher to match any PackedColorArray value -static func any_pool_color_array() -> GdUnitArgumentMatcher: + +## Argument matcher to match any PackedColorArray value +func any_pool_color_array() -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.by_type(TYPE_PACKED_COLOR_ARRAY) -# Argument matcher to match any instance of given class -static func any_class(clazz :Object) -> GdUnitArgumentMatcher: + +## Argument matcher to match any instance of given class +func any_class(clazz :Object) -> GdUnitArgumentMatcher: return GdUnitArgumentMatchers.any_class(clazz) # === value extract utils ====================================================== -# Builds an extractor by given function name and optional arguments -static func extr(func_name :String, args := Array()) -> GdUnitValueExtractor: +## Builds an extractor by given function name and optional arguments +func extr(func_name :String, args := Array()) -> GdUnitValueExtractor: return GdUnitFuncValueExtractor.new(func_name, args) -# Constructs a tuple by given arguments -static func tuple(arg0, arg1=GdUnitTuple.NO_ARG, arg2=GdUnitTuple.NO_ARG, arg3=GdUnitTuple.NO_ARG, arg4=GdUnitTuple.NO_ARG, arg5=GdUnitTuple.NO_ARG, arg6=GdUnitTuple.NO_ARG, arg7=GdUnitTuple.NO_ARG, arg8=GdUnitTuple.NO_ARG, arg9=GdUnitTuple.NO_ARG) -> GdUnitTuple: + +## Constructs a tuple by given arguments +func tuple(arg0, arg1=GdUnitTuple.NO_ARG, arg2=GdUnitTuple.NO_ARG, arg3=GdUnitTuple.NO_ARG, arg4=GdUnitTuple.NO_ARG, arg5=GdUnitTuple.NO_ARG, arg6=GdUnitTuple.NO_ARG, arg7=GdUnitTuple.NO_ARG, arg8=GdUnitTuple.NO_ARG, arg9=GdUnitTuple.NO_ARG) -> GdUnitTuple: return GdUnitTuple.new(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) + # === Asserts ================================================================== func assert_that(current, expect_result: int = GdUnitAssert.EXPECT_SUCCESS) -> GdUnitAssert: @@ -333,50 +390,65 @@ func assert_that(current, expect_result: int = GdUnitAssert.EXPECT_SUCCESS) -> G _: return GdUnitAssertImpl.new(current, expect_result) + func assert_bool(current, expect_result: int = GdUnitAssert.EXPECT_SUCCESS) -> GdUnitBoolAssert: return GdUnitBoolAssertImpl.new(current, expect_result) + func assert_str(current, expect_result: int = GdUnitAssert.EXPECT_SUCCESS) -> GdUnitStringAssert: return GdUnitStringAssertImpl.new(current, expect_result) + func assert_int(current, expect_result: int = GdUnitAssert.EXPECT_SUCCESS) -> GdUnitIntAssert: return GdUnitIntAssertImpl.new(current, expect_result) + func assert_float(current, expect_result: int = GdUnitAssert.EXPECT_SUCCESS) -> GdUnitFloatAssert: return GdUnitFloatAssertImpl.new(current, expect_result) + func assert_vector2(current, expect_result: int = GdUnitAssert.EXPECT_SUCCESS) -> GdUnitVector2Assert: return GdUnitVector2AssertImpl.new(current, expect_result) + func assert_vector3(current, expect_result: int = GdUnitAssert.EXPECT_SUCCESS) -> GdUnitVector3Assert: return GdUnitVector3AssertImpl.new(current, expect_result) + func assert_array(current, expect_result: int = GdUnitAssert.EXPECT_SUCCESS) -> GdUnitArrayAssert: return GdUnitArrayAssertImpl.new(current, expect_result) + func assert_dict(current, expect_result: int = GdUnitAssert.EXPECT_SUCCESS) -> GdUnitDictionaryAssert: return GdUnitDictionaryAssertImpl.new(current, expect_result) + func assert_file(current, expect_result: int = GdUnitAssert.EXPECT_SUCCESS) -> GdUnitFileAssert: return GdUnitFileAssertImpl.new(current, expect_result) + func assert_object(current, expect_result: int = GdUnitAssert.EXPECT_SUCCESS) -> GdUnitObjectAssert: return GdUnitObjectAssertImpl.new(current, expect_result) + func assert_result(current, expect_result: int = GdUnitAssert.EXPECT_SUCCESS) -> GdUnitResultAssert: return GdUnitResultAssertImpl.new(current, expect_result) + func assert_func(instance :Object, func_name :String, args := Array(), expect_result :int = GdUnitAssert.EXPECT_SUCCESS) -> GdUnitFuncAssert: return GdUnitFuncAssertImpl.new(instance, func_name, args, expect_result) + func assert_signal(instance :Object, expect_result :int = GdUnitAssert.EXPECT_SUCCESS) -> GdUnitSignalAssert: return GdUnitSignalAssertImpl.new(instance, expect_result) + # TODO see https://github.com/MikeSchulze/gdUnit4/issues/4 func assert_fail(assertion :GdUnitAssert) -> GdUnitAssert: return assertion -# Utility to check if a test has failed in a particular line and if there is an error message + +## Utility to check if a test has failed in a particular line and if there is an error message func assert_failed_at(line_number :int, expected_failure :String) -> bool: var is_failed = is_failure() var last_failure = GdAssertReports.current_failure() @@ -389,9 +461,11 @@ func assert_failed_at(line_number :int, expected_failure :String) -> bool: func assert_not_yet_implemented(): GdUnitAssertImpl.new(null).test_fail() + func fail(message :String): GdUnitAssertImpl.new(null).report_error(message) + # --- internal stuff do not override!!! func ResourcePath() -> String: return get_script().resource_path diff --git a/addons/gdUnit4/src/GdUnitTuple.gd b/addons/gdUnit4/src/GdUnitTuple.gd index 2c8db142..e7f1bae7 100644 --- a/addons/gdUnit4/src/GdUnitTuple.gd +++ b/addons/gdUnit4/src/GdUnitTuple.gd @@ -1,4 +1,4 @@ -# A tuple implementation to hold two or many values +## A tuple implementation to hold two or many values class_name GdUnitTuple extends RefCounted @@ -6,11 +6,14 @@ const NO_ARG :Variant = GdUnitConstants.NO_ARG var __values :Array = Array() + func _init(arg0,arg1,arg2=NO_ARG,arg3=NO_ARG,arg4=NO_ARG,arg5=NO_ARG,arg6=NO_ARG,arg7=NO_ARG,arg8=NO_ARG,arg9=NO_ARG): __values = GdObjects.array_filter_value([arg0,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9], NO_ARG) + func values() -> Array: return __values + func _to_string(): return "tuple(%s)" % str(__values) diff --git a/addons/gdUnit4/src/GdUnitValueExtractor.gd b/addons/gdUnit4/src/GdUnitValueExtractor.gd index f3154224..be702cf7 100644 --- a/addons/gdUnit4/src/GdUnitValueExtractor.gd +++ b/addons/gdUnit4/src/GdUnitValueExtractor.gd @@ -1,8 +1,9 @@ -# This is the base interface for value extraction +## This is the base interface for value extraction class_name GdUnitValueExtractor extends RefCounted -# Extracts a value by given implementation + +## Extracts a value by given implementation func extract_value(value): push_error("Uninplemented func 'extract_value'") return value diff --git a/addons/gdUnit4/src/GdUnitVector2Assert.gd b/addons/gdUnit4/src/GdUnitVector2Assert.gd index f282e660..ef5297f7 100644 --- a/addons/gdUnit4/src/GdUnitVector2Assert.gd +++ b/addons/gdUnit4/src/GdUnitVector2Assert.gd @@ -1,38 +1,57 @@ +## An Assertion Tool to verify Vector2 values class_name GdUnitVector2Assert extends GdUnitAssert -# Verifies that the current value is equal to expected one. + +## Verifies that the current value is equal to expected one. +@warning_ignore("unused_parameter") func is_equal(expected :Vector2) -> GdUnitVector2Assert: return self -# Verifies that the current value is not equal to expected one. + +## Verifies that the current value is not equal to expected one. +@warning_ignore("unused_parameter") func is_not_equal(expected :Vector2) -> GdUnitVector2Assert: return self -# Verifies that the current and expected value are approximately equal. + +## Verifies that the current and expected value are approximately equal. +@warning_ignore("unused_parameter", "shadowed_global_identifier") func is_equal_approx(expected :Vector2, approx :Vector2) -> GdUnitVector2Assert: return self -# Verifies that the current value is less than the given one. + +## Verifies that the current value is less than the given one. +@warning_ignore("unused_parameter") func is_less(expected :Vector2) -> GdUnitVector2Assert: return self -# Verifies that the current value is less than or equal the given one. + +## Verifies that the current value is less than or equal the given one. +@warning_ignore("unused_parameter") func is_less_equal(expected :Vector2) -> GdUnitVector2Assert: return self -# Verifies that the current value is greater than the given one. + +## Verifies that the current value is greater than the given one. +@warning_ignore("unused_parameter") func is_greater(expected :Vector2) -> GdUnitVector2Assert: return self -# Verifies that the current value is greater than or equal the given one. + +## Verifies that the current value is greater than or equal the given one. +@warning_ignore("unused_parameter") func is_greater_equal(expected :Vector2) -> GdUnitVector2Assert: return self -# Verifies that the current value is between the given boundaries (inclusive). + +## Verifies that the current value is between the given boundaries (inclusive). +@warning_ignore("unused_parameter") func is_between(from :Vector2, to :Vector2) -> GdUnitVector2Assert: return self -# Verifies that the current value is not between the given boundaries (inclusive). + +## Verifies that the current value is not between the given boundaries (inclusive). +@warning_ignore("unused_parameter") func is_not_between(from :Vector2, to :Vector2) -> GdUnitVector2Assert: return self diff --git a/addons/gdUnit4/src/GdUnitVector3Assert.gd b/addons/gdUnit4/src/GdUnitVector3Assert.gd index 7f7c0e83..67d81814 100644 --- a/addons/gdUnit4/src/GdUnitVector3Assert.gd +++ b/addons/gdUnit4/src/GdUnitVector3Assert.gd @@ -1,38 +1,56 @@ +## An Assertion Tool to verify Vector3 values class_name GdUnitVector3Assert extends GdUnitAssert -# Verifies that the current value is equal to expected one. +## Verifies that the current value is equal to expected one. +@warning_ignore("unused_parameter") func is_equal(expected :Vector3) -> GdUnitVector3Assert: return self -# Verifies that the current value is not equal to expected one. + +## Verifies that the current value is not equal to expected one. +@warning_ignore("unused_parameter") func is_not_equal(expected :Vector3) -> GdUnitVector3Assert: return self -# Verifies that the current and expected value are approximately equal. + +## Verifies that the current and expected value are approximately equal. +@warning_ignore("unused_parameter", "shadowed_global_identifier") func is_equal_approx(expected :Vector3, approx :Vector3) -> GdUnitVector3Assert: return self -# Verifies that the current value is less than the given one. + +## Verifies that the current value is less than the given one. +@warning_ignore("unused_parameter") func is_less(expected :Vector3) -> GdUnitVector3Assert: return self -# Verifies that the current value is less than or equal the given one. + +## Verifies that the current value is less than or equal the given one. +@warning_ignore("unused_parameter") func is_less_equal(expected :Vector3) -> GdUnitVector3Assert: return self -# Verifies that the current value is greater than the given one. + +## Verifies that the current value is greater than the given one. +@warning_ignore("unused_parameter") func is_greater(expected :Vector3) -> GdUnitVector3Assert: return self -# Verifies that the current value is greater than or equal the given one. + +## Verifies that the current value is greater than or equal the given one. +@warning_ignore("unused_parameter") func is_greater_equal(expected :Vector3) -> GdUnitVector3Assert: return self -# Verifies that the current value is between the given boundaries (inclusive). + +## Verifies that the current value is between the given boundaries (inclusive). +@warning_ignore("unused_parameter") func is_between(from :Vector3, to :Vector3) -> GdUnitVector3Assert: return self -# Verifies that the current value is not between the given boundaries (inclusive). + +## Verifies that the current value is not between the given boundaries (inclusive). +@warning_ignore("unused_parameter") func is_not_between(from :Vector3, to :Vector3) -> GdUnitVector3Assert: return self diff --git a/addons/gdUnit4/src/asserts/CallBackValueProvider.gd b/addons/gdUnit4/src/asserts/CallBackValueProvider.gd index 41b87e66..f5b1d076 100644 --- a/addons/gdUnit4/src/asserts/CallBackValueProvider.gd +++ b/addons/gdUnit4/src/asserts/CallBackValueProvider.gd @@ -5,16 +5,20 @@ extends ValueProvider var _cb :Callable var _args :Array + func _init(instance :Object, func_name :String, args :Array = Array(), force_error := true): _cb = Callable(instance, func_name); _args = args if force_error and not _cb.is_valid(): push_error("Can't find function '%s' checked instance %s" % [func_name, instance]) - + + func get_value() -> Variant: if not _cb.is_valid(): return null + @warning_ignore("redundant_await") return await (_cb.call() if _args.is_empty() else _cb.callv(_args)) + func dispose(): _cb = Callable() diff --git a/addons/gdUnit4/src/asserts/GdAssertMessages.gd b/addons/gdUnit4/src/asserts/GdAssertMessages.gd index df006c82..25b6af4b 100644 --- a/addons/gdUnit4/src/asserts/GdAssertMessages.gd +++ b/addons/gdUnit4/src/asserts/GdAssertMessages.gd @@ -201,6 +201,7 @@ static func error_is_same(current, expected) -> String: return "%s\n %s\n to refer to the same object\n %s" % [_error("Expecting:"), _colored_value(expected), _colored_value(current)] +@warning_ignore("unused_parameter") static func error_not_same(current, expected) -> String: return "%s %s" % [_error("Expecting: not same"), _colored_value(expected)] diff --git a/addons/gdUnit4/src/asserts/GdUnitArrayAssertImpl.gd b/addons/gdUnit4/src/asserts/GdUnitArrayAssertImpl.gd index 9662fec2..7df5a250 100644 --- a/addons/gdUnit4/src/asserts/GdUnitArrayAssertImpl.gd +++ b/addons/gdUnit4/src/asserts/GdUnitArrayAssertImpl.gd @@ -54,7 +54,7 @@ func _array_equals_div(current :Array, expected :Array, case_sensitive :bool = f return [current_, expected_, index_report_] -func _array_div(left :Array, right :Array, same_order := false) -> Array: +func _array_div(left :Array, right :Array, _same_order := false) -> Array: var not_expect := left.duplicate(true) var not_found := right.duplicate(true) for index_c in left.size(): @@ -194,7 +194,7 @@ func contains(expected) -> GdUnitArrayAssert: if current_ == null: return report_error(GdAssertMessages.error_arr_contains(current_, expected_, [], expected_)) var diffs := _array_div(current_, expected_) - var not_expect := diffs[0] as Array + #var not_expect := diffs[0] as Array var not_found := diffs[1] as Array if not not_found.is_empty(): return report_error(GdAssertMessages.error_arr_contains(current_, expected_, [], not_found)) @@ -235,6 +235,7 @@ func contains_exactly_in_any_order(expected) -> GdUnitArrayAssert: return report_error(GdAssertMessages.error_arr_contains_exactly_in_any_order(current_, expected_, not_expect, not_found)) +@warning_ignore("shadowed_global_identifier") func is_same(expected) -> GdUnitAssert: _base.is_same(expected) return self diff --git a/addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd b/addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd index d6ac0d37..d1e72bad 100644 --- a/addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd +++ b/addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd @@ -60,7 +60,7 @@ func report_success() -> GdUnitAssert: func report_error(error_message :String, failure_line_number: int = -1) -> GdUnitAssert: _set_test_failure(true) - var line_number := failure_line_number if failure_line_number != -1 else _get_line_number() + var line_number := failure_line_number if failure_line_number != -1 else GdUnitAssertImpl._get_line_number() GdAssertReports.set_last_error_line_number(line_number) if _custom_failure_message.is_empty(): return GdAssertReports.report_error(error_message, self, line_number) @@ -82,7 +82,7 @@ static func _normalize_bbcode(message :String) -> String: func has_failure_message(expected :String): var expected_error := GdUnitTools.normalize_text(expected) - var current_error := _normalize_bbcode(_current_error_message) + var current_error := GdUnitAssertImpl._normalize_bbcode(_current_error_message) if current_error != expected_error: _expect_fail = false var diffs := GdDiffTool.string_diff(current_error, expected_error) @@ -93,7 +93,7 @@ func has_failure_message(expected :String): func starts_with_failure_message(expected :String): var expected_error := GdUnitTools.normalize_text(expected) - var current_error := _normalize_bbcode(_current_error_message) + var current_error := GdUnitAssertImpl._normalize_bbcode(_current_error_message) if current_error.find(expected_error) != 0: _expect_fail = false var diffs := GdDiffTool.string_diff(current_error, expected_error) diff --git a/addons/gdUnit4/src/asserts/GdUnitFloatAssertImpl.gd b/addons/gdUnit4/src/asserts/GdUnitFloatAssertImpl.gd index 1b8b366a..0bbbdd97 100644 --- a/addons/gdUnit4/src/asserts/GdUnitFloatAssertImpl.gd +++ b/addons/gdUnit4/src/asserts/GdUnitFloatAssertImpl.gd @@ -8,60 +8,75 @@ func _init(current, expect_result :int): if not _base.__validate_value_type(current, TYPE_FLOAT): report_error("GdUnitFloatAssert inital error, unexpected type <%s>" % GdObjects.typeof_as_string(current)) + func __current(): return _base.__current() + func report_success() -> GdUnitFloatAssert: _base.report_success() return self + func report_error(error :String) -> GdUnitFloatAssert: _base.report_error(error) return self + # -------- Base Assert wrapping ------------------------------------------------ func has_failure_message(expected: String) -> GdUnitFloatAssert: _base.has_failure_message(expected) return self + func starts_with_failure_message(expected: String) -> GdUnitFloatAssert: _base.starts_with_failure_message(expected) return self + func override_failure_message(message :String) -> GdUnitFloatAssert: _base.override_failure_message(message) return self + func _notification(event): if event == NOTIFICATION_PREDELETE: if _base != null: _base.notification(event) _base = null + + #------------------------------------------------------------------------------- # Verifies that the current value is null. func is_null() -> GdUnitFloatAssert: _base.is_null() return self + # Verifies that the current value is not null. func is_not_null() -> GdUnitFloatAssert: _base.is_not_null() return self + # Verifies that the current value is equal to expected one. func is_equal(expected :float) -> GdUnitFloatAssert: _base.is_equal(expected) return self + # Verifies that the current value is not equal to expected one. func is_not_equal(expected :float) -> GdUnitFloatAssert: _base.is_not_equal(expected) return self + # Verifies that the current and expected value are approximately equal. +@warning_ignore("shadowed_global_identifier") func is_equal_approx(expected :float, approx :float) -> GdUnitFloatAssert: return is_between(expected-approx, expected+approx) + # Verifies that the current value is less than the given one. func is_less(expected :float) -> GdUnitFloatAssert: var current = __current() @@ -69,6 +84,7 @@ func is_less(expected :float) -> GdUnitFloatAssert: report_error(GdAssertMessages.error_is_value(Comparator.LESS_THAN, current, expected)) return report_success() + # Verifies that the current value is less than or equal the given one. func is_less_equal(expected :float) -> GdUnitFloatAssert: var current = __current() @@ -76,6 +92,7 @@ func is_less_equal(expected :float) -> GdUnitFloatAssert: report_error(GdAssertMessages.error_is_value(Comparator.LESS_EQUAL, current, expected)) return report_success() + # Verifies that the current value is greater than the given one. func is_greater(expected :float) -> GdUnitFloatAssert: var current = __current() @@ -83,6 +100,7 @@ func is_greater(expected :float) -> GdUnitFloatAssert: return report_error(GdAssertMessages.error_is_value(Comparator.GREATER_THAN, current, expected)) return report_success() + # Verifies that the current value is greater than or equal the given one. func is_greater_equal(expected :float) -> GdUnitFloatAssert: var current = __current() @@ -90,6 +108,7 @@ func is_greater_equal(expected :float) -> GdUnitFloatAssert: return report_error(GdAssertMessages.error_is_value(Comparator.GREATER_EQUAL, current, expected)) return report_success() + # Verifies that the current value is negative. func is_negative() -> GdUnitFloatAssert: var current = __current() @@ -97,6 +116,7 @@ func is_negative() -> GdUnitFloatAssert: return report_error(GdAssertMessages.error_is_negative(current)) return report_success() + # Verifies that the current value is not negative. func is_not_negative() -> GdUnitFloatAssert: var current = __current() @@ -104,6 +124,7 @@ func is_not_negative() -> GdUnitFloatAssert: return report_error(GdAssertMessages.error_is_not_negative(current)) return report_success() + # Verifies that the current value is equal to zero. func is_zero() -> GdUnitFloatAssert: var current = __current() @@ -111,6 +132,7 @@ func is_zero() -> GdUnitFloatAssert: return report_error(GdAssertMessages.error_is_zero(current)) return report_success() + # Verifies that the current value is not equal to zero. func is_not_zero() -> GdUnitFloatAssert: var current = __current() @@ -118,6 +140,7 @@ func is_not_zero() -> GdUnitFloatAssert: return report_error(GdAssertMessages.error_is_not_zero()) return report_success() + # Verifies that the current value is in the given set of values. func is_in(expected :Array) -> GdUnitFloatAssert: var current = __current() @@ -125,6 +148,7 @@ func is_in(expected :Array) -> GdUnitFloatAssert: return report_error(GdAssertMessages.error_is_in(current, expected)) return report_success() + # Verifies that the current value is not in the given set of values. func is_not_in(expected :Array) -> GdUnitFloatAssert: var current = __current() @@ -132,10 +156,10 @@ func is_not_in(expected :Array) -> GdUnitFloatAssert: return report_error(GdAssertMessages.error_is_not_in(current, expected)) return report_success() + # Verifies that the current value is between the given boundaries (inclusive). func is_between(from :float, to :float) -> GdUnitFloatAssert: var current = __current() if current == null or current < from or current > to: return report_error(GdAssertMessages.error_is_value(Comparator.BETWEEN_EQUAL, current, from, to)) return report_success() - diff --git a/addons/gdUnit4/src/asserts/GdUnitFuncAssertImpl.gd b/addons/gdUnit4/src/asserts/GdUnitFuncAssertImpl.gd index cc69b28e..b52fde76 100644 --- a/addons/gdUnit4/src/asserts/GdUnitFuncAssertImpl.gd +++ b/addons/gdUnit4/src/asserts/GdUnitFuncAssertImpl.gd @@ -67,12 +67,12 @@ func starts_with_failure_message(expected: String) -> GdUnitFuncAssert: return self -func override_failure_message(message :String) -> GdUnitAssert: +func override_failure_message(message :String) -> GdUnitFuncAssert: _custom_failure_message = message return self -func wait_until(timeout := 2000) -> GdUnitAssert: +func wait_until(timeout := 2000) -> GdUnitFuncAssert: if timeout <= 0: push_warning("Invalid timeout param, alloed timeouts must be grater than 0. Use default timeout instead") _timeout = DEFAULT_TIMEOUT @@ -81,27 +81,27 @@ func wait_until(timeout := 2000) -> GdUnitAssert: return self -func is_null() -> GdUnitAssert: - return await _validate_callback(func is_null(c, e): return c == null) +func is_null() -> GdUnitFuncAssert: + return await _validate_callback(func is_null(c, _e): return c == null) -func is_not_null() -> GdUnitAssert: - return await _validate_callback(func is_not_null(c, e): return c != null) +func is_not_null() -> GdUnitFuncAssert: + return await _validate_callback(func is_not_null(c, _e): return c != null) -func is_false() -> GdUnitAssert: - return await _validate_callback(func is_false(c, e): return c == false) +func is_false() -> GdUnitFuncAssert: + return await _validate_callback(func is_false(c, _e): return c == false) -func is_true() -> GdUnitAssert: - return await _validate_callback(func is_true(c, e): return c == true) +func is_true() -> GdUnitFuncAssert: + return await _validate_callback(func is_true(c, _e): return c == true) -func is_equal(expected) -> GdUnitAssert: +func is_equal(expected) -> GdUnitFuncAssert: return await _validate_callback(func is_equal(c, e): return GdObjects.equals(c, e), expected) -func is_not_equal(expected) -> GdUnitAssert: +func is_not_equal(expected) -> GdUnitFuncAssert: return await _validate_callback(func is_not_equal(c, e): return not GdObjects.equals(c, e), expected) @@ -151,6 +151,7 @@ func _validate_callback(predicate :Callable, expected = null) -> GdUnitFuncAsser return self +@warning_ignore("redundant_await") func next_current_value(): var current = await _current_value_provider.get_value() call_deferred("emit_signal", "value_provided", current) diff --git a/addons/gdUnit4/src/asserts/GdUnitObjectAssertImpl.gd b/addons/gdUnit4/src/asserts/GdUnitObjectAssertImpl.gd index b1f4c142..5c8292f3 100644 --- a/addons/gdUnit4/src/asserts/GdUnitObjectAssertImpl.gd +++ b/addons/gdUnit4/src/asserts/GdUnitObjectAssertImpl.gd @@ -3,6 +3,7 @@ extends GdUnitObjectAssert var _base :GdUnitAssert + func _init(current, expect_result :int): _base = GdUnitAssertImpl.new(current, expect_result) if current is ValueProvider or current == null: @@ -13,75 +14,89 @@ func _init(current, expect_result :int): or _base.__validate_value_type(current, TYPE_STRING): report_error("GdUnitObjectAssert inital error, unexpected type <%s>" % GdObjects.typeof_as_string(current)) + func __current() -> Variant: return _base.__current() + func report_success() -> GdUnitObjectAssert: _base.report_success() return self + func report_error(error :String) -> GdUnitObjectAssert: _base.report_error(error) return self + # -------- Base Assert wrapping ------------------------------------------------ func has_failure_message(expected: String) -> GdUnitObjectAssert: _base.has_failure_message(expected) return self - + + func starts_with_failure_message(expected: String) -> GdUnitObjectAssert: _base.starts_with_failure_message(expected) return self + func override_failure_message(message :String) -> GdUnitObjectAssert: _base.override_failure_message(message) return self + func _notification(event): if event == NOTIFICATION_PREDELETE: if _base != null: _base.notification(event) _base = null -#------------------------------------------------------------------------------- + # Verifies that the current value is equal to expected one. func is_equal(expected) -> GdUnitObjectAssert: _base.is_equal(expected) return self + # Verifies that the current value is not equal to expected one. func is_not_equal(expected) -> GdUnitObjectAssert: _base.is_not_equal(expected) return self + # Verifies that the current value is null. func is_null() -> GdUnitObjectAssert: _base.is_null() return self + # Verifies that the current value is not null. func is_not_null() -> GdUnitObjectAssert: _base.is_not_null() return self + # Verifies that the current value is the same as the given one. +@warning_ignore("shadowed_global_identifier") func is_same(expected) -> GdUnitObjectAssert: var current :Variant = __current() - if not GdObjects.is_same(current, expected): + if not is_same(current, expected): report_error(GdAssertMessages.error_is_same(current, expected)) return self report_success() return self + # Verifies that the current value is not the same as the given one. func is_not_same(expected) -> GdUnitObjectAssert: var current = __current() - if GdObjects.is_same(current, expected): + if is_same(current, expected): report_error(GdAssertMessages.error_not_same(current, expected)) return self report_success() return self + # Verifies that the current value is an instance of the given type. func is_instanceof(type :Object) -> GdUnitObjectAssert: var current :Object = __current() @@ -93,6 +108,7 @@ func is_instanceof(type :Object) -> GdUnitObjectAssert: report_success() return self + # Verifies that the current value is not an instance of the given type. func is_not_instanceof(type) -> GdUnitObjectAssert: var current :Variant = __current() diff --git a/addons/gdUnit4/src/asserts/GdUnitSignalAssertImpl.gd b/addons/gdUnit4/src/asserts/GdUnitSignalAssertImpl.gd index 7c37af3d..59ac7a01 100644 --- a/addons/gdUnit4/src/asserts/GdUnitSignalAssertImpl.gd +++ b/addons/gdUnit4/src/asserts/GdUnitSignalAssertImpl.gd @@ -9,7 +9,8 @@ var _current_error_message :String = "" var _custom_failure_message :String = "" var _line_number := -1 var _expect_fail := false -var _is_failed := false +@warning_ignore("unused_private_class_variable") +var _is_failed :bool = false var _timeout := DEFAULT_TIMEOUT var _expect_result :int var _interrupted := false @@ -214,7 +215,7 @@ func _wail_until_signal(signal_name :String, expected_args :Array, expect_not_em if is_instance_valid(_emitter): is_signal_emitted = _signal_collector.match(_emitter, signal_name, expected_args) if is_signal_emitted and expect_not_emitted: - report_error(GdAssertMessages.error_signal_emitted(signal_name, expected_args, LocalTime.elapsed(_timeout-timer.time_left*1000))) + report_error(GdAssertMessages.error_signal_emitted(signal_name, expected_args, LocalTime.elapsed(int(_timeout-timer.time_left*1000)))) if _interrupted and not expect_not_emitted: report_error(GdAssertMessages.error_wait_signal(signal_name, expected_args, LocalTime.elapsed(_timeout))) diff --git a/addons/gdUnit4/src/asserts/GdUnitVector2AssertImpl.gd b/addons/gdUnit4/src/asserts/GdUnitVector2AssertImpl.gd index 97e52dee..a57797b9 100644 --- a/addons/gdUnit4/src/asserts/GdUnitVector2AssertImpl.gd +++ b/addons/gdUnit4/src/asserts/GdUnitVector2AssertImpl.gd @@ -3,65 +3,80 @@ extends GdUnitVector2Assert var _base: GdUnitAssert + func _init(current, expect_result :int): _base = GdUnitAssertImpl.new(current, expect_result) if not _base.__validate_value_type(current, TYPE_VECTOR2): report_error("GdUnitVector2Assert inital error, unexpected type <%s>" % GdObjects.typeof_as_string(current)) + func __current() -> Variant: return _base.__current() + func report_success() -> GdUnitVector2Assert: _base.report_success() return self + func report_error(error :String) -> GdUnitVector2Assert: _base.report_error(error) return self + # -------- Base Assert wrapping ------------------------------------------------ func has_failure_message(expected: String) -> GdUnitVector2Assert: _base.has_failure_message(expected) return self + func starts_with_failure_message(expected: String) -> GdUnitVector2Assert: _base.starts_with_failure_message(expected) return self + func override_failure_message(message :String) -> GdUnitVector2Assert: _base.override_failure_message(message) return self + func _notification(event): if event == NOTIFICATION_PREDELETE: if _base != null: _base.notification(event) _base = null + #------------------------------------------------------------------------------- # Verifies that the current value is null. func is_null() -> GdUnitVector2Assert: _base.is_null() return self + # Verifies that the current value is not null. func is_not_null() -> GdUnitVector2Assert: _base.is_not_null() return self + # Verifies that the current value is equal to expected one. func is_equal(expected :Vector2) -> GdUnitVector2Assert: _base.is_equal(expected) return self + # Verifies that the current value is not equal to expected one. func is_not_equal(expected :Vector2) -> GdUnitVector2Assert: _base.is_not_equal(expected) return self + # Verifies that the current and expected value are approximately equal. +@warning_ignore("shadowed_global_identifier") func is_equal_approx(expected :Vector2, approx :Vector2) -> GdUnitVector2Assert: return is_between(expected-approx, expected+approx) + # Verifies that the current value is less than the given one. func is_less(expected :Vector2) -> GdUnitVector2Assert: var current = __current() @@ -69,6 +84,7 @@ func is_less(expected :Vector2) -> GdUnitVector2Assert: report_error(GdAssertMessages.error_is_value(Comparator.LESS_THAN, current, expected)) return report_success() + # Verifies that the current value is less than or equal the given one. func is_less_equal(expected :Vector2) -> GdUnitVector2Assert: var current = __current() @@ -76,6 +92,7 @@ func is_less_equal(expected :Vector2) -> GdUnitVector2Assert: report_error(GdAssertMessages.error_is_value(Comparator.LESS_EQUAL, current, expected)) return report_success() + # Verifies that the current value is greater than the given one. func is_greater(expected :Vector2) -> GdUnitVector2Assert: var current = __current() @@ -83,6 +100,7 @@ func is_greater(expected :Vector2) -> GdUnitVector2Assert: return report_error(GdAssertMessages.error_is_value(Comparator.GREATER_THAN, current, expected)) return report_success() + # Verifies that the current value is greater than or equal the given one. func is_greater_equal(expected :Vector2) -> GdUnitVector2Assert: var current = __current() @@ -90,6 +108,7 @@ func is_greater_equal(expected :Vector2) -> GdUnitVector2Assert: return report_error(GdAssertMessages.error_is_value(Comparator.GREATER_EQUAL, current, expected)) return report_success() + # Verifies that the current value is between the given boundaries (inclusive). func is_between(from :Vector2, to :Vector2) -> GdUnitVector2Assert: var current = __current() @@ -97,6 +116,7 @@ func is_between(from :Vector2, to :Vector2) -> GdUnitVector2Assert: return report_error(GdAssertMessages.error_is_value(Comparator.BETWEEN_EQUAL, current, from, to)) return report_success() + # Verifies that the current value is not between the given boundaries (inclusive). func is_not_between(from :Vector2, to :Vector2) -> GdUnitVector2Assert: var current = __current() diff --git a/addons/gdUnit4/src/asserts/GdUnitVector3AssertImpl.gd b/addons/gdUnit4/src/asserts/GdUnitVector3AssertImpl.gd index 48c6621c..253f4d32 100644 --- a/addons/gdUnit4/src/asserts/GdUnitVector3AssertImpl.gd +++ b/addons/gdUnit4/src/asserts/GdUnitVector3AssertImpl.gd @@ -8,60 +8,75 @@ func _init(current, expect_result :int): if not _base.__validate_value_type(current, TYPE_VECTOR3): report_error("GdUnitVector3Assert inital error, unexpected type <%s>" % GdObjects.typeof_as_string(current)) + func __current() -> Variant: return _base.__current() + func report_success() -> GdUnitVector3Assert: _base.report_success() return self + func report_error(error :String) -> GdUnitVector3Assert: _base.report_error(error) return self + # -------- Base Assert wrapping ------------------------------------------------ func has_failure_message(expected: String) -> GdUnitVector3Assert: _base.has_failure_message(expected) return self + func starts_with_failure_message(expected: String) -> GdUnitVector3Assert: _base.starts_with_failure_message(expected) return self + func override_failure_message(message :String) -> GdUnitVector3Assert: _base.override_failure_message(message) return self + func _notification(event): if event == NOTIFICATION_PREDELETE: if _base != null: _base.notification(event) _base = null + + #------------------------------------------------------------------------------- # Verifies that the current value is null. func is_null() -> GdUnitVector3Assert: _base.is_null() return self + # Verifies that the current value is not null. func is_not_null() -> GdUnitVector3Assert: _base.is_not_null() return self + # Verifies that the current value is equal to expected one. func is_equal(expected :Vector3) -> GdUnitVector3Assert: _base.is_equal(expected) return self + # Verifies that the current value is not equal to expected one. func is_not_equal(expected :Vector3) -> GdUnitVector3Assert: _base.is_not_equal(expected) return self + # Verifies that the current and expected value are approximately equal. +@warning_ignore("shadowed_global_identifier") func is_equal_approx(expected :Vector3, approx :Vector3) -> GdUnitVector3Assert: return is_between(expected-approx, expected+approx) + # Verifies that the current value is less than the given one. func is_less(expected :Vector3) -> GdUnitVector3Assert: var current = __current() @@ -69,6 +84,7 @@ func is_less(expected :Vector3) -> GdUnitVector3Assert: report_error(GdAssertMessages.error_is_value(Comparator.LESS_THAN, current, expected)) return report_success() + # Verifies that the current value is less than or equal the given one. func is_less_equal(expected :Vector3) -> GdUnitVector3Assert: var current = __current() @@ -76,6 +92,7 @@ func is_less_equal(expected :Vector3) -> GdUnitVector3Assert: report_error(GdAssertMessages.error_is_value(Comparator.LESS_EQUAL, current, expected)) return report_success() + # Verifies that the current value is greater than the given one. func is_greater(expected :Vector3) -> GdUnitVector3Assert: var current = __current() @@ -83,6 +100,7 @@ func is_greater(expected :Vector3) -> GdUnitVector3Assert: return report_error(GdAssertMessages.error_is_value(Comparator.GREATER_THAN, current, expected)) return report_success() + # Verifies that the current value is greater than or equal the given one. func is_greater_equal(expected :Vector3) -> GdUnitVector3Assert: var current = __current() @@ -90,6 +108,7 @@ func is_greater_equal(expected :Vector3) -> GdUnitVector3Assert: return report_error(GdAssertMessages.error_is_value(Comparator.GREATER_EQUAL, current, expected)) return report_success() + # Verifies that the current value is between the given boundaries (inclusive). func is_between(from :Vector3, to :Vector3) -> GdUnitVector3Assert: var current = __current() @@ -97,6 +116,7 @@ func is_between(from :Vector3, to :Vector3) -> GdUnitVector3Assert: return report_error(GdAssertMessages.error_is_value(Comparator.BETWEEN_EQUAL, current, from, to)) return report_success() + # Verifies that the current value is not between the given boundaries (inclusive). func is_not_between(from :Vector3, to :Vector3) -> GdUnitVector3Assert: var current = __current() diff --git a/addons/gdUnit4/src/cmd/CmdArgumentParser.gd b/addons/gdUnit4/src/cmd/CmdArgumentParser.gd index 32db4b0e..96293226 100644 --- a/addons/gdUnit4/src/cmd/CmdArgumentParser.gd +++ b/addons/gdUnit4/src/cmd/CmdArgumentParser.gd @@ -5,9 +5,11 @@ var _options :CmdOptions var _tool_name :String var _parsed_commands :Dictionary = Dictionary() -func _init(options :CmdOptions,tool_name :String): - _options = options - _tool_name = tool_name + +func _init(p_options :CmdOptions, p_tool_name :String): + _options = p_options + _tool_name = p_tool_name + func parse(args :Array, ignore_unknown_cmd := false) -> Result: _parsed_commands.clear() @@ -33,9 +35,11 @@ func parse(args :Array, ignore_unknown_cmd := false) -> Result: return Result.error("Unknown '%s' command!" % cmd) return Result.success(_parsed_commands.values()) + func options() -> CmdOptions: return _options + func _parse_cmd_arguments(option :CmdOption, args :Array) -> int: var command_name := option.short_command() var command :CmdCommand = _parsed_commands.get(command_name, CmdCommand.new(command_name)) @@ -50,6 +54,7 @@ func _parse_cmd_arguments(option :CmdOption, args :Array) -> int: _parsed_commands[command_name] = command return 0 + func _is_next_value_argument(args :Array) -> bool: if args.is_empty(): return false diff --git a/addons/gdUnit4/src/cmd/CmdCommand.gd b/addons/gdUnit4/src/cmd/CmdCommand.gd index c895876f..c9c34143 100644 --- a/addons/gdUnit4/src/cmd/CmdCommand.gd +++ b/addons/gdUnit4/src/cmd/CmdCommand.gd @@ -4,18 +4,23 @@ extends RefCounted var _name: String var _arguments: PackedStringArray -func _init(name: String, arguments: = []): - _name = name - _arguments = PackedStringArray(arguments) + +func _init(p_name: String, p_arguments: = []): + _name = p_name + _arguments = PackedStringArray(p_arguments) + func name() -> String: return _name + func arguments() -> PackedStringArray: return _arguments + func add_argument(arg: String) -> void: _arguments.append(arg) + func _to_string(): return "%s:%s" % [_name, ", ".join(_arguments)] diff --git a/addons/gdUnit4/src/cmd/CmdConsole.gd b/addons/gdUnit4/src/cmd/CmdConsole.gd index e7b11d38..5a64b154 100644 --- a/addons/gdUnit4/src/cmd/CmdConsole.gd +++ b/addons/gdUnit4/src/cmd/CmdConsole.gd @@ -22,82 +22,98 @@ var _debug_show_color_codes := false var _color_mode = COLOR_TABLE -func color(color :Color) -> CmdConsole: +func color(p_color :Color) -> CmdConsole: # using color table 16 - 231 a 6 x 6 x 6 RGB color cube (16 + R * 36 + G * 6 + B) if _color_mode == COLOR_TABLE: - var c2 = 16 + (int(color.r8/42) * 36) + (int(color.g8/42) * 6) + int(color.b8/42) + @warning_ignore("integer_division") + var c2 = 16 + (int(p_color.r8/42) * 36) + (int(p_color.g8/42) * 6) + int(p_color.b8/42) if _debug_show_color_codes: printraw("%6d" % [c2]) printraw("[38;5;%dm" % c2 ) else: - printraw("[38;2;%d;%d;%dm" % [color.r8, color.g8, color.b8] ) + printraw("[38;2;%d;%d;%dm" % [p_color.r8, p_color.g8, p_color.b8] ) return self + func end_color() -> CmdConsole: printraw("") return self + func row_pos(row :int) -> CmdConsole: printraw("[%d;0H" % row ) return self + func scrollArea(from :int, to :int ) -> CmdConsole: printraw("[%d;%dr" % [from ,to]) return self -func progressBar(progress :int, color :Color = Color.POWDER_BLUE) -> CmdConsole: - if progress < 0: - progress = 0 - if progress > 100: - progress = 100 - color(color) - printraw("[%-50s] %-3d%%\r" % ["".lpad(progress/2, "■").rpad(50, "-"), progress]) + +func progressBar(p_progress :int, p_color :Color = Color.POWDER_BLUE) -> CmdConsole: + if p_progress < 0: + p_progress = 0 + if p_progress > 100: + p_progress = 100 + color(p_color) + printraw("[%-50s] %-3d%%\r" % ["".lpad(int(p_progress/2.0), "■").rpad(50, "-"), p_progress]) end_color() return self + func printl(value :String) -> CmdConsole: printraw(value) return self + func new_line() -> CmdConsole: prints() return self + func reset() -> CmdConsole: return self + func bold(enable :bool) -> CmdConsole: if enable: printraw(__CSI_BOLD) return self + func italic(enable :bool) -> CmdConsole: if enable: printraw(__CSI_ITALIC) return self + func underline(enable :bool) -> CmdConsole: if enable: printraw(__CSI_UNDERLINE) return self + func prints_error(message :String) -> CmdConsole: return color(Color.CRIMSON).printl(message).end_color().new_line() + func prints_warning(message :String) -> CmdConsole: return color(Color.GOLDENROD).printl(message).end_color().new_line() -func prints_color(message :String, color :Color, flags := 0) -> CmdConsole: - return print_color(message, color, flags).new_line() -func print_color( message :String, color :Color, flags := 0) -> CmdConsole: - return color(color)\ - .bold(flags&BOLD == BOLD)\ - .italic(flags&ITALIC == ITALIC)\ - .underline(flags&UNDERLINE == UNDERLINE)\ - .printl(message)\ +func prints_color(p_message :String, p_color :Color, p_flags := 0) -> CmdConsole: + return print_color(p_message, p_color, p_flags).new_line() + + +func print_color(p_message :String, p_color :Color, p_flags := 0) -> CmdConsole: + return color(p_color)\ + .bold(p_flags&BOLD == BOLD)\ + .italic(p_flags&ITALIC == ITALIC)\ + .underline(p_flags&UNDERLINE == UNDERLINE)\ + .printl(p_message)\ .end_color() + func print_color_table(): prints_color("Color Table 6x6x6", Color.ANTIQUE_WHITE) _debug_show_color_codes = true diff --git a/addons/gdUnit4/src/cmd/CmdOption.gd b/addons/gdUnit4/src/cmd/CmdOption.gd index c70965a3..a562a037 100644 --- a/addons/gdUnit4/src/cmd/CmdOption.gd +++ b/addons/gdUnit4/src/cmd/CmdOption.gd @@ -8,44 +8,54 @@ var _description :String var _type :int var _arg_optional :bool = false + # constructs a command option by given arguments # commands : a string with comma separated list of available commands begining with the short form # help: a help text show howto use # description: a full description of the command # type: the argument type # arg_optional: defines of the argument optional -func _init(commands :String,help :String,description :String,type :int = TYPE_NIL,arg_optional :bool = false): - _commands = commands.replace(" ", "").replace("\t", "").split(",") - _help = help - _description = description - _type = type - _arg_optional = arg_optional +func _init(p_commands :String, p_help :String, p_description :String, p_type :int = TYPE_NIL, p_arg_optional :bool = false): + _commands = p_commands.replace(" ", "").replace("\t", "").split(",") + _help = p_help + _description = p_description + _type = p_type + _arg_optional = p_arg_optional + func commands() -> PackedStringArray: return _commands + func short_command() -> String: return _commands[0] + func help() -> String: return _help + func description() -> String: return _description + func type() -> int: return _type + func is_argument_optional() -> bool: return _arg_optional + func has_argument() -> bool: return _type != TYPE_NIL - + + func describe() -> String: if help().is_empty(): return " %-32s %s \n" % [commands(), description()] return " %-32s %s \n %-32s %s\n" % [commands(), description(), "", help()] - + + func _to_string(): return describe() diff --git a/addons/gdUnit4/src/cmd/CmdOptions.gd b/addons/gdUnit4/src/cmd/CmdOptions.gd index b29ea687..ddebe309 100644 --- a/addons/gdUnit4/src/cmd/CmdOptions.gd +++ b/addons/gdUnit4/src/cmd/CmdOptions.gd @@ -6,20 +6,24 @@ var _default_options :Array var _advanced_options :Array -func _init(options :Array = Array(),advanced_options :Array = Array()): +func _init(p_options :Array = Array(), p_advanced_options :Array = Array()): # default help options - _default_options = options - _advanced_options = advanced_options + _default_options = p_options + _advanced_options = p_advanced_options + func default_options() -> Array: return _default_options + func advanced_options() -> Array: return _advanced_options + func options() -> Array: return default_options() + advanced_options() + func get_option(cmd :String) -> CmdOption: for option in options(): if Array(option.commands()).has(cmd): diff --git a/addons/gdUnit4/src/core/GdFunctionDoubler.gd b/addons/gdUnit4/src/core/GdFunctionDoubler.gd index 86450644..d3df8a9b 100644 --- a/addons/gdUnit4/src/core/GdFunctionDoubler.gd +++ b/addons/gdUnit4/src/core/GdFunctionDoubler.gd @@ -68,7 +68,7 @@ const DEFAULT_ENUM_RETURN_VALUES = { var _push_errors :String static func default_return_value(func_descriptor :GdFunctionDescriptor) -> String: - var return_type := func_descriptor.return_type() + var return_type :Variant = func_descriptor.return_type() if return_type == GdObjects.TYPE_ENUM: var enum_path := func_descriptor._return_class.split(".") if enum_path.size() == 2: @@ -89,6 +89,7 @@ func _init(push_errors :bool = false): assert(DEFAULT_TYPED_RETURN_VALUES.has(type_key), "Missing Type default definition!") +@warning_ignore("unused_parameter") func get_template(return_type :Variant, is_vararg :bool) -> String: push_error("Must be implemented!") return "" @@ -102,35 +103,36 @@ func double(func_descriptor :GdFunctionDescriptor) -> PackedStringArray: var func_name := func_descriptor.name() var args := func_descriptor.args() var varargs := func_descriptor.varargs() - var default_return_value := default_return_value(func_descriptor) + var return_value := GdFunctionDoubler.default_return_value(func_descriptor) var arg_names := extract_arg_names(args) var vararg_names := extract_arg_names(varargs) # save original constructor arguments if func_name == "_init": - var constructor_args := ",".join(extract_constructor_args(args)) + var constructor_args := ",".join(GdFunctionDoubler.extract_constructor_args(args)) var constructor := "func _init(%s):\n super(%s)\n pass\n" % [constructor_args, ", ".join(arg_names)] return constructor.split("\n") - var double := "" + var double_src := "" if func_descriptor.is_engine(): - double += '@warning_ignore("native_method_override")\n' - double += func_signature + double_src += '@warning_ignore("native_method_override")\n' + double_src += '@warning_ignore("shadowed_variable")\n' + double_src += func_signature # fix to unix format, this is need when the template is edited under windows than the template is stored with \r\n var func_template := get_template(func_descriptor.return_type(), is_vararg).replace("\r\n", "\n") - double += func_template\ + double_src += func_template\ .replace("$(arguments)", ", ".join(arg_names))\ .replace("$(varargs)", ", ".join(vararg_names))\ - .replace("$(await)", await_is_coroutine(is_coroutine)) \ + .replace("$(await)", GdFunctionDoubler.await_is_coroutine(is_coroutine)) \ .replace("$(func_name)", func_name )\ - .replace("${default_return_value}", default_return_value)\ + .replace("${default_return_value}", return_value)\ .replace("$(push_errors)", _push_errors) if is_static: - double = double.replace("$(instance)", "__instance().") + double_src = double_src.replace("$(instance)", "__instance().") else: - double = double.replace("$(instance)", "") - return double.split("\n") + double_src = double_src.replace("$(instance)", "") + return double_src.split("\n") func extract_arg_names(argument_signatures :Array[GdFunctionArgument]) -> PackedStringArray: diff --git a/addons/gdUnit4/src/core/GdObjects.gd b/addons/gdUnit4/src/core/GdObjects.gd index 26254a76..d714dbe0 100644 --- a/addons/gdUnit4/src/core/GdObjects.gd +++ b/addons/gdUnit4/src/core/GdObjects.gd @@ -252,6 +252,7 @@ static func _equals(obj_a, obj_b, case_sensitive :bool, deep_check :bool, deep_s return obj_a == obj_b +@warning_ignore("shadowed_variable_base_class") static func notification_as_string(instance :Variant, notification :int) -> String: var error := "Unknown notification: '%s' at instance: %s" % [notification, instance] if instance == null: @@ -291,28 +292,6 @@ static func to_snake_case(value :String) -> String: return ''.join(result) -# Converts from one type to another as best as possible. -# The Type parameter uses the values Variant.Type and the extended GdObject.Type -static func convert(value :Variant, type :int) -> Variant: - # https://github.com/godotengine/godot/issues/65919 - # TODO replace this anoing code by GdScript.convert - if value is String: - return str_to_var(value) - - match type: - TYPE_NIL: - return null - TYPE_BOOL: - return str_to_var(value) - TYPE_STRING: - return var_to_str(value).replace("\"", "") - TYPE_FUZZER: - return str(value) - _: - push_error("To convert a value '%s':'%s' to type '%s' current not supported!" % [value, typeof_as_string(value), type_as_string(type)]) - return null - - static func is_snake_case(value :String) -> bool: for ch in value: if ch == '_': @@ -406,7 +385,8 @@ static func is_type(value :Variant) -> bool: return false -static func is_same(left, right) -> bool: +@warning_ignore("shadowed_global_identifier") +static func _is_same(left, right) -> bool: var left_type := -1 if left == null else typeof(left) var right_type := -1 if right == null else typeof(right) diff --git a/addons/gdUnit4/src/core/GdUnitClassDoubler.gd b/addons/gdUnit4/src/core/GdUnitClassDoubler.gd index 20ea2d49..d8ff4942 100644 --- a/addons/gdUnit4/src/core/GdUnitClassDoubler.gd +++ b/addons/gdUnit4/src/core/GdUnitClassDoubler.gd @@ -91,7 +91,7 @@ static func double_functions(instance :Object, clazz_name :String, clazz_path :P if functions.has(func_descriptor.name()) or exclude_override_functions.has(func_descriptor.name()): continue # GD-110: Hotfix do not double invalid engine functions - if is_invalid_method_descriptior(clazz_name, method): + if is_invalid_method_descriptior(method): #prints("'%s': invalid method descriptor found! %s" % [clazz_name, method]) continue # do not double on not implemented virtual functions @@ -104,7 +104,7 @@ static func double_functions(instance :Object, clazz_name :String, clazz_path :P # GD-110 -static func is_invalid_method_descriptior(clazz :String, method :Dictionary) -> bool: +static func is_invalid_method_descriptior(method :Dictionary) -> bool: var return_info = method["return"] var type :int = return_info["type"] var usage :int = return_info["usage"] diff --git a/addons/gdUnit4/src/core/GdUnitExecutor.gd b/addons/gdUnit4/src/core/GdUnitExecutor.gd index 28c849f1..b3f75629 100644 --- a/addons/gdUnit4/src/core/GdUnitExecutor.gd +++ b/addons/gdUnit4/src/core/GdUnitExecutor.gd @@ -15,6 +15,9 @@ var _testcase_timer :LocalTime var _memory_pool :GdUnitMemoryPool = GdUnitMemoryPool.new() var _report_errors_enabled :bool var _report_collector : = GdUnitReportCollector.new() + +# we hold here the main instance for the argument matcher (singleton) +@warning_ignore("unused_private_class_variable") var _arument_matcher = GdUnitArgumentMatchers.new() var _total_test_execution_orphans :int @@ -71,6 +74,7 @@ func fire_test_skipped(test_suite :GdUnitTestSuite, test_case :_TestCase): fire_event(GdUnitEvent.new()\ .test_after(test_suite.get_script().resource_path, test_suite.get_name(), test_case.get_name(), statistics, [report])) + func suite_before(test_suite :GdUnitTestSuite, total_count :int): set_stage(STAGE_TEST_SUITE_BEFORE) fire_event(GdUnitEvent.new()\ @@ -81,9 +85,11 @@ func suite_before(test_suite :GdUnitTestSuite, total_count :int): _total_test_warnings = 0 if not test_suite.is_skipped(): _memory_pool.set_pool(test_suite, GdUnitMemoryPool.POOL.TESTSUITE, true) + @warning_ignore("redundant_await") await test_suite.before() _memory_pool.monitor_stop() + func suite_after(test_suite :GdUnitTestSuite): set_stage(STAGE_TEST_SUITE_AFTER) GdUnitTools.clear_tmp() @@ -97,6 +103,7 @@ func suite_after(test_suite :GdUnitTestSuite): if not is_skipped: _memory_pool.set_pool(test_suite, GdUnitMemoryPool.POOL.TESTSUITE) skip_count = 0 + @warning_ignore("redundant_await") await test_suite.after() GdUnitTools.append_array(reports, _report_collector.get_reports(STAGE_TEST_SUITE_AFTER)) _memory_pool.free_pool() @@ -123,20 +130,23 @@ func suite_after(test_suite :GdUnitTestSuite): fire_event(GdUnitEvent.new().suite_after(test_suite.get_script().resource_path, test_suite.get_name(), statistics, reports)) _report_collector.clear_reports(STAGE_TEST_SUITE_BEFORE|STAGE_TEST_SUITE_AFTER) -func test_before(test_suite :GdUnitTestSuite, test_case :_TestCase, test_case_name :String, fire_event := true): + +func test_before(test_suite :GdUnitTestSuite, test_case_name :String, do_fire_event := true): set_stage(STAGE_TEST_CASE_BEFORE) _memory_pool.set_pool(test_suite, GdUnitMemoryPool.POOL.TESTCASE, true) _total_test_execution_orphans = 0 - if fire_event: + if do_fire_event: _testcase_timer = LocalTime.now() fire_event(GdUnitEvent.new()\ .test_before(test_suite.get_script().resource_path, test_suite.get_name(), test_case_name)) + @warning_ignore("redundant_await") await test_suite.before_test() _memory_pool.monitor_stop() -func test_after(test_suite :GdUnitTestSuite, test_case :_TestCase, test_case_name :String, fire_event := true): + +func test_after(test_suite :GdUnitTestSuite, test_case :_TestCase, test_case_name :String, do_fire_event := true): _memory_pool.free_pool() # give objects time to finallize await get_tree().process_frame @@ -155,7 +165,7 @@ func test_after(test_suite :GdUnitTestSuite, test_case :_TestCase, test_case_nam set_stage(STAGE_TEST_CASE_AFTER) _memory_pool.set_pool(test_suite, GdUnitMemoryPool.POOL.TESTCASE) - + @warning_ignore("redundant_await") await test_suite.after_test() _memory_pool.free_pool() _memory_pool.monitor_stop() @@ -185,13 +195,14 @@ func test_after(test_suite :GdUnitTestSuite, test_case :_TestCase, test_case_nam GdUnitEvent.SKIPPED_COUNT: int(test_case.is_skipped()), } - if fire_event: + if do_fire_event: fire_event(GdUnitEvent.new()\ .test_after(test_suite.get_script().resource_path, test_suite.get_name(), test_case_name, statistics, reports.duplicate())) _report_collector.clear_reports(STAGE_TEST_CASE_BEFORE|STAGE_TEST_CASE_EXECUTE|STAGE_TEST_CASE_AFTER) + func execute_test_case_single(test_suite :GdUnitTestSuite, test_case :_TestCase): - await test_before(test_suite, test_case, test_case.get_name()) + await test_before(test_suite, test_case.get_name()) set_stage(STAGE_TEST_CASE_EXECUTE) _memory_pool.set_pool(test_suite, GdUnitMemoryPool.POOL.EXECUTE, true) @@ -200,13 +211,14 @@ func execute_test_case_single(test_suite :GdUnitTestSuite, test_case :_TestCase) test_case.dispose() await test_after(test_suite, test_case, test_case.get_name()) + func execute_test_case_iterative(test_suite :GdUnitTestSuite, test_case :_TestCase): test_case.generate_seed() var fuzzers := create_fuzzers(test_suite, test_case) var is_failure := false for iteration in test_case.iterations(): # call before_test for each iteration - await test_before(test_suite, test_case, test_case.get_name(), iteration==0) + await test_before(test_suite, test_case.get_name(), iteration==0) set_stage(STAGE_TEST_CASE_EXECUTE) _memory_pool.set_pool(test_suite, GdUnitMemoryPool.POOL.EXECUTE, true) @@ -230,6 +242,7 @@ func execute_test_case_iterative(test_suite :GdUnitTestSuite, test_case :_TestCa break test_case.dispose() + func execute_test_case_parameterized(test_suite :GdUnitTestSuite, test_case :_TestCase): var testcase_timer = LocalTime.now() fire_event(GdUnitEvent.new()\ @@ -245,7 +258,7 @@ func execute_test_case_parameterized(test_suite :GdUnitTestSuite, test_case :_Te # is test_parameter_index is set, we run this parameterized test only if test_parameter_index != -1 and test_parameter_index != test_case_index: continue - await test_before(test_suite, test_case, test_case_names[test_case_index]) + await test_before(test_suite, test_case_names[test_case_index]) set_stage(STAGE_TEST_CASE_EXECUTE) _memory_pool.set_pool(test_suite, GdUnitMemoryPool.POOL.EXECUTE, true) await test_case.execute(test_case_parameters[test_case_index]) @@ -272,6 +285,7 @@ func execute_test_case_parameterized(test_suite :GdUnitTestSuite, test_case :_Te func execute(test_suite :GdUnitTestSuite): await Execute(test_suite) + func Execute(test_suite :GdUnitTestSuite) -> void: # stop checked first error if fail fast enabled if _fail_fast and _total_test_failed > 0: @@ -317,6 +331,7 @@ func Execute(test_suite :GdUnitTestSuite) -> void: ts.free() ExecutionCompleted.emit() + func copy_properties(source :Object, target :Object): if not source is _TestCase and not source is GdUnitTestSuite: return @@ -324,6 +339,7 @@ func copy_properties(source :Object, target :Object): var property_name = property["name"] target.set(property_name, source.get(property_name)) + # clones a test suite and moves the test cases to new instance func clone_test_suite(test_suite :GdUnitTestSuite) -> GdUnitTestSuite: dispose_timers(test_suite) @@ -339,6 +355,7 @@ func clone_test_suite(test_suite :GdUnitTestSuite) -> GdUnitTestSuite: parent.add_child(_test_suite) return _test_suite + func dispose_timers(test_suite :GdUnitTestSuite): for child in test_suite.get_children(): if child is Timer: @@ -346,7 +363,8 @@ func dispose_timers(test_suite :GdUnitTestSuite): test_suite.remove_child(child) child.free() -static func create_fuzzers(test_suite :GdUnitTestSuite, test_case :_TestCase) -> Array[Fuzzer]: + +func create_fuzzers(test_suite :GdUnitTestSuite, test_case :_TestCase) -> Array[Fuzzer]: if not test_case.has_fuzzer(): return Array() var fuzzers :Array[Fuzzer] = [] diff --git a/addons/gdUnit4/src/core/GdUnitMemoryPool.gd b/addons/gdUnit4/src/core/GdUnitMemoryPool.gd index c45d8658..79d3c5c7 100644 --- a/addons/gdUnit4/src/core/GdUnitMemoryPool.gd +++ b/addons/gdUnit4/src/core/GdUnitMemoryPool.gd @@ -8,7 +8,8 @@ enum POOL { TESTSUITE, TESTCASE, EXECUTE, - UNIT_TEST_ONLY + UNIT_TEST_ONLY, + ALL, } @@ -27,31 +28,31 @@ class MemoryStore extends RefCounted: func _notification(what): if what == NOTIFICATION_PREDELETE: while not _store.is_empty(): - var value := _store.pop_front() + var value :Variant = _store.pop_front() GdUnitTools.free_instance(value) - static func pool(pool :POOL) -> MemoryStore: - var pool_name :String = POOL.keys()[pool] + static func pool(p_pool :POOL) -> MemoryStore: + var pool_name :String = POOL.keys()[p_pool] return GdUnitSingleton.instance(pool_name, func(): return MemoryStore.new()) - static func append(pool :POOL, value :Variant) -> void: - pool(pool)._store.append(value) + static func append(p_pool :POOL, value :Variant) -> void: + pool(p_pool)._store.append(value) - static func contains(pool :POOL, value :Variant) -> bool: - return pool(pool)._store.has(value) + static func contains(p_pool :POOL, value :Variant) -> bool: + return pool(p_pool)._store.has(value) - static func push_front(pool :POOL, value :Variant) -> void: - pool(pool)._store.push_front(value) + static func push_front(p_pool :POOL, value :Variant) -> void: + pool(p_pool)._store.push_front(value) - static func release_objects(pool :POOL) -> void: - var store := pool(pool)._store + static func release_objects(p_pool :POOL) -> void: + var store := pool(p_pool)._store while not store.is_empty(): - var value := store.pop_front() + var value :Variant = store.pop_front() GdUnitTools.free_instance(value) @@ -84,7 +85,7 @@ func monitor_stop() -> void: func free_pool() -> void: - run_auto_free(_current) + GdUnitMemoryPool.run_auto_free(_current) func get_monitor(pool_id :POOL) -> GdUnitMemMonitor: @@ -118,12 +119,12 @@ static func run_auto_free(pool :POOL) -> void: # tests if given object is registered for auto freeing -static func is_auto_free_registered(obj, pool :POOL = -1) -> bool: +static func is_auto_free_registered(obj, pool :POOL = POOL.ALL) -> bool: # only register real object values if not is_instance_valid(obj): return false # check all pools? - if pool == -1: + if pool == POOL.ALL: return is_auto_free_registered(obj, POOL.TESTSUITE)\ or is_auto_free_registered(obj, POOL.TESTCASE)\ or is_auto_free_registered(obj, POOL.EXECUTE) diff --git a/addons/gdUnit4/src/core/GdUnitProperty.gd b/addons/gdUnit4/src/core/GdUnitProperty.gd index 262f739e..3ca23854 100644 --- a/addons/gdUnit4/src/core/GdUnitProperty.gd +++ b/addons/gdUnit4/src/core/GdUnitProperty.gd @@ -8,51 +8,62 @@ var _value var _value_set :PackedStringArray var _default -func _init(name :String,type :int,value,default_value,help :="",value_set := PackedStringArray()): - _name = name - _type = type - _value = value - _value_set = value_set - _default = default_value - _help = help + +func _init(p_name :String, p_type :int, p_value, p_default_value, p_help :="", p_value_set := PackedStringArray()): + _name = p_name + _type = p_type + _value = p_value + _value_set = p_value_set + _default = p_default_value + _help = p_help + func name() -> String: return _name + func type() -> int: return _type + func value(): return _value + func value_set() -> PackedStringArray: return _value_set + func is_selectable_value() -> bool: return not _value_set.is_empty() -func set_value(value) -> void: + +func set_value(p_value) -> void: match _type: TYPE_STRING: - _value = str(value) + _value = str(p_value) TYPE_BOOL: - _value = bool(value) + _value = bool(p_value) TYPE_INT: - _value = int(value) + _value = int(p_value) TYPE_FLOAT: - _value = float(value) + _value = float(p_value) + func default(): return _default + func category() -> String: var elements := _name.split("/") if elements.size() > 3: return elements[2] return "" + func help() -> String: return _help + func _to_string() -> String: return "%-64s %-10s %-10s (%s) help:%s set:%s" % [name(), type(), value(), default(), help(), _value_set] diff --git a/addons/gdUnit4/src/core/GdUnitRunner.gd b/addons/gdUnit4/src/core/GdUnitRunner.gd index ef270e47..0e61f7ea 100644 --- a/addons/gdUnit4/src/core/GdUnitRunner.gd +++ b/addons/gdUnit4/src/core/GdUnitRunner.gd @@ -21,9 +21,6 @@ var _test_suites_to_process :Array var _state = INIT var _cs_executor -# holds the received sync rpc result -var _result :Result - func _init(): # minimize scene window checked debug mode @@ -38,7 +35,7 @@ func _init(): func _ready(): - var config_result := _config.load() + var config_result := _config.load_config() if config_result.is_error(): push_error(config_result.error_message()) _state = EXIT @@ -63,7 +60,7 @@ func _notification(what): Engine.remove_meta(GDUNIT_RUNNER) -func _process(delta): +func _process(_delta): match _state: INIT: # wait until client is connected to the GdUnitServer diff --git a/addons/gdUnit4/src/core/GdUnitRunnerConfig.gd b/addons/gdUnit4/src/core/GdUnitRunnerConfig.gd index 9b3e1113..15d3ad0e 100644 --- a/addons/gdUnit4/src/core/GdUnitRunnerConfig.gd +++ b/addons/gdUnit4/src/core/GdUnitRunnerConfig.gd @@ -42,26 +42,26 @@ func self_test() -> GdUnitRunnerConfig: return self -func add_test_suite(resource_path :String) -> GdUnitRunnerConfig: - var to_execute := to_execute() - to_execute[resource_path] = to_execute.get(resource_path, PackedStringArray()) +func add_test_suite(p_resource_path :String) -> GdUnitRunnerConfig: + var to_execute_ := to_execute() + to_execute_[p_resource_path] = to_execute_.get(p_resource_path, PackedStringArray()) return self func add_test_suites(resource_paths :PackedStringArray) -> GdUnitRunnerConfig: - for resource_path in resource_paths: - add_test_suite(resource_path) + for resource_path_ in resource_paths: + add_test_suite(resource_path_) return self -func add_test_case(resource_path :String, test_name :StringName, test_param_index :int = -1) -> GdUnitRunnerConfig: - var to_execute := to_execute() - var test_cases :PackedStringArray = to_execute.get(resource_path, PackedStringArray()) +func add_test_case(p_resource_path :String, test_name :StringName, test_param_index :int = -1) -> GdUnitRunnerConfig: + var to_execute_ := to_execute() + var test_cases :PackedStringArray = to_execute_.get(p_resource_path, PackedStringArray()) if test_param_index != -1: test_cases.append("%s:%d" % [test_name, test_param_index]) else: test_cases.append(test_name) - to_execute[resource_path] = test_cases + to_execute_[p_resource_path] = test_cases return self @@ -81,16 +81,16 @@ func skip_test_suite(value :StringName) -> GdUnitRunnerConfig: func skip_test_suites(resource_paths :PackedStringArray) -> GdUnitRunnerConfig: - for resource_path in resource_paths: - skip_test_suite(resource_path) + for resource_path_ in resource_paths: + skip_test_suite(resource_path_) return self -func skip_test_case(resource_path :String, test_name :StringName) -> GdUnitRunnerConfig: +func skip_test_case(p_resource_path :String, test_name :StringName) -> GdUnitRunnerConfig: var to_ignore := skipped() - var test_cases :PackedStringArray = to_ignore.get(resource_path, PackedStringArray()) + var test_cases :PackedStringArray = to_ignore.get(p_resource_path, PackedStringArray()) test_cases.append(test_name) - to_ignore[resource_path] = test_cases + to_ignore[p_resource_path] = test_cases return self @@ -102,17 +102,17 @@ func skipped() -> Dictionary: return _config.get(SKIPPED, PackedStringArray()) -func save(path :String = CONFIG_FILE) -> Result: +func save_config(path :String = CONFIG_FILE) -> Result: var file := FileAccess.open(path, FileAccess.WRITE) if file == null: var error = FileAccess.get_open_error() return Result.error("Can't write test runner configuration '%s'! %s" % [path, GdUnitTools.error_as_string(error)]) _config[VERSION] = CONFIG_VERSION - file.store_string(JSON.new().stringify(_config)) + file.store_string(JSON.stringify(_config)) return Result.success(path) -func load(path :String = CONFIG_FILE) -> Result: +func load_config(path :String = CONFIG_FILE) -> Result: if not FileAccess.file_exists(path): return Result.error("Can't find test runner configuration '%s'! Please select a test to run." % path) var file := FileAccess.open(path, FileAccess.READ) @@ -135,8 +135,8 @@ func load(path :String = CONFIG_FILE) -> Result: func fix_value_types(): # fix float value to int json stores all numbers as float - var server_port :int = _config.get(SERVER_PORT, -1) - _config[SERVER_PORT] = server_port + var server_port_ :int = _config.get(SERVER_PORT, -1) + _config[SERVER_PORT] = server_port_ convert_Array_to_PackedStringArray(_config[INCLUDED]) convert_Array_to_PackedStringArray(_config[SKIPPED]) diff --git a/addons/gdUnit4/src/core/GdUnitSceneRunnerImpl.gd b/addons/gdUnit4/src/core/GdUnitSceneRunnerImpl.gd index e4f17e4d..a67edf41 100644 --- a/addons/gdUnit4/src/core/GdUnitSceneRunnerImpl.gd +++ b/addons/gdUnit4/src/core/GdUnitSceneRunnerImpl.gd @@ -24,34 +24,33 @@ var _key_on_press := [] # time factor settings var _time_factor := 1.0 -var _saved_time_scale :float var _saved_iterations_per_second :float -func _init(scene, verbose :bool, hide_push_errors = false): - _verbose = verbose +func _init(p_scene, p_verbose :bool, p_hide_push_errors = false): + _verbose = p_verbose _saved_iterations_per_second = Engine.get_physics_ticks_per_second() set_time_factor(1) # handle scene loading by resource path - if typeof(scene) == TYPE_STRING: - if !FileAccess.file_exists(scene): - if not hide_push_errors: - push_error("GdUnitSceneRunner: Can't load scene by given resource path: '%s'. The resource not exists." % scene) + if typeof(p_scene) == TYPE_STRING: + if !FileAccess.file_exists(p_scene): + if not p_hide_push_errors: + push_error("GdUnitSceneRunner: Can't load scene by given resource path: '%s'. The resource not exists." % p_scene) return - if !str(scene).ends_with("tscn"): - if not hide_push_errors: - push_error("GdUnitSceneRunner: The given resource: '%s'. is not a scene." % scene) + if !str(p_scene).ends_with("tscn"): + if not p_hide_push_errors: + push_error("GdUnitSceneRunner: The given resource: '%s'. is not a scene." % p_scene) return - _current_scene = load(scene).instantiate() + _current_scene = load(p_scene).instantiate() else: # verify we have a node instance - if not scene is Node: - if not hide_push_errors: - push_error("GdUnitSceneRunner: The given instance '%s' is not a Node." % scene) + if not p_scene is Node: + if not p_hide_push_errors: + push_error("GdUnitSceneRunner: The given instance '%s' is not a Node." % p_scene) return - _current_scene = scene + _current_scene = p_scene if _current_scene == null: - if not hide_push_errors: + if not p_hide_push_errors: push_error("GdUnitSceneRunner: Scene must be not null!") return _scene_tree = Engine.get_main_loop() @@ -160,13 +159,13 @@ func simulate_mouse_move_relative(relative :Vector2, speed :Vector2 = Vector2.ON return self -func simulate_mouse_button_pressed(buttonIndex :int, double_click := false) -> GdUnitSceneRunner: +func simulate_mouse_button_pressed(buttonIndex :MouseButton, double_click := false) -> GdUnitSceneRunner: simulate_mouse_button_press(buttonIndex, double_click) simulate_mouse_button_release(buttonIndex) return self -func simulate_mouse_button_press(buttonIndex :int, double_click := false) -> GdUnitSceneRunner: +func simulate_mouse_button_press(buttonIndex :MouseButton, double_click := false) -> GdUnitSceneRunner: var event := InputEventMouseButton.new() event.button_index = buttonIndex event.pressed = true @@ -178,7 +177,7 @@ func simulate_mouse_button_press(buttonIndex :int, double_click := false) -> GdU return _handle_input_event(event) -func simulate_mouse_button_release(buttonIndex :int) -> GdUnitSceneRunner: +func simulate_mouse_button_release(buttonIndex :MouseButton) -> GdUnitSceneRunner: var event := InputEventMouseButton.new() event.button_index = buttonIndex event.pressed = false @@ -272,12 +271,12 @@ func _scene_name() -> String: func __activate_time_factor() -> void: Engine.set_time_scale(_time_factor) - Engine.set_physics_ticks_per_second(_saved_iterations_per_second * _time_factor) + Engine.set_physics_ticks_per_second((_saved_iterations_per_second * _time_factor) as int) func __deactivate_time_factor() -> void: Engine.set_time_scale(1) - Engine.set_physics_ticks_per_second(_saved_iterations_per_second) + Engine.set_physics_ticks_per_second(_saved_iterations_per_second as int) # copy over current active modifiers diff --git a/addons/gdUnit4/src/core/GdUnitSignals.gd b/addons/gdUnit4/src/core/GdUnitSignals.gd index ff5a68a3..283770a5 100644 --- a/addons/gdUnit4/src/core/GdUnitSignals.gd +++ b/addons/gdUnit4/src/core/GdUnitSignals.gd @@ -19,9 +19,9 @@ const META_KEY := "GdUnitSignals" static func instance() -> GdUnitSignals: if Engine.has_meta(META_KEY): return Engine.get_meta(META_KEY) - var instance := GdUnitSignals.new() - Engine.set_meta(META_KEY, instance) - return instance + var instance_ := GdUnitSignals.new() + Engine.set_meta(META_KEY, instance_) + return instance_ static func dispose() -> void: diff --git a/addons/gdUnit4/src/core/GdUnitSingleton.gd b/addons/gdUnit4/src/core/GdUnitSingleton.gd index 7c61c452..192e90d5 100644 --- a/addons/gdUnit4/src/core/GdUnitSingleton.gd +++ b/addons/gdUnit4/src/core/GdUnitSingleton.gd @@ -14,26 +14,26 @@ const MEATA_KEY := "GdUnitSingletons" static func instance(name :String, clazz :Callable) -> Variant: if Engine.has_meta(name): return Engine.get_meta(name) - var singleton := clazz.call() + var singleton :Variant = clazz.call() Engine.set_meta(name, singleton) GdUnitTools.prints_verbose("Register singleton '%s:%s'" % [name, singleton]) - var singletons := Engine.get_meta(MEATA_KEY, PackedStringArray()) + var singletons :PackedStringArray = Engine.get_meta(MEATA_KEY, PackedStringArray()) singletons.append(name) Engine.set_meta(MEATA_KEY, singletons) return singleton -static func unregister(singleton :String) -> void: +static func unregister(p_singleton :String) -> void: var singletons :PackedStringArray = Engine.get_meta(MEATA_KEY, PackedStringArray()) - if singletons.has(singleton): - GdUnitTools.prints_verbose(" Unregister singleton '%s'" % singleton); - var index := singletons.find(singleton) + if singletons.has(p_singleton): + GdUnitTools.prints_verbose(" Unregister singleton '%s'" % p_singleton); + var index := singletons.find(p_singleton) singletons.remove_at(index) - var instance := Engine.get_meta(singleton) - GdUnitTools.prints_verbose(" Free singeleton instance '%s:%s'" % [singleton, instance]) - GdUnitTools.free_instance(instance) - Engine.remove_meta(singleton) - GdUnitTools.prints_verbose(" Succesfully freed '%s'" % singleton) + var instance_ :Variant = Engine.get_meta(p_singleton) + GdUnitTools.prints_verbose(" Free singeleton instance '%s:%s'" % [p_singleton, instance_]) + GdUnitTools.free_instance(instance_) + Engine.remove_meta(p_singleton) + GdUnitTools.prints_verbose(" Succesfully freed '%s'" % p_singleton) Engine.set_meta(MEATA_KEY, singletons) diff --git a/addons/gdUnit4/src/core/GdUnitStaticDictionary.gd b/addons/gdUnit4/src/core/GdUnitStaticDictionary.gd index ef78ba95..1fa3606e 100644 --- a/addons/gdUnit4/src/core/GdUnitStaticDictionary.gd +++ b/addons/gdUnit4/src/core/GdUnitStaticDictionary.gd @@ -2,9 +2,11 @@ class_name GdUnitStaticDictionary extends GdUnitSingleton + static func __data() -> Dictionary: return instance("GdUnitStaticVariables", func(): return {}) + static func add_value(key : Variant, value : Variant, overwrite := false) -> Variant: var data :Dictionary = __data() if overwrite and data.has(key): @@ -14,6 +16,7 @@ static func add_value(key : Variant, value : Variant, overwrite := false) -> Var #Engine.set_meta("GdUnitStaticVariables", data) return value + static func erase(key: Variant) -> bool: var data :Dictionary = __data() if data.has(key): @@ -22,35 +25,42 @@ static func erase(key: Variant) -> bool: return true return false + static func clear() -> void: Engine.set_meta("GdUnitStaticVariables", {}) + func find_key(value: Variant) -> Variant: - return __data().find_key(value) + return GdUnitStaticDictionary.__data().find_key(value) + static func get_value(key: Variant, default: Variant = null) -> Variant: - return __data().get(key, default) + return GdUnitStaticDictionary.__data().get(key, default) + static func has_key(key: Variant) -> bool: return __data().has(key) -static func has_keys(keys: Array) -> bool: - return __data().has_all(keys) -static func hash() -> int: - return __data().hash() +static func has_keys(keys_: Array) -> bool: + return __data().has_all(keys_) + static func is_empty() -> bool: return __data().is_empty() + static func keys() -> Array: return __data().keys() + static func size() -> int: return __data().size() + static func values() -> Array: return __data().values() + func _to_string() -> String: - return str(__data().keys()) + return str(GdUnitStaticDictionary.__data().keys()) diff --git a/addons/gdUnit4/src/core/GdUnitTestSuiteScanner.gd b/addons/gdUnit4/src/core/GdUnitTestSuiteScanner.gd index 8c004b43..1e67563f 100644 --- a/addons/gdUnit4/src/core/GdUnitTestSuiteScanner.gd +++ b/addons/gdUnit4/src/core/GdUnitTestSuiteScanner.gd @@ -42,7 +42,7 @@ func _scan_test_suites(dir :DirAccess, collected_suites :Array[Node]) -> Array[N dir.list_dir_begin() # TODOGODOT4 fill missing arguments https://github.com/godotengine/godot/pull/40547 var file_name := dir.get_next() while file_name != "": - var resource_path = _file(dir, file_name) + var resource_path = GdUnitTestSuiteScanner._file(dir, file_name) if dir.current_is_dir(): var sub_dir := DirAccess.open(resource_path) if sub_dir != null: @@ -63,7 +63,7 @@ static func _file(dir :DirAccess, file_name :String) -> String: func _parse_is_test_suite(resource_path :String) -> Node: - if not _is_script_format_supported(resource_path): + if not GdUnitTestSuiteScanner._is_script_format_supported(resource_path): return null if GdUnit3MonoAPI.is_test_suite(resource_path): return GdUnit3MonoAPI.parse_test_suite(resource_path) @@ -84,7 +84,7 @@ static func _is_script_format_supported(resource_path :String) -> bool: func _parse_test_suite(script :GDScript) -> GdUnitTestSuite: var test_suite = script.new() - test_suite.set_name(parse_test_suite_name(script)) + test_suite.set_name(GdUnitTestSuiteScanner.parse_test_suite_name(script)) # find all test cases as array of names var test_case_names := _extract_test_case_names(script) # add test cases to test suite and parse test case line nummber @@ -104,8 +104,6 @@ func _parse_test_suite(script :GDScript) -> GdUnitTestSuite: func _extract_test_case_names(script :GDScript) -> PackedStringArray: var names := PackedStringArray() for method in script.get_script_method_list(): - #prints(method["flags"], method["name"] ) - var flags :int = method["flags"] var funcName :String = method["name"] if funcName.begins_with("test"): names.append(funcName) @@ -187,7 +185,6 @@ static func _to_naming_convention(file_name :String) -> String: static func resolve_test_suite_path(source_script_path :String, test_root_folder :String = "test") -> String: - var file_extension := source_script_path.get_extension() var file_name = source_script_path.get_basename().get_file() var suite_name := _to_naming_convention(file_name) if test_root_folder.is_empty(): @@ -223,7 +220,6 @@ static func create_test_suite(test_suite_path :String, source_path :String) -> R var error := DirAccess.make_dir_recursive_absolute(test_suite_path.get_base_dir()) if error != OK: return Result.error("Can't create directoy at: %s. Error code %s" % [test_suite_path.get_base_dir(), error]) - var file_extension := test_suite_path.get_extension() var script := GDScript.new() script.source_code = GdUnitTestSuiteTemplate.build_template(source_path) var error := ResourceSaver.save(script, test_suite_path) diff --git a/addons/gdUnit4/src/core/LocalTime.gd b/addons/gdUnit4/src/core/LocalTime.gd index 9cee92d0..1ad986c0 100644 --- a/addons/gdUnit4/src/core/LocalTime.gd +++ b/addons/gdUnit4/src/core/LocalTime.gd @@ -26,24 +26,30 @@ var _minute :int var _second :int var _millisecond :int + static func now() -> LocalTime: return LocalTime.new(_get_system_time_msecs()) + static func of_unix_time(time_ms :int) -> LocalTime: return LocalTime.new(time_ms) - -static func local_time(hours :int, minutes :int, seconds :int, millis :int) -> LocalTime: + + +static func local_time(hours :int, minutes :int, seconds :int, milliseconds :int) -> LocalTime: return LocalTime.new(MILLIS_PER_HOUR * hours\ + MILLIS_PER_MINUTE * minutes\ + MILLIS_PER_SECOND * seconds\ - + millis) + + milliseconds) + func elapsed_since() -> String: - return elapsed(_get_system_time_msecs() - _time) + return LocalTime.elapsed(LocalTime._get_system_time_msecs() - _time) + func elapsed_since_ms() -> int: - return _get_system_time_msecs() - _time - + return LocalTime._get_system_time_msecs() - _time + + func plus(time_unit :TimeUnit, value :int) -> LocalTime: var addValue:int = 0 match time_unit: @@ -58,16 +64,19 @@ func plus(time_unit :TimeUnit, value :int) -> LocalTime: _init(_time + addValue) return self -static func elapsed(time_ms :int) -> String: - var local_time := LocalTime.new(time_ms) - if local_time._hour > 0: - return "%dh %dmin %ds %dms" % [local_time._hour, local_time._minute, local_time._second, local_time._millisecond] - if local_time._minute > 0: - return "%dmin %ds %dms" % [local_time._minute, local_time._second, local_time._millisecond] - if local_time._second > 0: - return "%ds %dms" % [local_time._second, local_time._millisecond] - return "%dms" % local_time._millisecond +static func elapsed(p_time_ms :int) -> String: + var local_time_ := LocalTime.new(p_time_ms) + if local_time_._hour > 0: + return "%dh %dmin %ds %dms" % [local_time_._hour, local_time_._minute, local_time_._second, local_time_._millisecond] + if local_time_._minute > 0: + return "%dmin %ds %dms" % [local_time_._minute, local_time_._second, local_time_._millisecond] + if local_time_._second > 0: + return "%ds %dms" % [local_time_._second, local_time_._millisecond] + return "%dms" % local_time_._millisecond + + +@warning_ignore("integer_division") # create from epoch timestamp in ms func _init(time :int): _time = time @@ -76,21 +85,27 @@ func _init(time :int): _second = (time / MILLIS_PER_SECOND) % 60 _millisecond = time % 1000 + func hour() -> int: return _hour + func minute() -> int: return _minute + func second() -> int: return _second + func millis() -> int: return _millisecond + func _to_string() -> String: return "%02d:%02d:%02d.%03d" % [_hour, _minute, _second, _millisecond] + # wraper to old OS.get_system_time_msecs() function static func _get_system_time_msecs() -> int: return Time.get_unix_time_from_system() * 1000 as int diff --git a/addons/gdUnit4/src/core/Result.gd b/addons/gdUnit4/src/core/Result.gd index c161872a..6b709537 100644 --- a/addons/gdUnit4/src/core/Result.gd +++ b/addons/gdUnit4/src/core/Result.gd @@ -13,62 +13,76 @@ var _warn_message := "" var _error_message := "" var _value :Variant = null + static func empty() -> Result: var result := Result.new() result._state = EMPTY return result -static func success(value :Variant) -> Result: - assert(value != null) #,"The value must not be NULL") + +static func success(p_value :Variant) -> Result: + assert(p_value != null, "The value must not be NULL") var result := Result.new() - result._value = value + result._value = p_value result._state = SUCCESS return result -static func warn(warn_message :String, value :Variant = null) -> Result: - assert(not warn_message.is_empty()) #,"The message must not be empty") + +static func warn(p_warn_message :String, p_value :Variant = null) -> Result: + assert(not p_warn_message.is_empty()) #,"The message must not be empty") var result := Result.new() - result._value = value - result._warn_message = warn_message + result._value = p_value + result._warn_message = p_warn_message result._state = WARN return result -static func error(error_message :String, error :int = 0) -> Result: - assert(not error_message.is_empty()) #,"The message must not be empty") + +static func error(p_error_message :String) -> Result: + assert(not p_error_message.is_empty(), "The message must not be empty") var result := Result.new() result._value = null - result._error_message = error_message + result._error_message = p_error_message result._state = ERROR return result + func is_success() -> bool: return _state == SUCCESS + func is_warn() -> bool: return _state == WARN + func is_error() -> bool: return _state == ERROR + func is_empty() -> bool: return _state == EMPTY + func value() -> Variant: return _value - -func or_else(value): + + +func or_else(p_value): if not is_success(): - return value + return p_value return value() + func error_message() -> String: return _error_message + func warn_message() -> String: return _warn_message - + + func _to_string() -> String: - return str(serialize(self)) + return str(Result.serialize(self)) + static func serialize(result :Result) -> Dictionary: if result == null: @@ -80,6 +94,7 @@ static func serialize(result :Result) -> Dictionary: "err_msg" : result._error_message } + static func deserialize(config :Dictionary) -> Result: var result := Result.new() result._value = str_to_var(config.get("value", "")) @@ -87,4 +102,3 @@ static func deserialize(config :Dictionary) -> Result: result._error_message = config.get("err_msg", null) result._state = config.get("state") return result - diff --git a/addons/gdUnit4/src/core/_TestCase.gd b/addons/gdUnit4/src/core/_TestCase.gd index ccd72751..ade904ac 100644 --- a/addons/gdUnit4/src/core/_TestCase.gd +++ b/addons/gdUnit4/src/core/_TestCase.gd @@ -31,36 +31,36 @@ func _init(): _default_timeout = GdUnitSettings.test_timeout() -func configure(name: String, line_number: int, script_path: String, timeout :int = DEFAULT_TIMEOUT, fuzzers :Array = [], iterations: int = 1, seed_ :int = -1) -> _TestCase: - set_name(name) - _line_number = line_number - _fuzzers = fuzzers - _iterations = iterations - _seed = seed_ - _script_path = script_path +@warning_ignore("shadowed_variable_base_class") +func configure(p_name: String, p_line_number: int, p_script_path: String, p_timeout :int = DEFAULT_TIMEOUT, p_fuzzers :Array = [], p_iterations: int = 1, p_seed :int = -1) -> _TestCase: + set_name(p_name) + _line_number = p_line_number + _fuzzers = p_fuzzers + _iterations = p_iterations + _seed = p_seed + _script_path = p_script_path _timeout = _default_timeout - if timeout != DEFAULT_TIMEOUT: - _timeout = timeout + if p_timeout != DEFAULT_TIMEOUT: + _timeout = p_timeout return self -func execute(test_parameter := Array(), iteration := 0): - - _current_iteration = iteration - 1 - if iteration == 0: +func execute(p_test_parameter := Array(), p_iteration := 0): + _current_iteration = p_iteration - 1 + if p_iteration == 0: _set_failure_handler() set_timeout() _monitor.start() - if not test_parameter.is_empty(): - update_fuzzers(test_parameter, iteration) - _execute_test_case(name, test_parameter) + if not p_test_parameter.is_empty(): + update_fuzzers(p_test_parameter, p_iteration) + _execute_test_case(name, p_test_parameter) else: _execute_test_case(name, []) await completed _monitor.stop() - for report in _monitor.reports(): - if report.is_error(): - _report = report + for report_ in _monitor.reports(): + if report_.is_error(): + _report = report_ _interupted = true @@ -69,6 +69,7 @@ func dispose(): _remove_failure_handler() +@warning_ignore("shadowed_variable_base_class", "redundant_await") func _execute_test_case(name :String, test_parameter :Array): # needs at least on await otherwise it braks the awaiting chain await get_parent().callv(name, test_parameter) @@ -194,8 +195,8 @@ func skip(skipped :bool, error :String = "") -> void: _skip_info = error -func set_test_parameters(test_parameters :Array) -> void: - _test_parameters = test_parameters +func set_test_parameters(p_test_parameters :Array) -> void: + _test_parameters = p_test_parameters func set_test_parameter_index(index :int) -> void: @@ -211,11 +212,11 @@ func test_parameter_index() -> int: func test_case_names() -> PackedStringArray: - var test_case_names := PackedStringArray() + var test_cases := PackedStringArray() var test_name = get_name() for index in _test_parameters.size(): - test_case_names.append("%s:%d %s" % [test_name, index, str(_test_parameters[index]).replace('"', "'")]) - return test_case_names + test_cases.append("%s:%d %s" % [test_name, index, str(_test_parameters[index]).replace('"', "'")]) + return test_cases func _to_string(): diff --git a/addons/gdUnit4/src/core/event/GdUnitEvent.gd b/addons/gdUnit4/src/core/event/GdUnitEvent.gd index 098c74e3..173f64d7 100644 --- a/addons/gdUnit4/src/core/event/GdUnitEvent.gd +++ b/addons/gdUnit4/src/core/event/GdUnitEvent.gd @@ -1,7 +1,6 @@ class_name GdUnitEvent extends Resource - const WARNINGS = "warnings" const FAILED = "failed" const ERRORS = "errors" @@ -29,96 +28,120 @@ var _total_count :int = 0 var _statistics := Dictionary() var _reports := Array() -func suite_before(resource_path :String, suite_name :String, total_count) -> GdUnitEvent: + +func suite_before(p_resource_path :String, p_suite_name :String, p_total_count) -> GdUnitEvent: _event_type = TESTSUITE_BEFORE - _resource_path = resource_path - _suite_name = suite_name + _resource_path = p_resource_path + _suite_name = p_suite_name _test_name = "before" - _total_count = total_count + _total_count = p_total_count return self -func suite_after(resource_path :String, suite_name :String, statistics :Dictionary = {}, reports :Array = []) -> GdUnitEvent: + +func suite_after(p_resource_path :String, p_suite_name :String, p_statistics :Dictionary = {}, p_reports :Array = []) -> GdUnitEvent: _event_type = TESTSUITE_AFTER - _resource_path = resource_path - _suite_name = suite_name + _resource_path = p_resource_path + _suite_name = p_suite_name _test_name = "after" - _statistics = statistics - _reports = reports + _statistics = p_statistics + _reports = p_reports return self -func test_before(resource_path :String, suite_name:String, test_name:String) -> GdUnitEvent: + +func test_before(p_resource_path :String, p_suite_name :String, p_test_name :String) -> GdUnitEvent: _event_type = TESTCASE_BEFORE - _resource_path = resource_path - _suite_name = suite_name - _test_name = test_name + _resource_path = p_resource_path + _suite_name = p_suite_name + _test_name = p_test_name return self -func test_after(resource_path :String, suite_name :String, test_name :String, statistics :Dictionary = {}, reports :Array = []) -> GdUnitEvent: + +func test_after(p_resource_path :String, p_suite_name :String, p_test_name :String, p_statistics :Dictionary = {}, p_reports :Array = []) -> GdUnitEvent: _event_type = TESTCASE_AFTER - _resource_path = resource_path - _suite_name = suite_name - _test_name = test_name - _statistics = statistics - _reports = reports + _resource_path = p_resource_path + _suite_name = p_suite_name + _test_name = p_test_name + _statistics = p_statistics + _reports = p_reports return self + func type() -> int: return _event_type + func suite_name() -> String: return _suite_name + func test_name() -> String: return _test_name + func elapsed_time() -> int: return _statistics.get(ELAPSED_TIME, 0) + func orphan_nodes() -> int: return _statistics.get(ORPHAN_NODES, 0) -func statistic(type :String) -> int: - return _statistics.get(type, 0) + +func statistic(p_type :String) -> int: + return _statistics.get(p_type, 0) + func total_count() -> int: return _total_count + func success_count() -> int: return total_count() - error_count() - failed_count() - skipped_count() + func error_count() -> int: return _statistics.get(ERROR_COUNT, 0) - + + func failed_count() -> int: return _statistics.get(FAILED_COUNT, 0) - + + func skipped_count() -> int: return _statistics.get(SKIPPED_COUNT, 0) + func resource_path() -> String: return _resource_path + func is_success() -> bool: return not is_warning() and not is_failed() and not is_error() and not is_skipped() + func is_warning() -> bool: return _statistics.get(WARNINGS, false) + func is_failed() -> bool: return _statistics.get(FAILED, false) + func is_error() -> bool: return _statistics.get(ERRORS, false) + func is_skipped() -> bool: return _statistics.get(SKIPPED, false) + func reports() -> Array: return _reports + func _to_string(): return "Event: %d %s:%s, %s, %s" % [_event_type, _suite_name, _test_name, _statistics, _reports] + func serialize() -> Dictionary: var serialized := { "type" : _event_type, @@ -131,6 +154,7 @@ func serialize() -> Dictionary: serialized["reports"] = _serialize_TestReports() return serialized + func deserialize(serialized :Dictionary) -> GdUnitEvent: _event_type = serialized.get("type", null) _resource_path = serialized.get("resource_path", null) @@ -141,16 +165,17 @@ func deserialize(serialized :Dictionary) -> GdUnitEvent: _reports = _deserialize_reports(serialized.get("reports",[])) return self + func _serialize_TestReports() -> Array: var serialized_reports := Array() for report in _reports: serialized_reports.append(report.serialize()) return serialized_reports -func _deserialize_reports(reports :Array) -> Array: + +func _deserialize_reports(p_reports :Array) -> Array: var deserialized_reports := Array() - for report in reports: + for report in p_reports: var test_report := GdUnitReport.new().deserialize(report) deserialized_reports.append(test_report) return deserialized_reports - diff --git a/addons/gdUnit4/src/core/event/GdUnitEventInit.gd b/addons/gdUnit4/src/core/event/GdUnitEventInit.gd index 896aa0c5..eeb88dce 100644 --- a/addons/gdUnit4/src/core/event/GdUnitEventInit.gd +++ b/addons/gdUnit4/src/core/event/GdUnitEventInit.gd @@ -4,14 +4,15 @@ extends GdUnitEvent var _total_testsuites :int -func _init(total_testsuites :int,total_tests :int): +func _init(p_total_testsuites :int, p_total_count :int): _event_type = INIT - _total_testsuites = total_testsuites - _total_count = total_tests + _total_testsuites = p_total_testsuites + _total_count = p_total_count func total_test_suites() -> int: return _total_testsuites + func total_tests() -> int: return _total_count diff --git a/addons/gdUnit4/src/core/parse/GdClassDescriptor.gd b/addons/gdUnit4/src/core/parse/GdClassDescriptor.gd index cc20a2ba..d2ac7048 100644 --- a/addons/gdUnit4/src/core/parse/GdClassDescriptor.gd +++ b/addons/gdUnit4/src/core/parse/GdClassDescriptor.gd @@ -7,22 +7,28 @@ var _parent = null var _is_inner_class :bool var _functions -func _init(name :String,is_inner_class :bool,functions :Array): - _name = name - _is_inner_class = is_inner_class - _functions = functions -func set_parent_clazz(parent :GdClassDescriptor): - _parent = parent +func _init(p_name :String, p_is_inner_class :bool, p_functions :Array): + _name = p_name + _is_inner_class = p_is_inner_class + _functions = p_functions + + +func set_parent_clazz(p_parent :GdClassDescriptor): + _parent = p_parent + func name() -> String: return _name + func parent() -> GdClassDescriptor: return _parent + func is_inner_class() -> bool: return _is_inner_class + func functions() -> Array: return _functions diff --git a/addons/gdUnit4/src/core/parse/GdDefaultValueDecoder.gd b/addons/gdUnit4/src/core/parse/GdDefaultValueDecoder.gd index 954ec049..2df3aa2e 100644 --- a/addons/gdUnit4/src/core/parse/GdDefaultValueDecoder.gd +++ b/addons/gdUnit4/src/core/parse/GdDefaultValueDecoder.gd @@ -9,8 +9,8 @@ var _decoders = { TYPE_STRING_NAME: Callable(self, "_on_type_string"), TYPE_BOOL: Callable(self, "_on_type_bool"), TYPE_RID: Callable(self, "_on_type_RID"), - TYPE_RECT2: Callable(self, "_on_decode_Rect2").bind(_regex("P: ?(\\(.+\\)), S: ?(\\(.+\\))")), - TYPE_RECT2I: Callable(self, "_on_decode_Rect2i").bind(_regex("P: ?(\\(.+\\)), S: ?(\\(.+\\))")), + TYPE_RECT2: Callable(self, "_on_decode_Rect2").bind(GdDefaultValueDecoder._regex("P: ?(\\(.+\\)), S: ?(\\(.+\\))")), + TYPE_RECT2I: Callable(self, "_on_decode_Rect2i").bind(GdDefaultValueDecoder._regex("P: ?(\\(.+\\)), S: ?(\\(.+\\))")), TYPE_TRANSFORM2D: Callable(self, "_on_type_Transform2D"), TYPE_TRANSFORM3D: Callable(self, "_on_type_Transform3D"), TYPE_PACKED_COLOR_ARRAY: Callable(self, "_on_type_PackedColorArray"), @@ -25,10 +25,15 @@ static func _regex(pattern :String) -> RegEx: return regex +func get_decoder(type :int) -> Callable: + return _decoders.get(type) + + func _on_type_self(value :Variant) -> String: return str(value) +@warning_ignore("unused_parameter") func _on_type_nill(value :Variant) -> String: return "null" @@ -60,6 +65,7 @@ func _on_type_PackedColorArray(value :Variant) -> String: return "invalid" +@warning_ignore("unused_parameter") func _on_type_RID(value :Variant) -> String: return "RID()" @@ -81,7 +87,7 @@ func _on_decode_Rect2i(value :Variant, regEx :RegEx) -> String: static func decode(type :int, value :Variant) -> String: - var decoder :Callable = instance("GdUnitDefaultValueDecoders", func(): return GdDefaultValueDecoder.new())._decoders.get(type) + var decoder :Callable = instance("GdUnitDefaultValueDecoders", func(): return GdDefaultValueDecoder.new()).get_decoder(type) if decoder == null: push_error("No value decoder registered for type '%d'! Please open a Bug issue at 'https://github.com/MikeSchulze/gdUnit4/issues/new/choose'." % type) return "null" diff --git a/addons/gdUnit4/src/core/parse/GdFunctionArgument.gd b/addons/gdUnit4/src/core/parse/GdFunctionArgument.gd index 73c39df6..6c444936 100644 --- a/addons/gdUnit4/src/core/parse/GdFunctionArgument.gd +++ b/addons/gdUnit4/src/core/parse/GdFunctionArgument.gd @@ -8,37 +8,46 @@ var _default_value :Variant const UNDEFINED = "<-NO_ARG->" const ARG_PARAMETERIZED_TEST := "test_parameters" -func _init(name :String, type :int = TYPE_MAX, default_value :Variant = UNDEFINED): - _name = name - _type = type - _default_value = default_value + +func _init(p_name :String, p_type :int = TYPE_MAX, p_default_value :Variant = UNDEFINED): + _name = p_name + _type = p_type + _default_value = p_default_value + func name() -> String: return _name + func default() -> Variant: - return GdObjects.convert(_default_value, _type) + return convert(_default_value, _type) + func value_as_string() -> String: if has_default(): return str(_default_value) return "" + func type() -> int: return _type + func has_default() -> bool: return _default_value != UNDEFINED + func is_parameter_set() -> bool: return _name == ARG_PARAMETERIZED_TEST + static func get_parameter_set(parameters :Array) -> GdFunctionArgument: for current in parameters: if current != null and current.is_parameter_set(): return current return null + func _to_string() -> String: var s = _name if _type != TYPE_MAX: diff --git a/addons/gdUnit4/src/core/parse/GdFunctionDescriptor.gd b/addons/gdUnit4/src/core/parse/GdFunctionDescriptor.gd index 9f99f4e3..ea1d9a83 100644 --- a/addons/gdUnit4/src/core/parse/GdFunctionDescriptor.gd +++ b/addons/gdUnit4/src/core/parse/GdFunctionDescriptor.gd @@ -13,25 +13,25 @@ var _args : Array[GdFunctionArgument] var _varargs :Array[GdFunctionArgument] -func _init(name :String, - line_number :int, - is_virtual :bool, - is_static :bool, - is_engine :bool, - return_type :int, - return_class :String, - args : Array[GdFunctionArgument], - varargs :Array[GdFunctionArgument] = []): - _name = name - _line_number = line_number - _return_type = return_type - _return_class = return_class - _is_virtual = is_virtual - _is_static = is_static - _is_engine = is_engine +func _init(p_name :String, + p_line_number :int, + p_is_virtual :bool, + p_is_static :bool, + p_is_engine :bool, + p_return_type :int, + p_return_class :String, + p_args : Array[GdFunctionArgument], + p_varargs :Array[GdFunctionArgument] = []): + _name = p_name + _line_number = p_line_number + _return_type = p_return_type + _return_class = p_return_class + _is_virtual = p_is_virtual + _is_static = p_is_static + _is_engine = p_is_engine _is_coroutine = false - _args = args - _varargs = varargs + _args = p_args + _varargs = p_varargs func name() -> String: @@ -135,14 +135,14 @@ func _to_string() -> String: # extract function description given by Object.get_method_list() -static func extract_from(method_descriptor :Dictionary) -> GdFunctionDescriptor: - var function_flags :int = method_descriptor["flags"] - var is_virtual :bool = function_flags & METHOD_FLAG_VIRTUAL - var is_static :bool = function_flags & METHOD_FLAG_STATIC - var is_vararg :bool = function_flags & METHOD_FLAG_VARARG - var is_const :bool = function_flags & METHOD_FLAG_CONST - var is_core :bool = function_flags & METHOD_FLAG_OBJECT_CORE - var is_default :bool = function_flags & METHOD_FLAGS_DEFAULT +static func extract_from(descriptor :Dictionary) -> GdFunctionDescriptor: + var function_flags :int = descriptor["flags"] + var is_virtual_ :bool = function_flags & METHOD_FLAG_VIRTUAL + var is_static_ :bool = function_flags & METHOD_FLAG_STATIC + var is_vararg_ :bool = function_flags & METHOD_FLAG_VARARG + #var is_const :bool = function_flags & METHOD_FLAG_CONST + #var is_core :bool = function_flags & METHOD_FLAG_OBJECT_CORE + #var is_default :bool = function_flags & METHOD_FLAGS_DEFAULT #prints("is_virtual: ", is_virtual) #prints("is_static: ", is_static) #prints("is_const: ", is_const) @@ -150,15 +150,15 @@ static func extract_from(method_descriptor :Dictionary) -> GdFunctionDescriptor: #prints("is_default: ", is_default) #prints("is_vararg: ", is_vararg) return GdFunctionDescriptor.new( - method_descriptor["name"], + descriptor["name"], -1, - is_virtual, - is_static, + is_virtual_, + is_static_, true, - _extract_return_type(method_descriptor["return"]), - method_descriptor["return"]["class_name"], - _extract_args(method_descriptor), - _build_varargs(is_vararg) + _extract_return_type(descriptor["return"]), + descriptor["return"]["class_name"], + _extract_args(descriptor), + _build_varargs(is_vararg_) ) # temporary exclude GlobalScope enums @@ -195,10 +195,10 @@ static func _extract_return_type(return_info :Dictionary) -> Variant: return type -static func _extract_args(method_descriptor :Dictionary) -> Array[GdFunctionArgument]: - var args :Array[GdFunctionArgument] = [] - var arguments :Array = method_descriptor["args"] - var defaults :Array = method_descriptor["default_args"] +static func _extract_args(descriptor :Dictionary) -> Array[GdFunctionArgument]: + var args_ :Array[GdFunctionArgument] = [] + var arguments :Array = descriptor["args"] + var defaults :Array = descriptor["default_args"] # iterate backwards because the default values are stored from right to left while not arguments.is_empty(): var arg :Dictionary = arguments.pop_back() @@ -207,19 +207,19 @@ static func _extract_args(method_descriptor :Dictionary) -> Array[GdFunctionArgu var arg_default := GdFunctionArgument.UNDEFINED if not defaults.is_empty(): arg_default = _argument_default_value(arg, defaults.pop_back()) - args.push_front(GdFunctionArgument.new(arg_name, arg_type, arg_default)) - return args + args_.push_front(GdFunctionArgument.new(arg_name, arg_type, arg_default)) + return args_ -static func _build_varargs(is_vararg :bool) -> Array[GdFunctionArgument]: - var varargs :Array[GdFunctionArgument] = [] - if not is_vararg: - return varargs +static func _build_varargs(p_is_vararg :bool) -> Array[GdFunctionArgument]: + var varargs_ :Array[GdFunctionArgument] = [] + if not p_is_vararg: + return varargs_ # if function has vararg we need to handle this manually by adding 10 default arguments var type := GdObjects.TYPE_VARARG for index in 10: - varargs.push_back(GdFunctionArgument.new("vararg%d_" % index, type, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE)) - return varargs + varargs_.push_back(GdFunctionArgument.new("vararg%d_" % index, type, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE)) + return varargs_ static func _argument_name(arg :Dictionary) -> String: @@ -269,7 +269,6 @@ static func _argument_default_value(arg :Dictionary, default_value) -> String: TYPE_PACKED_COLOR_ARRAY: return GdDefaultValueDecoder.decode(type, default_value) TYPE_OBJECT: - var clazz_name := arg["class_name"] as String if default_value == null: return "null" if GdObjects.is_primitive_type(default_value): diff --git a/addons/gdUnit4/src/core/parse/GdScriptParser.gd b/addons/gdUnit4/src/core/parse/GdScriptParser.gd index dc342610..c28f1077 100644 --- a/addons/gdUnit4/src/core/parse/GdScriptParser.gd +++ b/addons/gdUnit4/src/core/parse/GdScriptParser.gd @@ -79,11 +79,12 @@ class Token extends RefCounted: var _is_operator: bool var _regex :RegEx - func _init(token: String, is_operator := false, regex :RegEx = null) -> void: - _token = token - _is_operator = is_operator - _consumed = token.length() - _regex = regex + + func _init(p_token: String, p_is_operator := false, p_regex :RegEx = null) -> void: + _token = p_token + _is_operator = p_is_operator + _consumed = p_token.length() + _regex = p_regex func match(input: String, pos: int) -> bool: if _regex: @@ -154,40 +155,40 @@ class FuzzerToken extends Token: class Variable extends Token: var _plain_value var _typed_value - var _type := TYPE_NIL + var _type :int = TYPE_NIL - func _init(value: String): - super(value) - _type = _scan_type(value) - _plain_value = value - _typed_value = _cast_to_type(value, _type) + func _init(p_value: String): + super(p_value) + _type = _scan_type(p_value) + _plain_value = p_value + _typed_value = _cast_to_type(p_value, _type) - func _scan_type(value: String) -> int: - if value.begins_with("\"") and value.ends_with("\""): + func _scan_type(p_value: String) -> int: + if p_value.begins_with("\"") and p_value.ends_with("\""): return TYPE_STRING - var type := GdObjects.string_to_type(value) - if type != TYPE_NIL: - return type - if value.is_valid_int(): + var type_ := GdObjects.string_to_type(p_value) + if type_ != TYPE_NIL: + return type_ + if p_value.is_valid_int(): return TYPE_INT - if value.is_valid_float(): + if p_value.is_valid_float(): return TYPE_FLOAT - if value.is_valid_hex_number(): + if p_value.is_valid_hex_number(): return TYPE_INT return TYPE_OBJECT - func _cast_to_type(value :String, type: int) -> Variant: - match type: + func _cast_to_type(p_value :String, p_type: int) -> Variant: + match p_type: TYPE_STRING: - return value#.substr(1, value.length() - 2) + return p_value#.substr(1, p_value.length() - 2) TYPE_INT: - return value.to_int() + return p_value.to_int() TYPE_FLOAT: - return value.to_float() - return value + return p_value.to_float() + return p_value func is_variable() -> bool: @@ -248,7 +249,7 @@ class TokenInnerClass extends Token: for row_index in range(offset+1, source_rows.size()): # scan until next non tab var source_row := source_rows[row_index] - var row = _strip_leading_spaces(source_row) + var row = TokenInnerClass._strip_leading_spaces(source_row) if row.is_empty() or row.begins_with("\t") or row.begins_with("#"): # fold all line to left by removing leading tabs and spaces if source_row.begins_with("\t"): @@ -260,7 +261,7 @@ class TokenInnerClass extends Token: _content.append(source_row) continue break - _consumed += _consumed_bytes("".join(_content)) + _consumed += TokenInnerClass._consumed_bytes("".join(_content)) func _to_string(): @@ -326,30 +327,32 @@ func extract_clazz_name(value :String) -> String: return result.get_string(2) +@warning_ignore("unused_parameter") func tokenize_inner_class(source_code: String, current: int, token: Token) -> Token: var clazz_name := extract_clazz_name(source_code.substr(current, 64)) return TokenInnerClass.new(clazz_name) +@warning_ignore("assert_always_false") func _process_values(left: Token, token_stack: Array, operator: Token) -> Token: # precheck if left.is_variable() and operator.is_operator(): var lvalue = left.value() var value = null - var next_token = token_stack.pop_front() as Token + var next_token_ = token_stack.pop_front() as Token if operator == OPERATOR_ADD: - value = lvalue + next_token.value() + value = lvalue + next_token_.value() elif operator == OPERATOR_SUB: - value = lvalue - next_token.value() + value = lvalue - next_token_.value() elif operator == OPERATOR_MUL: - value = lvalue * next_token.value() + value = lvalue * next_token_.value() elif operator == OPERATOR_DIV: - value = lvalue / next_token.value() + value = lvalue / next_token_.value() elif operator == OPERATOR_REMAINDER: - value = lvalue & next_token.value() + value = lvalue & next_token_.value() else: - assert(false) #,"Unsupported operator %s" % operator) + assert(false, "Unsupported operator %s" % operator) return Variable.new( str(value)) return operator @@ -450,7 +453,6 @@ func parse_arguments(input: String) -> Array[GdFunctionArgument]: break arg_value = arg_value.lstrip(" ") if arg_type == TYPE_NIL and arg_value != GdFunctionArgument.UNDEFINED: - var value_type := TYPE_STRING if arg_value.begins_with("Color."): arg_type = TYPE_COLOR elif arg_value.begins_with("Vector2."): @@ -476,7 +478,7 @@ func parse_arguments(input: String) -> Array[GdFunctionArgument]: # Parse an string for an argument with given name and returns the value # if the argument not found the is returned func parse_argument(row: String, argument_name: String, default_value): - var input := clean_up_row(row) + var input := GdScriptParser.clean_up_row(row) var argument_found := false var current_index := 0 var token :Token = null @@ -532,7 +534,7 @@ func _parse_end_function(input: String, remove_trailing_char := false) -> String func extract_inner_class(source_rows: PackedStringArray, clazz_name :String) -> PackedStringArray: for row_index in source_rows.size(): - var input := clean_up_row(source_rows[row_index]) + var input := GdScriptParser.clean_up_row(source_rows[row_index]) var token := next_token(input, 0) if token.is_inner_class(): if token.is_class_name(clazz_name): @@ -575,7 +577,7 @@ func load_source_code(script :GDScript, script_path :PackedStringArray) -> Packe if class_path.size() > 1: _scanned_inner_classes.append(class_path[1]) - var source_code := to_unix_format(script.source_code) + var source_code := GdScriptParser.to_unix_format(script.source_code) var source_rows := source_code.split("\n") # extract all inner class names # want to extract an inner class? @@ -586,11 +588,11 @@ func load_source_code(script :GDScript, script_path :PackedStringArray) -> Packe func get_class_name(script :GDScript) -> String: - var source_code := to_unix_format(script.source_code) + var source_code := GdScriptParser.to_unix_format(script.source_code) var source_rows := source_code.split("\n") for index in min(10, source_rows.size()): - var input = clean_up_row(source_rows[index]) + var input = GdScriptParser.clean_up_row(source_rows[index]) var token := next_token(input, 0) if token == TOKEN_CLASS_NAME: token = tokenize_value(input, token._consumed, token) @@ -600,7 +602,7 @@ func get_class_name(script :GDScript) -> String: func parse_func_name(row :String) -> String: - var input = clean_up_row(row) + var input = GdScriptParser.clean_up_row(row) var current_index = 0 var token := next_token(input, current_index) current_index += token._consumed @@ -619,7 +621,7 @@ func parse_functions(rows :PackedStringArray, clazz_name :String, clazz_path :Pa # step over inner class functions if row.begins_with("\t"): continue - var input = clean_up_row(row) + var input = GdScriptParser.clean_up_row(row) # skip comments and empty lines if input.begins_with("#") or input.length() == 0: continue @@ -640,7 +642,7 @@ func is_func_coroutine(rows :PackedStringArray, index :int) -> bool: is_coroutine = row.contains("await") if is_coroutine: return true - var input = clean_up_row(row) + var input = GdScriptParser.clean_up_row(row) var token := next_token(input, 0) if token == TOKEN_FUNCTION_STATIC_DECLARATION or token == TOKEN_FUNCTION_DECLARATION: break @@ -698,7 +700,7 @@ func is_virtual_func(clazz_name :String, clazz_path :PackedStringArray, func_nam func is_static_func(func_signature :String) -> bool: - var input := clean_up_row(func_signature) + var input := GdScriptParser.clean_up_row(func_signature) var token := next_token(input, 0) return token == TOKEN_FUNCTION_STATIC_DECLARATION @@ -728,15 +730,15 @@ func extract_functions(script :GDScript, clazz_name :String, clazz_path :PackedS func parse(clazz_name :String, clazz_path :PackedStringArray) -> Result: if clazz_path.is_empty(): return Result.error("Invalid script path '%s'" % clazz_path) - var is_inner_class := is_inner_class(clazz_path) + var is_inner_class_ := is_inner_class(clazz_path) var script :GDScript = load(clazz_path[0]) var function_descriptors := extract_functions(script, clazz_name, clazz_path) - var gd_class := GdClassDescriptor.new(clazz_name, is_inner_class, function_descriptors) + var gd_class := GdClassDescriptor.new(clazz_name, is_inner_class_, function_descriptors) # iterate over class dependencies script = script.get_base_script() while script != null: clazz_name = GdObjects.extract_class_name_from_class_path([script.resource_path]) function_descriptors = extract_functions(script, clazz_name, clazz_path) - gd_class.set_parent_clazz(GdClassDescriptor.new(clazz_name, is_inner_class, function_descriptors)) + gd_class.set_parent_clazz(GdClassDescriptor.new(clazz_name, is_inner_class_, function_descriptors)) script = script.get_base_script() return Result.success(gd_class) diff --git a/addons/gdUnit4/src/core/report/GdUnitReport.gd b/addons/gdUnit4/src/core/report/GdUnitReport.gd index 6dab6fbc..90b260a8 100644 --- a/addons/gdUnit4/src/core/report/GdUnitReport.gd +++ b/addons/gdUnit4/src/core/report/GdUnitReport.gd @@ -18,10 +18,10 @@ var _line_number :int var _message :String -func create(type, line_number :int, message :String) -> GdUnitReport: - _type = type - _line_number = line_number - _message = message +func create(p_type, p_line_number :int, p_message :String) -> GdUnitReport: + _type = p_type + _line_number = p_line_number + _message = p_message return self diff --git a/addons/gdUnit4/src/extractors/GdUnitFuncValueExtractor.gd b/addons/gdUnit4/src/extractors/GdUnitFuncValueExtractor.gd index 1538a85f..bf6a2a3a 100644 --- a/addons/gdUnit4/src/extractors/GdUnitFuncValueExtractor.gd +++ b/addons/gdUnit4/src/extractors/GdUnitFuncValueExtractor.gd @@ -5,16 +5,19 @@ extends GdUnitValueExtractor var _func_names :Array var _args :Array -func _init(func_name :String,args :Array): +func _init(func_name :String, p_args :Array): _func_names = func_name.split(".") - _args = args + _args = p_args + func func_names() -> Array: return _func_names + func args() -> Array: return _args + # Extracts a value by given `func_name` and `args`, # Allows to use a chained list of functions setarated ba a dot. # e.g. "func_a.func_b.name" @@ -43,6 +46,7 @@ func extract_value(value): return value return value + func _call_func(value, func_name :String): # for array types we need to call explicit by function name, using funcref is only supported for Objects # TODO extend to all array functions diff --git a/addons/gdUnit4/src/fuzzers/FuzzerTool.gd b/addons/gdUnit4/src/fuzzers/FuzzerTool.gd index 4bebbca6..64a81186 100644 --- a/addons/gdUnit4/src/fuzzers/FuzzerTool.gd +++ b/addons/gdUnit4/src/fuzzers/FuzzerTool.gd @@ -20,12 +20,12 @@ static func create_fuzzer(source :GDScript, function: GdFunctionArgument) -> Fuz script.source_code = source_code var temp_dir := "res://addons/gdUnit4/.tmp" DirAccess.make_dir_recursive_absolute(temp_dir) - var resource_path := "%s/%s" % [temp_dir, "_fuzzer_bulder%d.gd" % Time.get_ticks_msec()] - var err := ResourceSaver.save(script, resource_path, ResourceSaver.FLAG_BUNDLE_RESOURCES|ResourceSaver.FLAG_REPLACE_SUBRESOURCE_PATHS) + var resource_path_ := "%s/%s" % [temp_dir, "_fuzzer_bulder%d.gd" % Time.get_ticks_msec()] + var err := ResourceSaver.save(script, resource_path_, ResourceSaver.FLAG_BUNDLE_RESOURCES|ResourceSaver.FLAG_REPLACE_SUBRESOURCE_PATHS) if err != OK: prints("Script loading error", error_string(err)) return null - script = ResourceLoader.load(resource_path, "GDScript", ResourceLoader.CACHE_MODE_IGNORE); + script = ResourceLoader.load(resource_path_, "GDScript", ResourceLoader.CACHE_MODE_IGNORE); var instance :Object = script.new() instance.queue_free() DirAccess.remove_absolute(script.resource_path) diff --git a/addons/gdUnit4/src/fuzzers/IntFuzzer.gd b/addons/gdUnit4/src/fuzzers/IntFuzzer.gd index 8a4778a8..40015629 100644 --- a/addons/gdUnit4/src/fuzzers/IntFuzzer.gd +++ b/addons/gdUnit4/src/fuzzers/IntFuzzer.gd @@ -11,20 +11,22 @@ var _from :int = 0 var _to : int = 0 var _mode : int = NORMAL + func _init(from: int, to: int, mode :int = NORMAL): assert(from <= to, "Invalid range!") _from = from _to = to _mode = mode + func next_value() -> int: var value := randi_range(_from, _to) match _mode: NORMAL: return value EVEN: - return (value / 2) * 2 + return int((value / 2.0) * 2) ODD: - return (value / 2) * 2 + 1 + return int((value / 2.0) * 2 + 1) _: return value diff --git a/addons/gdUnit4/src/fuzzers/StringFuzzer.gd b/addons/gdUnit4/src/fuzzers/StringFuzzer.gd index 13fa8351..b75e0423 100644 --- a/addons/gdUnit4/src/fuzzers/StringFuzzer.gd +++ b/addons/gdUnit4/src/fuzzers/StringFuzzer.gd @@ -14,7 +14,7 @@ func _init(min_length :int,max_length :int,pattern :String = DEFAULT_CHARSET): assert(not null or not pattern.is_empty()) _min_length = min_length _max_length = max_length - _charset = extract_charset(pattern) + _charset = StringFuzzer.extract_charset(pattern) static func extract_charset(pattern :String) -> PackedByteArray: var reg := RegEx.new() diff --git a/addons/gdUnit4/src/matchers/AnyArgumentMatcher.gd b/addons/gdUnit4/src/matchers/AnyArgumentMatcher.gd index 41d795d2..6eca57a6 100644 --- a/addons/gdUnit4/src/matchers/AnyArgumentMatcher.gd +++ b/addons/gdUnit4/src/matchers/AnyArgumentMatcher.gd @@ -1,5 +1,7 @@ class_name AnyArgumentMatcher extends GdUnitArgumentMatcher - + + +@warning_ignore("unused_parameter") func is_match(value) -> bool: return true diff --git a/addons/gdUnit4/src/matchers/GdUnitArgumentMatcher.gd b/addons/gdUnit4/src/matchers/GdUnitArgumentMatcher.gd index 1fb3b1d6..dff6dac2 100644 --- a/addons/gdUnit4/src/matchers/GdUnitArgumentMatcher.gd +++ b/addons/gdUnit4/src/matchers/GdUnitArgumentMatcher.gd @@ -1,7 +1,8 @@ -# base class of all argument matchers +## The base class of all argument matchers class_name GdUnitArgumentMatcher extends RefCounted +@warning_ignore("unused_parameter") func is_match(value) -> bool: return true diff --git a/addons/gdUnit4/src/matchers/GdUnitArgumentMatchers.gd b/addons/gdUnit4/src/matchers/GdUnitArgumentMatchers.gd index 0a15de27..8baf229b 100644 --- a/addons/gdUnit4/src/matchers/GdUnitArgumentMatchers.gd +++ b/addons/gdUnit4/src/matchers/GdUnitArgumentMatchers.gd @@ -3,10 +3,12 @@ extends GdUnitStaticDictionary const TYPE_ANY = TYPE_MAX + 100 + func _init(): for build_in_type in GdObjects.all_types(): - add_value(build_in_type, AnyBuildInTypeArgumentMatcher.new(build_in_type)) - add_value(TYPE_ANY, AnyArgumentMatcher.new()) + GdUnitStaticDictionary.add_value(build_in_type, AnyBuildInTypeArgumentMatcher.new(build_in_type)) + GdUnitStaticDictionary.add_value(TYPE_ANY, AnyArgumentMatcher.new()) + static func to_matcher(arguments :Array, auto_deep_check_mode := false) -> ChainedArgumentMatcher: var matchers := Array() @@ -19,11 +21,14 @@ static func to_matcher(arguments :Array, auto_deep_check_mode := false) -> Chain matchers.append(EqualsArgumentMatcher.new(arg, auto_deep_check_mode)) return ChainedArgumentMatcher.new(matchers) + static func any() -> GdUnitArgumentMatcher: return get_value(TYPE_ANY) + static func by_type(type :int) -> GdUnitArgumentMatcher: return get_value(type) + static func any_class(clazz) -> GdUnitArgumentMatcher: return AnyClazzArgumentMatcher.new(clazz) diff --git a/addons/gdUnit4/src/mocking/GdUnitMock.gd b/addons/gdUnit4/src/mocking/GdUnitMock.gd index 8c567738..b552b8b5 100644 --- a/addons/gdUnit4/src/mocking/GdUnitMock.gd +++ b/addons/gdUnit4/src/mocking/GdUnitMock.gd @@ -1,24 +1,27 @@ class_name GdUnitMock extends RefCounted -# do call the real implementation +## do call the real implementation const CALL_REAL_FUNC = "CALL_REAL_FUNC" -# do return a default value for primitive types or null +## do return a default value for primitive types or null const RETURN_DEFAULTS = "RETURN_DEFAULTS" -# do return a default value for primitive types and a fully mocked value for Object types -# builds full deep mocked object +## do return a default value for primitive types and a fully mocked value for Object types +## builds full deep mocked object const RETURN_DEEP_STUB = "RETURN_DEEP_STUB" var _value - + + func _init(value): _value = value + func checked(obj :Object): - if not _is_mock_or_spy( obj, "__do_return"): + if not GdUnitMock._is_mock_or_spy( obj, "__do_return"): return obj return obj.__do_return(_value) + static func _is_mock_or_spy(obj :Object, func_sig :String) -> bool: if obj is GDScript and not obj.get_script().has_script_method(func_sig): push_error("Error: You try to use a non mock or spy!") diff --git a/addons/gdUnit4/src/mocking/GdUnitMockBuilder.gd b/addons/gdUnit4/src/mocking/GdUnitMockBuilder.gd index 736dae8e..2ceeef99 100644 --- a/addons/gdUnit4/src/mocking/GdUnitMockBuilder.gd +++ b/addons/gdUnit4/src/mocking/GdUnitMockBuilder.gd @@ -130,7 +130,6 @@ static func is_mockable(clazz :Variant, push_errors :bool=false) -> bool: return true # verify class type if GdObjects.is_object(clazz): - var mockable := false if GdObjects.is_instance(clazz): if push_errors: push_error("It is not allowed to mock an instance '%s', use class name instead, Read 'Mocker' documentation for details" % clazz) diff --git a/addons/gdUnit4/src/monitor/GdUnitMemMonitor.gd b/addons/gdUnit4/src/monitor/GdUnitMemMonitor.gd index 6d6207d2..f6e3dfa1 100644 --- a/addons/gdUnit4/src/monitor/GdUnitMemMonitor.gd +++ b/addons/gdUnit4/src/monitor/GdUnitMemMonitor.gd @@ -1,9 +1,9 @@ class_name GdUnitMemMonitor extends GdUnitMonitor -var _orphan_nodes_start :int -var _orphan_nodes_end :int -var _orphan_total :int +var _orphan_nodes_start :float +var _orphan_nodes_end :float +var _orphan_total :float func _init(name :String = ""): super("MemMonitor:" + name) @@ -22,5 +22,5 @@ func stop(): _orphan_total += _orphan_nodes_end - _orphan_nodes_start func orphan_nodes() -> int: - return _orphan_total + return _orphan_total as int diff --git a/addons/gdUnit4/src/monitor/GdUnitMonitor.gd b/addons/gdUnit4/src/monitor/GdUnitMonitor.gd index ff92276d..1516d754 100644 --- a/addons/gdUnit4/src/monitor/GdUnitMonitor.gd +++ b/addons/gdUnit4/src/monitor/GdUnitMonitor.gd @@ -5,17 +5,20 @@ extends Resource var _id :String # constructs new Monitor with given id -func _init(id :String): - _id = id +func _init(p_id :String): + _id = p_id + # Returns the id of the monitor to uniqe identify func id() -> String: return _id + # starts monitoring func start(): pass + # stops monitoring func stop(): pass diff --git a/addons/gdUnit4/src/monitor/GodotGdErrorMonitor.gd b/addons/gdUnit4/src/monitor/GodotGdErrorMonitor.gd index 9eeedb1f..0999df35 100644 --- a/addons/gdUnit4/src/monitor/GodotGdErrorMonitor.gd +++ b/addons/gdUnit4/src/monitor/GodotGdErrorMonitor.gd @@ -29,16 +29,16 @@ func stop(): func reports() -> Array[GdUnitReport]: - var reports :Array[GdUnitReport] = [] + var reports_ :Array[GdUnitReport] = [] if _report_enabled: var loggs := _collect_log_entries() for index in loggs.size(): var message := loggs[index] if _is_report_script_errors() and message.contains(USER_SCRIPT_ERROR): - reports.append(_report_runtime_error(message, loggs[index+1])) + reports_.append(GodotGdErrorMonitor._report_runtime_error(message, loggs[index+1])) if _is_report_push_errors() and message.contains(USER_PUSH_ERROR): - reports.append(_report_user_error(message, loggs[index+1])) - return reports + reports_.append(GodotGdErrorMonitor._report_user_error(message, loggs[index+1])) + return reports_ func is_reporting_enabled() -> bool: diff --git a/addons/gdUnit4/src/network/GdUnitTcpClient.gd b/addons/gdUnit4/src/network/GdUnitTcpClient.gd index a32c71fb..83c7c316 100644 --- a/addons/gdUnit4/src/network/GdUnitTcpClient.gd +++ b/addons/gdUnit4/src/network/GdUnitTcpClient.gd @@ -4,8 +4,6 @@ extends Node signal connection_succeeded(message) signal connection_failed(message) -# connetion timeout in ms -var _connection_timeout = 2.000 var _timer :Timer var _host :String @@ -14,6 +12,7 @@ var _client_id :int var _connected :bool var _stream :StreamPeerTCP + func _ready(): _connected = false _stream = StreamPeerTCP.new() @@ -23,6 +22,7 @@ func _ready(): _timer.set_one_shot(true) _timer.connect('timeout', Callable(self, '_connecting_timeout')) + func stop() -> void: console("Client: disconnect from server") if _stream != null: @@ -31,6 +31,7 @@ func stop() -> void: _stream.disconnect_from_host() _connected = false + func start(host :String, port :int) -> Result: _host = host _port = port @@ -45,6 +46,7 @@ func start(host :String, port :int) -> Result: return Result.error("GdUnit3: Can't establish client, error code: %s" % err) return Result.success("GdUnit3: Client connected checked port %d" % port) + func _process(_delta): match _stream.get_status(): StreamPeerTCP.STATUS_NONE: @@ -68,13 +70,13 @@ func _process(_delta): StreamPeerTCP.STATUS_CONNECTED: if not _connected: - var rpc = null + var rpc_ = null set_process(false) - while rpc == null: + while rpc_ == null: await get_tree().create_timer(0.500).timeout - rpc = rpc_receive() + rpc_ = rpc_receive() set_process(true) - _client_id = rpc.client_id() + _client_id = rpc_.client_id() console("Connected to Server: %d" % _client_id) emit_signal("connection_succeeded", "Connect to TCP Server %s:%d success." % [_host, _port]) _connected = true @@ -86,20 +88,24 @@ func _process(_delta): emit_signal("connection_failed", "Connect to TCP Server %s:%d faild!" % [_host, _port]) return + func is_client_connected() -> bool: return _connected + func process_rpc() -> void: if _stream.get_available_bytes() > 0: - var rpc = rpc_receive() - if rpc is RPCClientDisconnect: + var rpc_ = rpc_receive() + if rpc_ is RPCClientDisconnect: stop() -func rpc_send(rpc :RPC) -> void: + +func rpc_send(p_rpc :RPC) -> void: if _stream != null: - var data := GdUnitServerConstants.JSON_RESPONSE_DELIMITER + rpc.serialize() + GdUnitServerConstants.JSON_RESPONSE_DELIMITER + var data := GdUnitServerConstants.JSON_RESPONSE_DELIMITER + p_rpc.serialize() + GdUnitServerConstants.JSON_RESPONSE_DELIMITER _stream.put_data(data.to_ascii_buffer()) + func rpc_receive() -> RPC: if _stream != null: while _stream.get_available_bytes() > 0: @@ -117,12 +123,15 @@ func rpc_receive() -> RPC: return RPC.deserialize(decoded) return null + func console(message :String) -> void: prints("TCP Client:", message) pass + func _on_connection_failed(message :String): console("connection faild: " + message) + func _on_connection_succeeded(message :String): console("connected: " + message) diff --git a/addons/gdUnit4/src/network/GdUnitTcpServer.gd b/addons/gdUnit4/src/network/GdUnitTcpServer.gd index 6209bce3..58e006b2 100644 --- a/addons/gdUnit4/src/network/GdUnitTcpServer.gd +++ b/addons/gdUnit4/src/network/GdUnitTcpServer.gd @@ -15,9 +15,9 @@ class TcpConnection extends Node: var _readBuffer :String = "" - func _init(server): - #assert(server is TCPServer) - _stream = server.take_connection() + func _init(p_server): + #assert(p_server is TCPServer) + _stream = p_server.take_connection() _stream.set_big_endian(true) _id = _stream.get_instance_id() rpc_send(RPCClientConnect.new().with_id(_id)) @@ -42,8 +42,8 @@ class TcpConnection extends Node: return get_parent() - func rpc_send(rpc :RPC) -> void: - _stream.put_var(rpc.serialize(), true) + func rpc_send(p_rpc :RPC) -> void: + _stream.put_var(p_rpc.serialize(), true) func _process(_delta): @@ -63,10 +63,10 @@ class TcpConnection extends Node: else: var received_data := partial_data[1] as PackedByteArray for package in _read_next_data_packages(received_data): - var rpc = RPC.deserialize(package) - if rpc is RPCClientDisconnect: + var rpc_ = RPC.deserialize(package) + if rpc_ is RPCClientDisconnect: close() - server().rpc_data.emit(rpc) + server().rpc_data.emit(rpc_) func _read_next_data_packages(data_package :PackedByteArray) -> PackedStringArray: @@ -87,8 +87,8 @@ class TcpConnection extends Node: return json_array - func console(message :String) -> void: - #print_debug("TCP Connection:", message) + func console(_message :String) -> void: + #print_debug("TCP Connection:", _message) pass @@ -157,6 +157,6 @@ func _on_client_disconnected(client_id :int): -func console(message :String) -> void: - #print_debug("TCP Server:", message) +func console(_message :String) -> void: + #print_debug("TCP Server:", _message) pass diff --git a/addons/gdUnit4/src/network/rpc/RPCClientConnect.gd b/addons/gdUnit4/src/network/rpc/RPCClientConnect.gd index a3c57618..2c8540bf 100644 --- a/addons/gdUnit4/src/network/rpc/RPCClientConnect.gd +++ b/addons/gdUnit4/src/network/rpc/RPCClientConnect.gd @@ -3,9 +3,11 @@ extends RPC var _client_id :int -func with_id(client_id :int) -> RPCClientConnect: - _client_id = client_id + +func with_id(p_client_id :int) -> RPCClientConnect: + _client_id = p_client_id return self + func client_id() -> int: return _client_id diff --git a/addons/gdUnit4/src/network/rpc/RPCClientDisconnect.gd b/addons/gdUnit4/src/network/rpc/RPCClientDisconnect.gd index 37448d67..1bfc3029 100644 --- a/addons/gdUnit4/src/network/rpc/RPCClientDisconnect.gd +++ b/addons/gdUnit4/src/network/rpc/RPCClientDisconnect.gd @@ -3,9 +3,11 @@ extends RPC var _client_id :int -func with_id(client_id :int) -> RPCClientDisconnect: - _client_id = client_id + +func with_id(p_client_id :int) -> RPCClientDisconnect: + _client_id = p_client_id return self + func client_id() -> int: return _client_id diff --git a/addons/gdUnit4/src/network/rpc/RPCGdUnitEvent.gd b/addons/gdUnit4/src/network/rpc/RPCGdUnitEvent.gd index 2b058137..2cc3e108 100644 --- a/addons/gdUnit4/src/network/rpc/RPCGdUnitEvent.gd +++ b/addons/gdUnit4/src/network/rpc/RPCGdUnitEvent.gd @@ -3,13 +3,16 @@ extends RPC var _event :Dictionary -static func of(event :GdUnitEvent) -> RPCGdUnitEvent: + +static func of(p_event :GdUnitEvent) -> RPCGdUnitEvent: var rpc = RPCGdUnitEvent.new() - rpc._event = event.serialize() + rpc._event = p_event.serialize() return rpc + func event() -> GdUnitEvent: return GdUnitEvent.new().deserialize(_event) -func to_string(): + +func _to_string(): return "RPCGdUnitEvent: " + str(_event) diff --git a/addons/gdUnit4/src/network/rpc/RPCGdUnitTestSuite.gd b/addons/gdUnit4/src/network/rpc/RPCGdUnitTestSuite.gd index 0b053340..d8d8b00e 100644 --- a/addons/gdUnit4/src/network/rpc/RPCGdUnitTestSuite.gd +++ b/addons/gdUnit4/src/network/rpc/RPCGdUnitTestSuite.gd @@ -11,5 +11,5 @@ static func of(test_suite) -> RPCGdUnitTestSuite: func dto() -> GdUnitResourceDto: return GdUnitTestSuiteDto.new().deserialize(_data) -func to_string(): +func _to_string(): return "RPCGdUnitTestSuite: " + str(_data) diff --git a/addons/gdUnit4/src/network/rpc/RPCMessage.gd b/addons/gdUnit4/src/network/rpc/RPCMessage.gd index d07f53d9..6beafa2d 100644 --- a/addons/gdUnit4/src/network/rpc/RPCMessage.gd +++ b/addons/gdUnit4/src/network/rpc/RPCMessage.gd @@ -3,13 +3,13 @@ extends RPC var _message :String -static func of(message :String) -> RPCMessage: +static func of(p_message :String) -> RPCMessage: var rpc = RPCMessage.new() - rpc._message = message + rpc._message = p_message return rpc func message() -> String: return _message -func to_string(): +func _to_string(): return "RPCMessage: " + _message diff --git a/addons/gdUnit4/src/network/rpc/dtos/GdUnitTestSuiteDto.gd b/addons/gdUnit4/src/network/rpc/dtos/GdUnitTestSuiteDto.gd index 92752119..fb93edc5 100644 --- a/addons/gdUnit4/src/network/rpc/dtos/GdUnitTestSuiteDto.gd +++ b/addons/gdUnit4/src/network/rpc/dtos/GdUnitTestSuiteDto.gd @@ -3,26 +3,31 @@ extends GdUnitResourceDto var _test_cases_by_name := Dictionary() + func serialize(test_suite :Node) -> Dictionary: var serialized := super.serialize(test_suite) - var test_cases := Array() - serialized["test_cases"] = test_cases + var test_cases_ := Array() + serialized["test_cases"] = test_cases_ for test_case in test_suite.get_children(): - test_cases.append(GdUnitTestCaseDto.new().serialize(test_case)) + test_cases_.append(GdUnitTestCaseDto.new().serialize(test_case)) return serialized + func deserialize(data :Dictionary) -> GdUnitResourceDto: super.deserialize(data) - var test_cases :Array = data.get("test_cases", Array()) - for test_case in test_cases: + var test_cases_ :Array = data.get("test_cases", Array()) + for test_case in test_cases_: add_test_case(GdUnitTestCaseDto.new().deserialize(test_case)) return self + func add_test_case(test_case :GdUnitTestCaseDto): _test_cases_by_name[test_case.name()] = test_case + func test_case_count() -> int: return _test_cases_by_name.size() + func test_cases() -> Array: return _test_cases_by_name.values() diff --git a/addons/gdUnit4/src/report/GdUnitReportSummary.gd b/addons/gdUnit4/src/report/GdUnitReportSummary.gd index 15303f14..08f02eb0 100644 --- a/addons/gdUnit4/src/report/GdUnitReportSummary.gd +++ b/addons/gdUnit4/src/report/GdUnitReportSummary.gd @@ -8,7 +8,6 @@ const CHARACTERS_TO_ENCODE := { var _resource_path :String var _name :String -var _suite_count := 0 var _test_count := 0 var _failure_count := 0 var _error_count := 0 @@ -92,23 +91,23 @@ func succes_rate() -> String: return calculate_succes_rate(test_count(), error_count(), failure_count()) -static func calculate_state(error_count :int, failure_count :int, orphan_count :int) -> String: - if error_count > 0: +func calculate_state(p_error_count :int, p_failure_count :int, p_orphan_count :int) -> String: + if p_error_count > 0: return "error" - if failure_count > 0: + if p_failure_count > 0: return "failure" - if orphan_count > 0: + if p_orphan_count > 0: return "warning" return "success" -static func calculate_succes_rate(test_count :int, error_count: int, failure_count: int) -> String: - if failure_count == 0: +func calculate_succes_rate(p_test_count :int, p_error_count :int, p_failure_count :int) -> String: + if p_failure_count == 0: return "100%" - return "%d" % ((test_count-failure_count-error_count) * 100 / test_count) + "%" + return "%d" % ((p_test_count-p_failure_count-p_error_count) * 100.0 / p_test_count) + "%" -func create_summary(report_dir :String) -> String: +func create_summary(_report_dir :String) -> String: return "" diff --git a/addons/gdUnit4/src/report/GdUnitTestCaseReport.gd b/addons/gdUnit4/src/report/GdUnitTestCaseReport.gd index ff48f95e..f0c824b0 100644 --- a/addons/gdUnit4/src/report/GdUnitTestCaseReport.gd +++ b/addons/gdUnit4/src/report/GdUnitTestCaseReport.gd @@ -7,18 +7,18 @@ var _rtf :RichTextLabel func _init(rtf :RichTextLabel, - resource_path :String, - suite_name :String, + p_resource_path :String, + p_suite_name :String, test_name :String, is_error := false, is_failed := false, orphans :int = 0, is_skipped := false, failure_reports :Array = [], - duration :int = 0): + p_duration :int = 0): _rtf = rtf - _resource_path = resource_path - _suite_name = suite_name + _resource_path = p_resource_path + _suite_name = p_suite_name _name = test_name _test_count = 1 _error_count = is_error @@ -26,7 +26,7 @@ func _init(rtf :RichTextLabel, _orphan_count = orphans _skipped_count = is_skipped _failure_reports = failure_reports - _duration = duration + _duration = p_duration func suite_name() -> String: @@ -52,7 +52,7 @@ func convert_rtf_to_html(bbcode :String) -> String: return "\n".join(converted) -func create_record(report_dir :String) -> String: +func create_record(_report_dir :String) -> String: return GdUnitHtmlPatterns.TABLE_RECORD_TESTCASE\ .replace(GdUnitHtmlPatterns.REPORT_STATE, report_state())\ .replace(GdUnitHtmlPatterns.TESTCASE_NAME, name())\ diff --git a/addons/gdUnit4/src/report/GdUnitTestSuiteReport.gd b/addons/gdUnit4/src/report/GdUnitTestSuiteReport.gd index d9208a26..2f9d8164 100644 --- a/addons/gdUnit4/src/report/GdUnitTestSuiteReport.gd +++ b/addons/gdUnit4/src/report/GdUnitTestSuiteReport.gd @@ -4,10 +4,10 @@ extends GdUnitReportSummary var _time_stamp :int -func _init(resource_path :String,name :String): - _resource_path = resource_path - _name = name - _time_stamp = Time.get_unix_time_from_system() +func _init(p_resource_path :String, p_name :String): + _resource_path = p_resource_path + _name = p_name + _time_stamp = Time.get_unix_time_from_system() as int func create_record(report_link :String) -> String: @@ -41,8 +41,8 @@ func write(report_dir :String) -> String: return report_output_path -func set_duration(duration :int) -> void: - _duration = duration +func set_duration(p_duration :int) -> void: + _duration = p_duration func time_stamp() -> int: diff --git a/addons/gdUnit4/src/report/JUnitXmlReport.gd b/addons/gdUnit4/src/report/JUnitXmlReport.gd index 0d3181b3..6c1f8a6d 100644 --- a/addons/gdUnit4/src/report/JUnitXmlReport.gd +++ b/addons/gdUnit4/src/report/JUnitXmlReport.gd @@ -46,7 +46,7 @@ func build_junit_report(report :GdUnitReportSummary) -> String: .attribute(ATTR_NAME, "report_%s" % _iteration)\ .attribute(ATTR_TESTS, report.test_count())\ .attribute(ATTR_FAILURES, report.failure_count())\ - .attribute(ATTR_TIME, to_time(report.duration()))\ + .attribute(ATTR_TIME, JUnitXmlReport.to_time(report.duration()))\ .add_childs(build_test_suites(report)) var as_string = test_suites.to_xml() test_suites.dispose() @@ -68,7 +68,7 @@ func build_test_suites(summary :GdUnitReportSummary) -> Array: .attribute(ATTR_FAILURES, suite_report.failure_count())\ .attribute(ATTR_ERRORS, suite_report.error_count())\ .attribute(ATTR_SKIPPED, suite_report.skipped_count())\ - .attribute(ATTR_TIME, to_time(suite_report.duration()))\ + .attribute(ATTR_TIME, JUnitXmlReport.to_time(suite_report.duration()))\ .add_childs(build_test_cases(suite_report))) return test_suites @@ -80,7 +80,7 @@ func build_test_cases(suite_report :GdUnitTestSuiteReport) -> Array: test_cases.append( XmlElement.new("testcase")\ .attribute(ATTR_NAME, report.name())\ .attribute(ATTR_CLASSNAME, report.suite_name())\ - .attribute(ATTR_TIME, to_time(report.duration()))\ + .attribute(ATTR_TIME, JUnitXmlReport.to_time(report.duration()))\ .add_childs(build_reports(report))) return test_cases @@ -93,12 +93,12 @@ func build_reports(testReport :GdUnitTestCaseReport) -> Array: if report.is_failure(): failure_reports.append( XmlElement.new("failure")\ .attribute(ATTR_MESSAGE, "FAILED: %s:%d" % [testReport._resource_path, report.line_number()])\ - .attribute(ATTR_TYPE, to_type(report.type()))\ + .attribute(ATTR_TYPE, JUnitXmlReport.to_type(report.type()))\ .text(convert_rtf_to_text(report.message()))) elif report.is_error(): failure_reports.append( XmlElement.new("error")\ .attribute(ATTR_MESSAGE, "ERROR: %s:%d" % [testReport._resource_path, report.line_number()])\ - .attribute(ATTR_TYPE, to_type(report.type()))\ + .attribute(ATTR_TYPE, JUnitXmlReport.to_type(report.type()))\ .text(convert_rtf_to_text(report.message()))) if testReport.skipped_count(): for failure in testReport._failure_reports: diff --git a/addons/gdUnit4/src/report/XmlElement.gd b/addons/gdUnit4/src/report/XmlElement.gd index 4ccd7e10..62757781 100644 --- a/addons/gdUnit4/src/report/XmlElement.gd +++ b/addons/gdUnit4/src/report/XmlElement.gd @@ -25,8 +25,8 @@ func attribute(name :String, value) -> XmlElement: return self -func text(text :String) -> XmlElement: - _text = text if text.ends_with("\n") else text + "\n" +func text(p_text :String) -> XmlElement: + _text = p_text if p_text.ends_with("\n") else p_text + "\n" return self @@ -63,5 +63,5 @@ func to_xml() -> String: "text": cdata(_text)}) -func cdata(text :String) -> String: - return "" if text.is_empty() else "\n".format({"text" : text}) +func cdata(p_text :String) -> String: + return "" if p_text.is_empty() else "\n".format({"text" : p_text}) diff --git a/addons/gdUnit4/src/spy/GdUnitSpyBuilder.gd b/addons/gdUnit4/src/spy/GdUnitSpyBuilder.gd index e78d348c..393fc7ac 100644 --- a/addons/gdUnit4/src/spy/GdUnitSpyBuilder.gd +++ b/addons/gdUnit4/src/spy/GdUnitSpyBuilder.gd @@ -2,7 +2,7 @@ class_name GdUnitSpyBuilder extends GdUnitClassDoubler -static func build(caller :Object, to_spy, push_errors :bool = true, debug_write = false): +static func build(caller :Object, to_spy, debug_write = false): var memory_pool :GdUnitMemoryPool.POOL = caller.get_meta(GdUnitMemoryPool.META_PARAM) # if resource path load it before diff --git a/addons/gdUnit4/src/ui/GdUnitFonts.gd b/addons/gdUnit4/src/ui/GdUnitFonts.gd index 27b015a2..43dceb2c 100644 --- a/addons/gdUnit4/src/ui/GdUnitFonts.gd +++ b/addons/gdUnit4/src/ui/GdUnitFonts.gd @@ -36,5 +36,5 @@ static func init_fonts(item: CanvasItem) -> float: static func create_font(font_resource: String, size: float) -> Font: var font := FontFile.new() font.font_data = load(font_resource) - font.fixed_size = size + font.fixed_size = int(size) return font diff --git a/addons/gdUnit4/src/ui/GdUnitInspector.gd b/addons/gdUnit4/src/ui/GdUnitInspector.gd index d0c78e9e..18106713 100644 --- a/addons/gdUnit4/src/ui/GdUnitInspector.gd +++ b/addons/gdUnit4/src/ui/GdUnitInspector.gd @@ -33,7 +33,7 @@ func _ready(): if Engine.is_editor_hint(): _getEditorThemes(_editor_interface) # preload previous test execution - _runner_config.load() + _runner_config.load_config() if GdUnitSettings.is_update_notification_enabled(): var update_tool = load("res://addons/gdUnit4/src/update/GdUnitUpdateNotify.tscn").instantiate() add_child(update_tool) @@ -71,7 +71,7 @@ func _getEditorThemes(interface :EditorInterface) -> void: if interface == null: return # example to access current theme - var editiorTheme := interface.get_base_control().theme + #var editiorTheme := interface.get_base_control().theme # setup inspector button icons #var stylebox_types :PackedStringArray = editiorTheme.get_stylebox_type_list() #for stylebox_type in stylebox_types: @@ -80,7 +80,7 @@ func _getEditorThemes(interface :EditorInterface) -> void: # prints(editiorTheme.get_stylebox_list(stylebox_type)) #var style:StyleBoxFlat = editiorTheme.get_stylebox("panel", "Tree") #style.bg_color = Color.RED - var locale = interface.get_editor_settings().get_setting("interface/editor/editor_language") + #var locale = interface.get_editor_settings().get_setting("interface/editor/editor_language") #sessions_label.add_theme_color_override("font_color", get_color("contrast_color_2", "Editor")) #status_label.add_theme_color_override("font_color", get_color("contrast_color_2", "Editor")) #no_sessions_label.add_theme_color_override("font_color", get_color("contrast_color_2", "Editor")) @@ -92,7 +92,7 @@ func add_file_system_dock_context_menu() -> void: if script == null: return true return GdObjects.is_test_suite(script) == is_test_suite - var is_enabled := func is_enabled(script :GDScript): + var is_enabled := func is_enabled(_script :GDScript): return !_runButton.disabled var run_test := func run_test(resource_paths :PackedStringArray, debug :bool): run_test_suites(resource_paths, debug) @@ -106,7 +106,7 @@ func add_file_system_dock_context_menu() -> void: func add_script_editor_context_menu(): var is_test_suite := func is_visible(script :GDScript, is_test_suite :bool): return GdObjects.is_test_suite(script) == is_test_suite - var is_enabled := func is_enabled(script :GDScript): + var is_enabled := func is_enabled(_script :GDScript): return !_runButton.disabled var run_test := func run_test(script :Script, text_edit :TextEdit, debug :bool): var cursor_line := text_edit.get_caret_line() @@ -146,7 +146,7 @@ func run_test_suites(test_suite_paths :PackedStringArray, debug :bool, rerun :bo if not rerun: var result := _runner_config.clear()\ .add_test_suites(test_suite_paths)\ - .save() + .save_config() if result.is_error(): push_error(result.error_message()) return @@ -158,7 +158,7 @@ func run_test_case(test_suite_resource_path :String, test_case :String, test_par if not rerun: var result := _runner_config.clear()\ .add_test_case(test_suite_resource_path, test_case, test_param_index)\ - .save() + .save_config() if result.is_error(): push_error(result.error_message()) return @@ -173,7 +173,7 @@ func _gdUnit_run(debug :bool) -> void: grab_focus() show() # save current selected excution config - var result := _runner_config.set_server_port(Engine.get_meta("gdunit_server_port")).save() + var result := _runner_config.set_server_port(Engine.get_meta("gdunit_server_port")).save_config() if result.is_error(): push_error(result.error_message()) return diff --git a/addons/gdUnit4/src/ui/ScriptEditorControls.gd b/addons/gdUnit4/src/ui/ScriptEditorControls.gd index 5e3b2886..0dee58ff 100644 --- a/addons/gdUnit4/src/ui/ScriptEditorControls.gd +++ b/addons/gdUnit4/src/ui/ScriptEditorControls.gd @@ -60,21 +60,19 @@ static func save_an_open_script(script_path :String, close := false) -> bool: #prints("save_an_open_script", script_path, close) if !Engine.is_editor_hint(): return false - var editor_interface := editor_interface() - var script_editor := script_editor() + var interface := editor_interface() + var editor := script_editor() var editor_popup := _menu_popup() - var open_file_index = 0 # search for the script in all opened editor scrips - for open_script in script_editor.get_open_scripts(): + for open_script in editor.get_open_scripts(): if open_script.resource_path == script_path: # select the script in the editor - editor_interface.edit_script(open_script, 0); + interface.edit_script(open_script, 0); # save and close editor_popup.id_pressed.emit(FILE_SAVE) if close: editor_popup.id_pressed.emit(FILE_CLOSE) return true - open_file_index +=1 return false @@ -88,19 +86,20 @@ static func close_open_editor_scripts() -> void: if Engine.is_editor_hint(): _menu_popup().id_pressed.emit(CLOSE_ALL) + # Edits the given script. # The script is openend in the current editor and selected in the file system dock. # The line and column on which to open the script can also be specified. # The script will be open with the user-configured editor for the script's language which may be an external editor. static func edit_script(script_path :String, line_number :int = -1): - var editor_interface := editor_interface() - var file_system := editor_interface.get_resource_filesystem() + var interface := editor_interface() + var file_system := interface.get_resource_filesystem() file_system.update_file(script_path) - var file_system_dock := editor_interface.get_file_system_dock() + var file_system_dock := interface.get_file_system_dock() file_system_dock.navigate_to_path(script_path) - editor_interface.select_file(script_path) + interface.select_file(script_path) var script = load(script_path) - editor_interface.edit_script(script, line_number) + interface.edit_script(script, line_number) # Register the given context menu to the current script editor diff --git a/addons/gdUnit4/src/ui/menu/EditorFileSystemContextMenuHandler.gd b/addons/gdUnit4/src/ui/menu/EditorFileSystemContextMenuHandler.gd index 2ab8c200..0793a146 100644 --- a/addons/gdUnit4/src/ui/menu/EditorFileSystemContextMenuHandler.gd +++ b/addons/gdUnit4/src/ui/menu/EditorFileSystemContextMenuHandler.gd @@ -50,7 +50,7 @@ func on_context_menu_pressed(id :int, file_tree :Tree) -> void: menu_item.execute([selected_test_suites]) -func collect_testsuites(menu_item :GdUnitContextMenuItem, file_tree :Tree) -> PackedStringArray: +func collect_testsuites(_menu_item :GdUnitContextMenuItem, file_tree :Tree) -> PackedStringArray: var file_system := editor_interface().get_resource_filesystem() var selected_item := file_tree.get_selected() var selected_test_suites := PackedStringArray() @@ -71,7 +71,7 @@ func collect_testsuites(menu_item :GdUnitContextMenuItem, file_tree :Tree) -> Pa # Returns the EditorInterface instance -static func editor_interface() -> EditorInterface: +func editor_interface() -> EditorInterface: if not Engine.has_meta("GdUnitEditorPlugin"): return null var plugin :EditorPlugin = Engine.get_meta("GdUnitEditorPlugin") diff --git a/addons/gdUnit4/src/ui/menu/GdUnitContextMenuItem.gd b/addons/gdUnit4/src/ui/menu/GdUnitContextMenuItem.gd index 0eea89e3..2078ed9b 100644 --- a/addons/gdUnit4/src/ui/menu/GdUnitContextMenuItem.gd +++ b/addons/gdUnit4/src/ui/menu/GdUnitContextMenuItem.gd @@ -11,12 +11,12 @@ var _is_enabled :Callable var _runnable: Callable -func _init(id :MENU_ID, name :StringName, is_visible :Callable, is_enabled: Callable, runnable: Callable): - self.id = id - self.name = name - _is_visible = is_visible - _is_enabled = is_enabled - _runnable = runnable +func _init(p_id :MENU_ID, p_name :StringName, p_is_visible :Callable, p_is_enabled: Callable, p_runnable: Callable): + self.id = p_id + self.name = p_name + _is_visible = p_is_visible + _is_enabled = p_is_enabled + _runnable = p_runnable var id: MENU_ID: diff --git a/addons/gdUnit4/src/ui/parts/InspectorTreeMainPanel.gd b/addons/gdUnit4/src/ui/parts/InspectorTreeMainPanel.gd index 07f38a7f..0e107081 100644 --- a/addons/gdUnit4/src/ui/parts/InspectorTreeMainPanel.gd +++ b/addons/gdUnit4/src/ui/parts/InspectorTreeMainPanel.gd @@ -74,7 +74,7 @@ func clear_tree_item_cache() -> void: _item_hash.clear() -static func _find_item(parent :TreeItem, resource_path :String, test_case :String = "") -> TreeItem: +func _find_item(parent :TreeItem, resource_path :String, test_case :String = "") -> TreeItem: var item = _find_by_resource_path(parent, resource_path) if not item: return null @@ -83,45 +83,45 @@ static func _find_item(parent :TreeItem, resource_path :String, test_case :Strin return _find_by_name(item, test_case) -static func _find_by_resource_path(parent :TreeItem, resource_path :String) -> TreeItem: +func _find_by_resource_path(parent :TreeItem, resource_path :String) -> TreeItem: for item in parent.get_children(): if item.get_meta(META_RESOURCE_PATH) == resource_path: return item return null -static func _find_by_name(parent :TreeItem, name :String) -> TreeItem: +func _find_by_name(parent :TreeItem, item_name :String) -> TreeItem: for item in parent.get_children(): - if item.get_meta(META_GDUNIT_NAME) == name: + if item.get_meta(META_GDUNIT_NAME) == item_name: return item return null -static func is_state_running(item :TreeItem) -> bool: +func is_state_running(item :TreeItem) -> bool: return item.has_meta(META_GDUNIT_STATE) and item.get_meta(META_GDUNIT_STATE) == STATE.RUNNING -static func is_state_success(item :TreeItem) -> bool: +func is_state_success(item :TreeItem) -> bool: return item.has_meta(META_GDUNIT_STATE) and item.get_meta(META_GDUNIT_STATE) == STATE.SUCCESS -static func is_state_warning(item :TreeItem) -> bool: +func is_state_warning(item :TreeItem) -> bool: return item.has_meta(META_GDUNIT_STATE) and item.get_meta(META_GDUNIT_STATE) == STATE.WARNING -static func is_state_failed(item :TreeItem) -> bool: +func is_state_failed(item :TreeItem) -> bool: return item.has_meta(META_GDUNIT_STATE) and item.get_meta(META_GDUNIT_STATE) == STATE.FAILED -static func is_state_error(item :TreeItem) -> bool: +func is_state_error(item :TreeItem) -> bool: return item.has_meta(META_GDUNIT_STATE) and (item.get_meta(META_GDUNIT_STATE) == STATE.ERROR or item.get_meta(META_GDUNIT_STATE) == STATE.ABORDED) -static func is_item_state_orphan(item :TreeItem) -> bool: +func is_item_state_orphan(item :TreeItem) -> bool: return item.has_meta(META_GDUNIT_ORPHAN) -static func is_test_suite(item :TreeItem) -> bool: +func is_test_suite(item :TreeItem) -> bool: return item.has_meta(META_GDUNIT_TYPE) and item.get_meta(META_GDUNIT_TYPE) == GdUnitType.TEST_SUITE @@ -470,9 +470,9 @@ func add_test_cases(parent :TreeItem, test_case_names :Array) -> void: ################################################################################ # Tree signal receiver ################################################################################ -func _on_tree_item_mouse_selected(position :Vector2, mouse_button_index :int): +func _on_tree_item_mouse_selected(mouse_position :Vector2, mouse_button_index :int): if mouse_button_index == MOUSE_BUTTON_RIGHT: - _context_menu.position = position + _tree.get_global_position() + _context_menu.position = mouse_position + _tree.get_global_position() _context_menu.popup() @@ -531,7 +531,7 @@ func _on_GdUnit_gdunit_runner_start(): clear_failures() -func _on_GdUnit_gdunit_runner_stop(client_id :int): +func _on_GdUnit_gdunit_runner_stop(_client_id :int): _context_menu_run.disabled = false _context_menu_debug.disabled = false abort_running() diff --git a/addons/gdUnit4/src/update/GdMarkDownReader.gd b/addons/gdUnit4/src/update/GdMarkDownReader.gd index 48e4163a..2082c95b 100644 --- a/addons/gdUnit4/src/update/GdMarkDownReader.gd +++ b/addons/gdUnit4/src/update/GdMarkDownReader.gd @@ -78,14 +78,14 @@ var _image_urls := Array() var _on_table_tag := false var _client -static func regex(pattern :String) -> RegEx: - var regex := RegEx.new() - var err = regex.compile(pattern) + +func regex(pattern :String) -> RegEx: + var regex_ := RegEx.new() + var err = regex_.compile(pattern) if err != OK: push_error("error '%s' checked pattern '%s'" % [err, pattern]) return null - return regex - + return regex_ func _init(): @@ -114,25 +114,24 @@ func list_replace(indent :int) -> String: func code_block(replace :String, border :bool = false) -> String: - var code_block := "[code][color=aqua][font_size=16]%s[/font_size][/color][/code]" % replace + var cb := "[code][color=aqua][font_size=16]%s[/font_size][/color][/code]" % replace if border: return "[img=1400x14]res://addons/gdUnit4/src/update/assets/border_top.png[/img]"\ - + "[indent]" + code_block + "[/indent]"\ + + "[indent]" + cb + "[/indent]"\ + "[img=1400x14]res://addons/gdUnit4/src/update/assets/border_bottom.png[/img]\n" - return code_block + return cb func to_bbcode(input :String) -> String: - var bbcode := Array() input = process_tables(input) for pattern in md_replace_patterns: - var regex :RegEx = pattern[0] + var regex_ :RegEx = pattern[0] var bb_replace = pattern[1] if bb_replace is Callable: - input = await bb_replace.call(regex, input) + input = await bb_replace.call(regex_, input) else: - input = regex.sub(input, bb_replace, true) + input = regex_.sub(input, bb_replace, true) return input @@ -244,54 +243,52 @@ func extract_cells(line :String, bold := false) -> String: return cells -func process_image_references(regex :RegEx, input :String) -> String: - var to_replace := PackedStringArray() - var tool_tips := PackedStringArray() +func process_image_references(p_regex :RegEx, p_input :String) -> String: # exists references? - var matches := regex.search_all(input) + var matches := p_regex.search_all(p_input) if matches.is_empty(): - return input + return p_input # collect image references and remove_at it var references := Dictionary() var link_regex := regex("\\[(\\S+)\\]:(\\S+)([ ]\"(.*)\")?") # create copy of original source to replace checked it - input = input.replace("\r", "") - var extracted_references := input + var input := p_input.replace("\r", "") + var extracted_references := p_input.replace("\r", "") for reg_match in link_regex.search_all(input): var line = reg_match.get_string(0) + "\n" - var reference = reg_match.get_string(1) - var topl_tip = reg_match.get_string(4) + var ref = reg_match.get_string(1) + #var topl_tip = reg_match.get_string(4) # collect reference and url - references[reference] = reg_match.get_string(2) + references[ref] = reg_match.get_string(2) extracted_references = extracted_references.replace(line, "") # replace image references by collected url's for reference_key in references.keys(): var regex_key := regex("\\](\\[%s\\])" % reference_key) for reg_match in regex_key.search_all(extracted_references): - var reference :String = reg_match.get_string(0) + var ref :String = reg_match.get_string(0) var image_url :String = "](%s)" % references.get(reference_key) - extracted_references = extracted_references.replace(reference, image_url) + extracted_references = extracted_references.replace(ref, image_url) return extracted_references -func process_image(regex :RegEx, input :String) -> String: +func process_image(p_regex :RegEx, p_input :String) -> String: var to_replace := PackedStringArray() var tool_tips := PackedStringArray() # find all matches - var matches := regex.search_all(input) + var matches := p_regex.search_all(p_input) if matches.is_empty(): - return input + return p_input for reg_match in matches: # grap the parts to replace and store temporay because a direct replace will distort the offsets - to_replace.append(input.substr(reg_match.get_start(0), reg_match.get_end(0))) + to_replace.append(p_input.substr(reg_match.get_start(0), reg_match.get_end(0))) # grap optional tool tips tool_tips.append(reg_match.get_string(5)) # finally replace all findings for replace in to_replace: - var re := regex.sub(replace, "[img]$2[/img]") - input = input.replace(replace, re) - return await _process_external_image_resources(input) + var re := p_regex.sub(replace, "[img]$2[/img]") + p_input = p_input.replace(replace, re) + return await _process_external_image_resources(p_input) func _process_external_image_resources(input :String) -> String: diff --git a/addons/gdUnit4/src/update/GdUnitPatch.gd b/addons/gdUnit4/src/update/GdUnitPatch.gd index 8392dce4..37456878 100644 --- a/addons/gdUnit4/src/update/GdUnitPatch.gd +++ b/addons/gdUnit4/src/update/GdUnitPatch.gd @@ -5,12 +5,15 @@ const PATCH_VERSION = "patch_version" var _version :GdUnit4Version -func _init(version :GdUnit4Version): - _version = version + +func _init(version_ :GdUnit4Version): + _version = version_ + func version() -> GdUnit4Version: return _version + # this function needs to be implement func execute() -> bool: push_error("The function 'execute()' is not implemented at %s" % self) diff --git a/addons/gdUnit4/src/update/GdUnitUpdate.gd b/addons/gdUnit4/src/update/GdUnitUpdate.gd index cade4cca..e28e5e18 100644 --- a/addons/gdUnit4/src/update/GdUnitUpdate.gd +++ b/addons/gdUnit4/src/update/GdUnitUpdate.gd @@ -2,7 +2,7 @@ extends ConfirmationDialog -@onready var _progress_panel :Control =$UpdateProgress +#@onready var _progress_panel :Control =$UpdateProgress @onready var _progress_content :Label = $UpdateProgress/Progress/label @onready var _progress_bar :ProgressBar = $UpdateProgress/Progress/bar @@ -80,7 +80,7 @@ func restart_godot() -> void: plugin.get_editor_interface().restart_editor(true) -static func enable_gdUnit() -> void: +func enable_gdUnit() -> void: var enabled_plugins := PackedStringArray() if ProjectSettings.has_setting("editor_plugins/enabled"): enabled_plugins = ProjectSettings.get_setting("editor_plugins/enabled") @@ -97,13 +97,13 @@ func disable_gdUnit() -> void: const GDUNIT_TEMP := "user://tmp" -static func temp_dir() -> String: +func temp_dir() -> String: if not DirAccess.dir_exists_absolute(GDUNIT_TEMP): DirAccess.make_dir_recursive_absolute(GDUNIT_TEMP) return GDUNIT_TEMP -static func create_temp_dir(folder_name :String) -> String: +func create_temp_dir(folder_name :String) -> String: var new_folder = temp_dir() + "/" + folder_name delete_directory(new_folder) if not DirAccess.dir_exists_absolute(new_folder): @@ -111,7 +111,7 @@ static func create_temp_dir(folder_name :String) -> String: return new_folder -static func delete_directory(path :String, only_content := false) -> void: +func delete_directory(path :String, only_content := false) -> void: var dir := DirAccess.open(path) if dir != null: dir.list_dir_begin() @@ -134,7 +134,7 @@ static func delete_directory(path :String, only_content := false) -> void: push_error("Delete %s failed: %s" % [path, error_string(err)]) -static func copy_directory(from_dir :String, to_dir :String) -> bool: +func copy_directory(from_dir :String, to_dir :String) -> bool: if not DirAccess.dir_exists_absolute(from_dir): push_error("Source directory not found '%s'" % from_dir) return false @@ -170,7 +170,7 @@ static func copy_directory(from_dir :String, to_dir :String) -> bool: return false -static func extract_zip(zip_package :String, dest_path :String) -> Variant: +func extract_zip(zip_package :String, dest_path :String) -> Variant: var zip: ZIPReader = ZIPReader.new() var err := zip.open(zip_package) if err != OK: diff --git a/addons/gdUnit4/src/update/GdUnitUpdateClient.gd b/addons/gdUnit4/src/update/GdUnitUpdateClient.gd index 6b844eb1..e7973883 100644 --- a/addons/gdUnit4/src/update/GdUnitUpdateClient.gd +++ b/addons/gdUnit4/src/update/GdUnitUpdateClient.gd @@ -7,9 +7,9 @@ class HttpResponse: var _code :int var _body :PackedByteArray - func _init(code :int, body :PackedByteArray): - _code = code - _body = body + func _init(code_ :int, body_ :PackedByteArray): + _code = code_ + _body = body_ func code() -> int: return _code @@ -76,7 +76,7 @@ func request_zip_package(url :String, file :String) -> HttpResponse: return await self.request_completed -func _on_request_completed(result :int, response_code :int, headers :PackedStringArray, body :PackedByteArray): +func _on_request_completed(_result :int, response_code :int, _headers :PackedStringArray, body :PackedByteArray): if _http_request.get_http_client_status() != HTTPClient.STATUS_DISCONNECTED: _http_request.set_download_file("") request_completed.emit(HttpResponse.new(response_code, body)) diff --git a/addons/gdUnit4/test/GdUnitTestCaseTimeoutTest.gd b/addons/gdUnit4/test/GdUnitTestCaseTimeoutTest.gd index 9fc10c2b..84afeadf 100644 --- a/addons/gdUnit4/test/GdUnitTestCaseTimeoutTest.gd +++ b/addons/gdUnit4/test/GdUnitTestCaseTimeoutTest.gd @@ -36,6 +36,7 @@ func test_timeout_after_test_completes(): assert_int(counter).is_equal(5) # set test timeout to 2s +@warning_ignore("unused_parameter") func test_timeout_2s(timeout=2000): assert_str(_before_arg).is_equal("---before---") prints("B", "0s") @@ -50,6 +51,7 @@ func test_timeout_2s(timeout=2000): prints("B", "end") # set test timeout to 4s +@warning_ignore("unused_parameter") func test_timeout_4s(timeout=4000): assert_str(_before_arg).is_equal("---before---") prints("C", "0s") @@ -65,6 +67,7 @@ func test_timeout_4s(timeout=4000): prints("C", "7s") prints("C", "end") +@warning_ignore("unused_parameter") func test_timeout_single_yield_wait(timeout=3000): assert_str(_before_arg).is_equal("---before---") prints("D", "0s") @@ -74,6 +77,7 @@ func test_timeout_single_yield_wait(timeout=3000): assert_bool(true).override_failure_message("The test case must be interupted by a timeout after 3s").is_false() prints("D", "end test test_timeout") +@warning_ignore("unused_parameter") func test_timeout_long_running_test_abort(timeout=4000): assert_str(_before_arg).is_equal("---before---") prints("E", "0s") @@ -83,7 +87,6 @@ func test_timeout_long_running_test_abort(timeout=4000): # simulate long running function while true: - var x = 1 var elapsed_time := Time.get_ticks_msec() - start_time var sec_time = Time.get_ticks_msec() - sec_start_time @@ -102,6 +105,7 @@ func test_timeout_long_running_test_abort(timeout=4000): assert_bool(true).override_failure_message("The test case must be abort interupted by a timeout 4s").is_false() prints("F", "end test test_timeout") +@warning_ignore("unused_parameter", "unused_variable") func test_timeout_fuzzer(fuzzer := Fuzzers.rangei(-23, 22), timeout=2000): discard_error_interupted_by_timeout() var value = fuzzer.next_value() diff --git a/addons/gdUnit4/test/GdUnitTestSuiteTest.gd b/addons/gdUnit4/test/GdUnitTestSuiteTest.gd index ab901de9..41280d61 100644 --- a/addons/gdUnit4/test/GdUnitTestSuiteTest.gd +++ b/addons/gdUnit4/test/GdUnitTestSuiteTest.gd @@ -38,5 +38,5 @@ func test_assert_that_types() -> void: assert_object(assert_that(Plane.PLANE_XY)).is_instanceof(GdUnitAssertImpl) -func test_unknown_argument_in_test_case(invalid_arg) -> void: +func test_unknown_argument_in_test_case(_invalid_arg) -> void: fail("This test case should be not executed, it must be skipped.") diff --git a/addons/gdUnit4/test/asserts/CallBackValueProviderTest.gd b/addons/gdUnit4/test/asserts/CallBackValueProviderTest.gd index 22985f5e..16989777 100644 --- a/addons/gdUnit4/test/asserts/CallBackValueProviderTest.gd +++ b/addons/gdUnit4/test/asserts/CallBackValueProviderTest.gd @@ -11,6 +11,7 @@ const __source = 'res://addons/gdUnit4/src/asserts/CallBackValueProvider.gd' func next_value() -> String: return "a value" + func test_get_value() -> void: var vp := CallBackValueProvider.new(self, "next_value") assert_str(await vp.get_value()).is_equal("a value") diff --git a/addons/gdUnit4/test/asserts/GdUnitFuncAssertImplTest.gd b/addons/gdUnit4/test/asserts/GdUnitFuncAssertImplTest.gd index 17ccb5ab..035efdb6 100644 --- a/addons/gdUnit4/test/asserts/GdUnitFuncAssertImplTest.gd +++ b/addons/gdUnit4/test/asserts/GdUnitFuncAssertImplTest.gd @@ -1,8 +1,8 @@ # GdUnit generated TestSuite -#warning-ignore-all:unused_argument -#warning-ignore-all:return_value_discarded class_name GdUnitFuncAssertImplTest extends GdUnitTestSuite +@warning_ignore("unused_parameter") + # TestSuite generated from const __source = 'res://addons/gdUnit4/src/asserts/GdUnitFuncAssertImpl.gd' @@ -53,13 +53,13 @@ class TestValueProvider: class ValueProvidersWithArguments: - func is_type(type :int) -> bool: + func is_type(_type :int) -> bool: return true - func get_index(instance :Object, name :String) -> int: + func get_index(_instance :Object, _name :String) -> int: return 1 - func get_index2(instance :Object, name :String, recursive := false) -> int: + func get_index2(_instance :Object, _name :String, _recursive := false) -> int: return 1 class TestIterativeValueProvider: @@ -91,7 +91,7 @@ class TestIterativeValueProvider: return _final_value return _inital_value - func has_type(type :int, recursive :bool = true) -> int: + func has_type(type :int, _recursive :bool = true) -> int: _current_itteration += 1 #await Engine.get_main_loop().idle_frame if type == _current_itteration: @@ -112,6 +112,8 @@ class TestIterativeValueProvider: func iteration() -> int: return _current_itteration + +@warning_ignore("unused_parameter") func test_is_null(timeout = 2000) -> void: var value_provider := TestIterativeValueProvider.new(RefCounted.new(), 5, null) # without default timeout od 2000ms @@ -130,6 +132,8 @@ func test_is_null(timeout = 2000) -> void: assert_fail(await assert_func(value_provider, "obj_value", [], GdUnitAssert.EXPECT_FAIL).wait_until(100).is_null())\ .has_failure_message("Expected: is null but timed out after 100ms") + +@warning_ignore("unused_parameter") func test_is_not_null(timeout = 2000) -> void: var value_provider := TestIterativeValueProvider.new(null, 5, RefCounted.new()) # without default timeout od 2000ms @@ -148,6 +152,8 @@ func test_is_not_null(timeout = 2000) -> void: assert_fail( await assert_func(value_provider, "obj_value", [], GdUnitAssert.EXPECT_FAIL).wait_until(100).is_not_null())\ .has_failure_message("Expected: is not null but timed out after 100ms") + +@warning_ignore("unused_parameter") func test_is_true(timeout = 2000) -> void: var value_provider := TestIterativeValueProvider.new(false, 5, true) # without default timeout od 2000ms @@ -166,6 +172,8 @@ func test_is_true(timeout = 2000) -> void: assert_fail( await assert_func(value_provider, "bool_value", [], GdUnitAssert.EXPECT_FAIL).wait_until(100).is_true())\ .has_failure_message("Expected: is true but timed out after 100ms") + +@warning_ignore("unused_parameter") func test_is_false(timeout = 2000) -> void: var value_provider := TestIterativeValueProvider.new(true, 5, false) # without default timeout od 2000ms @@ -184,6 +192,8 @@ func test_is_false(timeout = 2000) -> void: assert_fail( await assert_func(value_provider, "bool_value", [], GdUnitAssert.EXPECT_FAIL).wait_until(100).is_false())\ .has_failure_message("Expected: is false but timed out after 100ms") + +@warning_ignore("unused_parameter") func test_is_equal(timeout = 2000) -> void: var value_provider := TestIterativeValueProvider.new(42, 5, 23) # without default timeout od 2000ms @@ -202,6 +212,8 @@ func test_is_equal(timeout = 2000) -> void: assert_fail( await assert_func(value_provider, "int_value", [], GdUnitAssert.EXPECT_FAIL).wait_until(100).is_equal(25))\ .has_failure_message("Expected: is equal '25' but timed out after 100ms") + +@warning_ignore("unused_parameter") func test_is_not_equal(timeout = 2000) -> void: var value_provider := TestIterativeValueProvider.new(42, 5, 23) # without default timeout od 2000ms @@ -220,6 +232,8 @@ func test_is_not_equal(timeout = 2000) -> void: assert_fail( await assert_func(value_provider, "int_value", [], GdUnitAssert.EXPECT_FAIL).wait_until(100).is_not_equal(23))\ .has_failure_message("Expected: is not equal '23' but timed out after 100ms") + +@warning_ignore("unused_parameter") func test_is_equal_wiht_func_arg(timeout = 1300) -> void: var value_provider := TestIterativeValueProvider.new(42, 10, 23) # without default timeout od 2000ms @@ -233,7 +247,9 @@ func test_is_equal_wiht_func_arg(timeout = 1300) -> void: await assert_func(value_provider, "has_type", [10]).wait_until(5000).is_equal(23) assert_int(value_provider.iteration()).is_equal(10) + # abort test after 500ms to fail +@warning_ignore("unused_parameter") func test_timeout_and_assert_fails(timeout = 500) -> void: # disable temporary the timeout errors for this test discard_error_interupted_by_timeout() @@ -242,6 +258,7 @@ func test_timeout_and_assert_fails(timeout = 500) -> void: await assert_func(value_provider, "int_value").wait_until(1000).is_equal(42) fail("The test must be interrupted after 500ms") + func timed_function() -> Color: var color = Color.RED await await_millis(20) @@ -252,6 +269,7 @@ func timed_function() -> Color: color = Color.BLACK return color + func test_timer_yielded_function() -> void: await assert_func(self, "timed_function").is_equal(Color.BLACK) # will be never red @@ -260,10 +278,12 @@ func test_timer_yielded_function() -> void: assert_fail( await assert_func(self, "timed_function", [], GdUnitAssert.EXPECT_FAIL).wait_until(100).is_equal(Color.RED))\ .has_failure_message("Expected: is equal 'Color(1, 0, 0, 1)' but timed out after 100ms") + func test_timer_yielded_function_timeout() -> void: assert_fail( await assert_func(self, "timed_function", [], GdUnitAssert.EXPECT_FAIL).wait_until(40).is_equal(Color.BLACK))\ .has_failure_message("Expected: is equal 'Color(0, 0, 0, 1)' but timed out after 40ms") + func yielded_function() -> Color: var color = Color.RED await get_tree().process_frame @@ -271,18 +291,22 @@ func yielded_function() -> Color: await get_tree().process_frame color = Color.BLUE await get_tree().process_frame - return Color.BLACK + color = Color.BLACK + return color + func test_idle_frame_yielded_function() -> void: await assert_func(self, "yielded_function").is_equal(Color.BLACK) assert_fail( await assert_func(self, "yielded_function", [], GdUnitAssert.EXPECT_FAIL).wait_until(500).is_equal(Color.RED))\ .has_failure_message("Expected: is equal 'Color(1, 0, 0, 1)' but timed out after 500ms") + func test_has_failure_message() -> void: var value_provider := TestIterativeValueProvider.new(10, 1, 10) assert_fail( await assert_func(value_provider, "int_value", [], GdUnitAssert.EXPECT_FAIL).wait_until(500).is_equal(42))\ .has_failure_message("Expected: is equal '42' but timed out after 500ms") + func test_override_failure_message() -> void: var value_provider := TestIterativeValueProvider.new(10, 1, 20) assert_fail( await assert_func(value_provider, "int_value", [], GdUnitAssert.EXPECT_FAIL)\ @@ -291,6 +315,7 @@ func test_override_failure_message() -> void: .is_equal(42))\ .has_failure_message("Custom failure message") + func test_invalid_function(): assert_fail( await assert_func(self, "invalid_func_name", [], GdUnitAssert.EXPECT_FAIL)\ .wait_until(100)\ diff --git a/addons/gdUnit4/test/core/GdDiffToolTest.gd b/addons/gdUnit4/test/core/GdDiffToolTest.gd index 45f2b5dc..386bdbce 100644 --- a/addons/gdUnit4/test/core/GdDiffToolTest.gd +++ b/addons/gdUnit4/test/core/GdDiffToolTest.gd @@ -37,6 +37,8 @@ func test_string_diff(): assert_array(diffs[0]).contains_exactly(expected_l_diff) assert_array(diffs[1]).contains_exactly(expected_r_diff) + +@warning_ignore("unused_parameter") func test_string_diff_large_value(fuzzer := Fuzzers.rand_str(1000, 4000), fuzzer_iterations = 10): # test diff with large values not crashes the API GD-100 var value :String = fuzzer.next_value() diff --git a/addons/gdUnit4/test/core/GdObjectsTest.gd b/addons/gdUnit4/test/core/GdObjectsTest.gd index 297e9626..fc1da8cc 100644 --- a/addons/gdUnit4/test/core/GdObjectsTest.gd +++ b/addons/gdUnit4/test/core/GdObjectsTest.gd @@ -94,7 +94,6 @@ class TestClass extends Resource: B } - var _type := A var _a:int var _b:String var _c:Array @@ -314,14 +313,15 @@ func test_extract_class_name_from_instance(): assert_result(extract_class_name(CustomClass.InnerClassC.new())).is_equal("CustomClass.InnerClassC") # verify enigne class names are not converted by configured naming convention +@warning_ignore("unused_parameter") func test_extract_class_name_from_class_path(fuzzer=GodotClassNameFuzzer.new(true, true), fuzzer_iterations = 100) -> void: var clazz_name :String = fuzzer.next_value() assert_str(GdObjects.extract_class_name_from_class_path(PackedStringArray([clazz_name]))).is_equal(clazz_name) func test_extract_class_name_godot_classes(fuzzer=GodotClassNameFuzzer.new(true, true)): - var extract_class_name := fuzzer.next_value() as String - var instance :Variant = ClassDB.instantiate(extract_class_name) - assert_result(extract_class_name(instance)).is_equal(extract_class_name) + var extract_class_name_ := fuzzer.next_value() as String + var instance :Variant = ClassDB.instantiate(extract_class_name_) + assert_result(extract_class_name(instance)).is_equal(extract_class_name_) func test_extract_class_path_by_clazz(): # engine classes has no class path @@ -361,24 +361,6 @@ func test_extract_class_path_by_clazz(): assert_array(GdObjects.extract_class_path(CustomClass.InnerClassD.InnerInnerClassA))\ .contains_exactly(["res://addons/gdUnit4/test/resources/core/CustomClass.gd", "InnerClassD", "InnerInnerClassA"]) -func test_is_same(): - assert_bool(GdObjects.is_same(1, 1)).is_true() - assert_bool(GdObjects.is_same(1, 2)).is_false() - assert_bool(GdObjects.is_same(1.0, 1.0)).is_true() - assert_bool(GdObjects.is_same(1, 1.0)).is_false() - - var obj1 = auto_free(Camera3D.new()) - var obj2 = auto_free(Camera3D.new()) - var obj3 = auto_free(obj2.duplicate()) - assert_bool(GdObjects.is_same(obj1, obj1)).is_true() - assert_bool(GdObjects.is_same(obj1, obj2)).is_false() - assert_bool(GdObjects.is_same(obj1, obj3)).is_false() - assert_bool(GdObjects.is_same(obj2, obj1)).is_false() - assert_bool(GdObjects.is_same(obj2, obj2)).is_true() - assert_bool(GdObjects.is_same(obj2, obj3)).is_false() - assert_bool(GdObjects.is_same(obj3, obj1)).is_false() - assert_bool(GdObjects.is_same(obj3, obj2)).is_false() - assert_bool(GdObjects.is_same(obj3, obj3)).is_true() #func __test_can_instantiate(): # assert_bool(GdObjects.can_instantiate(GDScript)).is_true() diff --git a/addons/gdUnit4/test/core/GdUnit3VersionTest.gd b/addons/gdUnit4/test/core/GdUnit3VersionTest.gd index 4f9f9610..6c0a9f12 100644 --- a/addons/gdUnit4/test/core/GdUnit3VersionTest.gd +++ b/addons/gdUnit4/test/core/GdUnit3VersionTest.gd @@ -27,6 +27,8 @@ func test_to_string() -> void: assert_str(str(version)).is_equal("v0.9.1") assert_str("%s" % version).is_equal("v0.9.1") + +@warning_ignore("unused_parameter") func test_is_greater_major(fuzzer_major := Fuzzers.rangei(1, 20), fuzzer_minor := Fuzzers.rangei(0, 20), fuzzer_patch := Fuzzers.rangei(0, 20), fuzzer_iterations = 500) -> void: var version := GdUnit4Version.new(0, 9, 1) var current := GdUnit4Version.new(fuzzer_major.next_value(), fuzzer_minor.next_value(), fuzzer_patch.next_value()); @@ -34,6 +36,8 @@ func test_is_greater_major(fuzzer_major := Fuzzers.rangei(1, 20), fuzzer_minor : .override_failure_message("Expect %s is greater then %s" % [current, version])\ .is_true() + +@warning_ignore("unused_parameter") func test_is_not_greater_major(fuzzer_major := Fuzzers.rangei(1, 10), fuzzer_minor := Fuzzers.rangei(0, 20), fuzzer_patch := Fuzzers.rangei(0, 20), fuzzer_iterations = 500) -> void: var version := GdUnit4Version.new(11, 0, 0) var current := GdUnit4Version.new(fuzzer_major.next_value(), fuzzer_minor.next_value(), fuzzer_patch.next_value()); @@ -41,6 +45,8 @@ func test_is_not_greater_major(fuzzer_major := Fuzzers.rangei(1, 10), fuzzer_min .override_failure_message("Expect %s is not greater then %s" % [current, version])\ .is_false() + +@warning_ignore("unused_parameter") func test_is_greater_minor(fuzzer_minor := Fuzzers.rangei(3, 20), fuzzer_patch := Fuzzers.rangei(0, 20), fuzzer_iterations = 500) -> void: var version := GdUnit4Version.new(0, 2, 1) var current := GdUnit4Version.new(0, fuzzer_minor.next_value(), fuzzer_patch.next_value()); @@ -48,6 +54,8 @@ func test_is_greater_minor(fuzzer_minor := Fuzzers.rangei(3, 20), fuzzer_patch : .override_failure_message("Expect %s is greater then %s" % [current, version])\ .is_true() + +@warning_ignore("unused_parameter") func test_is_greater_patch(fuzzer_patch := Fuzzers.rangei(1, 20), fuzzer_iterations = 500) -> void: var version := GdUnit4Version.new(0, 2, 0) var current := GdUnit4Version.new(0, 2, fuzzer_patch.next_value()); diff --git a/addons/gdUnit4/test/core/GdUnitClassDoublerTest.gd b/addons/gdUnit4/test/core/GdUnitClassDoublerTest.gd index fd7f3313..21c266fb 100644 --- a/addons/gdUnit4/test/core/GdUnitClassDoublerTest.gd +++ b/addons/gdUnit4/test/core/GdUnitClassDoublerTest.gd @@ -7,7 +7,7 @@ const __source = 'res://addons/gdUnit4/src/core/GdUnitClassDoubler.gd' # simple function doubler whitout any modifications class TestFunctionDoubler extends GdFunctionDoubler: - func double(func_descriptor :GdFunctionDescriptor) -> PackedStringArray: + func double(_func_descriptor :GdFunctionDescriptor) -> PackedStringArray: return PackedStringArray([]) diff --git a/addons/gdUnit4/test/core/GdUnitExecutorTest.gd b/addons/gdUnit4/test/core/GdUnitExecutorTest.gd index d77d7327..916856f6 100644 --- a/addons/gdUnit4/test/core/GdUnitExecutorTest.gd +++ b/addons/gdUnit4/test/core/GdUnitExecutorTest.gd @@ -581,6 +581,7 @@ func test_execute_add_child_on_before_GD_106() -> void: assert_event_reports(events, [], [], [], [], [], []) +@warning_ignore("unused_parameter") func test_fuzzer_before_before(fuzzer := Fuzzers.rangei(0, 1000), fuzzer_iterations = 1000): # verify the used stack is cleaned by 'before_test' assert_array(_stack).is_empty() diff --git a/addons/gdUnit4/test/core/GdUnitRunnerConfigTest.gd b/addons/gdUnit4/test/core/GdUnitRunnerConfigTest.gd index ebf6fbd9..408fd3df 100644 --- a/addons/gdUnit4/test/core/GdUnitRunnerConfigTest.gd +++ b/addons/gdUnit4/test/core/GdUnitRunnerConfigTest.gd @@ -152,7 +152,7 @@ func test_skip_test_case(): func test_load_fail(): var config := GdUnitRunnerConfig.new() - assert_result(config.load("invalid_path"))\ + assert_result(config.load_config("invalid_path"))\ .is_error()\ .contains_message("Can't find test runner configuration 'invalid_path'! Please select a test to run.") @@ -166,10 +166,10 @@ func test_save_load(): var config_file := create_temp_dir("test_save_load") + "/testconf.cfg" - assert_result(config.save(config_file)).is_success() + assert_result(config.save_config(config_file)).is_success() assert_file(config_file).exists() var config2 := GdUnitRunnerConfig.new() - assert_result(config2.load(config_file)).is_success() + assert_result(config2.load_config(config_file)).is_success() # verify the config has original enties assert_object(config2).is_equal(config).is_not_same(config) diff --git a/addons/gdUnit4/test/core/GdUnitSceneRunnerInputEventTest.gd b/addons/gdUnit4/test/core/GdUnitSceneRunnerInputEventTest.gd index 71e96c05..acab53cb 100644 --- a/addons/gdUnit4/test/core/GdUnitSceneRunnerInputEventTest.gd +++ b/addons/gdUnit4/test/core/GdUnitSceneRunnerInputEventTest.gd @@ -463,6 +463,6 @@ func test_simulate_mouse_button_press_and_release(): event.global_position = gmp event.pressed = false event.button_index = mouse_button - event.button_mask = 0 + #event.button_mask = 0 verify(_scene_spy, 1)._input(event) assert_that(Input.is_mouse_button_pressed(mouse_button)).is_false() diff --git a/addons/gdUnit4/test/core/GdUnitSceneRunnerTest.gd b/addons/gdUnit4/test/core/GdUnitSceneRunnerTest.gd index 984a4cee..468a853b 100644 --- a/addons/gdUnit4/test/core/GdUnitSceneRunnerTest.gd +++ b/addons/gdUnit4/test/core/GdUnitSceneRunnerTest.gd @@ -34,16 +34,7 @@ func test_invoke_method() -> void: assert_that(runner.invoke("sub", 10, 12)).is_equal("The method 'sub' not exist checked loaded scene.") -func test_awaitForMilliseconds() -> void: - var runner := scene_runner(load_test_scene()) - - var stopwatch = LocalTime.now() - await await_millis(1000) - - # verify we wait around 1000 ms (using 100ms offset because timing is not 100% accurate) - assert_int(stopwatch.elapsed_since_ms()).is_between(800, 1100) - - +@warning_ignore("unused_parameter") func test_simulate_frames(timeout = 5000) -> void: var runner := scene_runner(load_test_scene()) var box1 :ColorRect = runner.get_property("_box1") @@ -64,6 +55,7 @@ func test_simulate_frames(timeout = 5000) -> void: assert_object(box1.color).is_equal(Color.RED) +@warning_ignore("unused_parameter") func test_simulate_frames_withdelay(timeout = 4000) -> void: var runner := scene_runner(load_test_scene()) var box1 :ColorRect = runner.get_property("_box1") @@ -79,6 +71,7 @@ func test_simulate_frames_withdelay(timeout = 4000) -> void: assert_object(box1.color).is_equal(Color.RED) +@warning_ignore("unused_parameter") func test_run_scene_colorcycle(timeout=2000) -> void: var runner := scene_runner(load_test_scene()) var box1 :ColorRect = runner.get_property("_box1") @@ -123,17 +116,17 @@ func test_simulate_scene_inteaction_by_press_enter(timeout=2000) -> void: # mock on a runner and spy on created spell func test_simulate_scene_inteaction_in_combination_with_spy(): - var spy = spy(load_test_scene()) + var spy_ = spy(load_test_scene()) # create a runner runner - var runner := scene_runner(spy) + var runner := scene_runner(spy_) # simulate a key event to fire a spell runner.simulate_key_pressed(KEY_ENTER) - verify(spy).create_spell() + verify(spy_).create_spell() var spell = runner.find_child("Spell") assert_that(spell).is_not_null() - assert_that(spell.is_connected("spell_explode", Callable(spy, "_destroy_spell"))).is_true() + assert_that(spell.is_connected("spell_explode", Callable(spy_, "_destroy_spell"))).is_true() func test_simulate_scene_interact_with_buttons(): @@ -206,7 +199,7 @@ func test_await_signal_without_time_factor() -> void: # should be interrupted is will never change to Color.KHAKI GdAssertReports.expect_fail() await runner.await_signal( "panel_color_change", [box1, Color.KHAKI], 300) - if assert_failed_at(208, "await_signal_on(panel_color_change, [%s, %s]) timed out after 300ms" % [str(box1), str(Color.KHAKI)]): + if assert_failed_at(201, "await_signal_on(panel_color_change, [%s, %s]) timed out after 300ms" % [str(box1), str(Color.KHAKI)]): return fail("test should failed after 300ms checked 'await_signal'") @@ -225,7 +218,7 @@ func test_await_signal_with_time_factor() -> void: # should be interrupted is will never change to Color.KHAKI GdAssertReports.expect_fail() await runner.await_signal("panel_color_change", [box1, Color.KHAKI], 30) - if assert_failed_at(227, "await_signal_on(panel_color_change, [%s, %s]) timed out after 30ms" % [str(box1), str(Color.KHAKI)]): + if assert_failed_at(220, "await_signal_on(panel_color_change, [%s, %s]) timed out after 30ms" % [str(box1), str(Color.KHAKI)]): return fail("test should failed after 30ms checked 'await_signal'") @@ -244,6 +237,7 @@ func test_simulate_until_signal() -> void: # .starts_with_failure_message("Expecting emit signal: 'panel_color_change(") +@warning_ignore("unused_parameter") func test_simulate_until_object_signal(timeout=2000) -> void: var runner := scene_runner(load_test_scene()) diff --git a/addons/gdUnit4/test/core/GdUnitSettingsTest.gd b/addons/gdUnit4/test/core/GdUnitSettingsTest.gd index f18f5647..b354cd7e 100644 --- a/addons/gdUnit4/test/core/GdUnitSettingsTest.gd +++ b/addons/gdUnit4/test/core/GdUnitSettingsTest.gd @@ -93,7 +93,7 @@ func test_migrate_property_change_key() -> void: # cleanup ProjectSettings.clear(new_property_X) -func convert_value(value :String) -> String: +func convert_value(_value :String) -> String: return "bar" func test_migrate_property_change_value() -> void: diff --git a/addons/gdUnit4/test/core/GdUnitSignalAwaiterTest.gd b/addons/gdUnit4/test/core/GdUnitSignalAwaiterTest.gd index eae6b4dc..c61ff4ee 100644 --- a/addons/gdUnit4/test/core/GdUnitSignalAwaiterTest.gd +++ b/addons/gdUnit4/test/core/GdUnitSignalAwaiterTest.gd @@ -38,6 +38,6 @@ func test_on_signal_fail() -> void: GdAssertReports.expect_fail() var monster = auto_free(Monster.new()) add_child(monster) - var signal_args = await await_signal_on(monster, "move", [4.0]) + await await_signal_on(monster, "move", [4.0]) assert_str(GdAssertReports.current_failure()).is_equal("await_signal_on(move, [4]) timed out after 2000ms") remove_child(monster) diff --git a/addons/gdUnit4/test/core/GdUnitTestSuiteBuilderTest.gd b/addons/gdUnit4/test/core/GdUnitTestSuiteBuilderTest.gd index 77e1ef0a..08571128 100644 --- a/addons/gdUnit4/test/core/GdUnitTestSuiteBuilderTest.gd +++ b/addons/gdUnit4/test/core/GdUnitTestSuiteBuilderTest.gd @@ -7,7 +7,6 @@ extends GdUnitTestSuite # TestSuite generated from const __source = 'res://addons/gdUnit4/src/core/GdUnitTestSuiteBuilder.gd' -var _test_suite_builder :GdUnitTestSuiteBuilder var _example_source_gd :String @@ -16,7 +15,6 @@ func before_test(): var result := GdUnitTools.copy_file("res://addons/gdUnit4/test/core/resources/sources/test_person.gd", temp) assert_result(result).is_success() _example_source_gd = result.value() as String - _test_suite_builder = GdUnitTestSuiteBuilder.new() func after_test(): @@ -29,9 +27,8 @@ func assert_tests(test_suite :Script) -> GdUnitArrayAssert: var methods := test_suite.get_script_method_list() var test_cases := Array() for method in methods: - var name :String = method.name - if name.begins_with("test_"): - test_cases.append(name) + if method.name.begins_with("test_"): + test_cases.append(method.name) return assert_array(test_cases) @@ -39,7 +36,7 @@ func test_create_gd_success() -> void: var source := load(_example_source_gd) # create initial test suite based checked function selected by line 9 - var result := _test_suite_builder.create(source, 9) + var result := GdUnitTestSuiteBuilder.create(source, 9) assert_result(result).is_success() var info := result.value() as Dictionary @@ -48,7 +45,7 @@ func test_create_gd_success() -> void: assert_tests(load(info.get("path"))).contains_exactly(["test_first_name"]) # create additional test checked existing suite based checked function selected by line 15 - result = _test_suite_builder.create(source, 15) + result = GdUnitTestSuiteBuilder.create(source, 15) assert_result(result).is_success() info = result.value() as Dictionary @@ -61,5 +58,5 @@ func test_create_gd_fail() -> void: var source := load(_example_source_gd) # attempt to create an initial test suite based checked the function selected in line 8, which has no function definition - var result := _test_suite_builder.create(source, 8) + var result := GdUnitTestSuiteBuilder.create(source, 8) assert_result(result).is_error().contains_message("No function found at line: 8.") diff --git a/addons/gdUnit4/test/core/GdUnitTestSuiteScannerTest.gd b/addons/gdUnit4/test/core/GdUnitTestSuiteScannerTest.gd index a3c91ec0..cd8f871c 100644 --- a/addons/gdUnit4/test/core/GdUnitTestSuiteScannerTest.gd +++ b/addons/gdUnit4/test/core/GdUnitTestSuiteScannerTest.gd @@ -245,7 +245,6 @@ func test_parse_and_add_test_cases() -> void: # fake a test suite var test_suite :GdUnitTestSuite = auto_free(GdUnitTestSuite.new()) test_suite.set_script( load("res://addons/gdUnit4/test/core/resources/test_script_with_arguments.gd")) - var line_number :int = 0 var test_case_names := PackedStringArray([ "test_no_args", @@ -306,7 +305,7 @@ func test_scan_by_inheritance_class_path() -> void: func test_get_test_case_line_number() -> void: - assert_int(GdUnitTestSuiteScanner.get_test_case_line_number("res://addons/gdUnit4/test/core/GdUnitTestSuiteScannerTest.gd", "get_test_case_line_number")).is_equal(308) + assert_int(GdUnitTestSuiteScanner.get_test_case_line_number("res://addons/gdUnit4/test/core/GdUnitTestSuiteScannerTest.gd", "get_test_case_line_number")).is_equal(307) assert_int(GdUnitTestSuiteScanner.get_test_case_line_number("res://addons/gdUnit4/test/core/GdUnitTestSuiteScannerTest.gd", "unknown")).is_equal(-1) diff --git a/addons/gdUnit4/test/core/GdUnitToolsTest.gd b/addons/gdUnit4/test/core/GdUnitToolsTest.gd index 7e522e8a..bdeb4c65 100644 --- a/addons/gdUnit4/test/core/GdUnitToolsTest.gd +++ b/addons/gdUnit4/test/core/GdUnitToolsTest.gd @@ -28,7 +28,7 @@ func test_create_temp_dir(): 'level': 42 } var file := FileAccess.open(file_to_save, FileAccess.WRITE) - file.store_line(JSON.new().stringify(data)) + file.store_line(JSON.stringify(data)) assert_bool(FileAccess.file_exists(file_to_save)).is_true() func test_error_as_string(): @@ -146,8 +146,8 @@ func test_scan_dir() -> void: "file_a", "file_b"]) -func _create_file(path :String, name :String) -> void: - var file := create_temp_file(path, name) +func _create_file(p_path :String, p_name :String) -> void: + var file := create_temp_file(p_path, p_name) file.store_string("some content") func test_delete_directory() -> void: diff --git a/addons/gdUnit4/test/core/LocalTimeTest.gd b/addons/gdUnit4/test/core/LocalTimeTest.gd index db75c723..3266faac 100644 --- a/addons/gdUnit4/test/core/LocalTimeTest.gd +++ b/addons/gdUnit4/test/core/LocalTimeTest.gd @@ -22,6 +22,7 @@ func test_now(): # Time.get_datetime_dict_from_system() does not provide milliseconds #assert_that(local_time.millis()).is_equal(0) +@warning_ignore("integer_division") func test_of_unix_time(): var time := LocalTime._get_system_time_msecs() var local_time := LocalTime.of_unix_time(time) @@ -47,7 +48,7 @@ func test_plus_seconds(): var start_time = time2._time for iteration in 10000: var t = LocalTime.of_unix_time(start_time) - var seconds:int = randf_range(0, 1000) + var seconds:int = randi_range(0, 1000) t.plus(LocalTime.TimeUnit.SECOND, seconds) var expected := LocalTime.of_unix_time(start_time + (seconds * LocalTime.MILLIS_PER_SECOND)) assert_str(t._to_string()).is_equal(expected._to_string()) diff --git a/addons/gdUnit4/test/core/ParameterizedTestCaseTest.gd b/addons/gdUnit4/test/core/ParameterizedTestCaseTest.gd index 84a7f9e4..53f783ad 100644 --- a/addons/gdUnit4/test/core/ParameterizedTestCaseTest.gd +++ b/addons/gdUnit4/test/core/ParameterizedTestCaseTest.gd @@ -61,6 +61,7 @@ func collect_test_call(test_name :String, values :Array) -> void: _collected_tests[test_name].append(values) +@warning_ignore("unused_parameter") func test_parameterized_bool_value(a: int, expected :bool, test_parameters := [ [0, false], [1, true]]): @@ -68,6 +69,7 @@ func test_parameterized_bool_value(a: int, expected :bool, test_parameters := [ assert_that(bool(a)).is_equal(expected) +@warning_ignore("unused_parameter") func test_parameterized_int_values(a: int, b :int, c :int, expected :int, test_parameters := [ [1, 2, 3, 6], [3, 4, 5, 12], @@ -77,6 +79,7 @@ func test_parameterized_int_values(a: int, b :int, c :int, expected :int, test_p assert_that(a+b+c).is_equal(expected) +@warning_ignore("unused_parameter") func test_parameterized_float_values(a: float, b :float, expected :float, test_parameters := [ [2.2, 2.2, 4.4], [2.2, 2.3, 4.5], @@ -86,6 +89,7 @@ func test_parameterized_float_values(a: float, b :float, expected :float, test_p assert_float(a+b).is_equal(expected) +@warning_ignore("unused_parameter") func test_parameterized_string_values(a: String, b :String, expected :String, test_parameters := [ ["2.2", "2.2", "2.22.2"], ["foo", "bar", "foobar"], @@ -95,6 +99,7 @@ func test_parameterized_string_values(a: String, b :String, expected :String, te assert_that(a+b).is_equal(expected) +@warning_ignore("unused_parameter") func test_parameterized_Vector2_values(a: Vector2, b :Vector2, expected :Vector2, test_parameters := [ [Vector2.ONE, Vector2.ONE, Vector2(2, 2)], [Vector2.LEFT, Vector2.RIGHT, Vector2.ZERO], @@ -104,6 +109,7 @@ func test_parameterized_Vector2_values(a: Vector2, b :Vector2, expected :Vector2 assert_that(a+b).is_equal(expected) +@warning_ignore("unused_parameter") func test_parameterized_Vector3_values(a: Vector3, b :Vector3, expected :Vector3, test_parameters := [ [Vector3.ONE, Vector3.ONE, Vector3(2, 2, 2)], [Vector3.LEFT, Vector3.RIGHT, Vector3.ZERO], @@ -123,6 +129,7 @@ class TestObj extends RefCounted: return _value +@warning_ignore("unused_parameter") func test_parameterized_obj_values(a: Object, b :Object, expected :String, test_parameters := [ [TestObj.new("abc"), TestObj.new("def"), "abcdef"]]): @@ -130,6 +137,7 @@ func test_parameterized_obj_values(a: Object, b :Object, expected :String, test_ assert_that(a.to_string()+b.to_string()).is_equal(expected) +@warning_ignore("unused_parameter") func test_parameterized_dict_values(data: Dictionary, expected :String, test_parameters := [ [{"key_a" : "value_a"}, '{"key_a":"value_a"}'], [{"key_b" : "value_b"}, '{"key_b":"value_b"}'] @@ -138,6 +146,7 @@ func test_parameterized_dict_values(data: Dictionary, expected :String, test_par assert_that(str(data).replace(" ", "")).is_equal(expected) +@warning_ignore("unused_parameter") func test_dictionary_div_number_types( value : Dictionary, expected : Dictionary, @@ -154,6 +163,7 @@ func test_dictionary_div_number_types( ProjectSettings.set_setting(GdUnitSettings.REPORT_ASSERT_STRICT_NUMBER_TYPE_COMPARE, true) +@warning_ignore("unused_parameter") func test_with_string_paramset( values : Array, expected : String, diff --git a/addons/gdUnit4/test/core/parse/GdFunctionDescriptorTest.gd b/addons/gdUnit4/test/core/parse/GdFunctionDescriptorTest.gd index 18e49b09..2d3c6e5b 100644 --- a/addons/gdUnit4/test/core/parse/GdFunctionDescriptorTest.gd +++ b/addons/gdUnit4/test/core/parse/GdFunctionDescriptorTest.gd @@ -7,7 +7,7 @@ const __source = 'res://addons/gdUnit4/src/core/parse/GdFunctionDescriptor.gd' # helper to get method descriptor -static func get_method_description(clazz_name :String, method_name :String) -> Dictionary: +func get_method_description(clazz_name :String, method_name :String) -> Dictionary: var method_list :Array = ClassDB.class_get_method_list(clazz_name) for method_descriptor in method_list: if method_descriptor["name"] == method_name: diff --git a/addons/gdUnit4/test/core/parse/GdScriptParserTest.gd b/addons/gdUnit4/test/core/parse/GdScriptParserTest.gd index d639964c..1685c9f6 100644 --- a/addons/gdUnit4/test/core/parse/GdScriptParserTest.gd +++ b/addons/gdUnit4/test/core/parse/GdScriptParserTest.gd @@ -336,15 +336,15 @@ func test_extract_function_signature() -> void: var path := GdObjects.extract_class_path("res://addons/gdUnit4/test/mocker/resources/ClassWithCustomFormattings.gd") var rows = _parser.extract_source_code(path) - assert_that(_parser.extract_func_signature(rows, 9))\ + assert_that(_parser.extract_func_signature(rows, 12))\ .is_equal('func a1(set_name:String, path:String="", load_on_init:bool=false,set_auto_save:bool=false, set_network_sync:bool=false) -> void:') - assert_that(_parser.extract_func_signature(rows, 14))\ - .is_equal('func a2(set_name:String, path:String="", load_on_init:bool=false,set_auto_save:bool=false, set_network_sync:bool=false) -> void:') assert_that(_parser.extract_func_signature(rows, 19))\ + .is_equal('func a2(set_name:String, path:String="", load_on_init:bool=false,set_auto_save:bool=false, set_network_sync:bool=false) -> void:') + assert_that(_parser.extract_func_signature(rows, 26))\ .is_equal('func a3(set_name:String, path:String="", load_on_init:bool=false,set_auto_save:bool=false, set_network_sync:bool=false) :') - assert_that(_parser.extract_func_signature(rows, 24))\ + assert_that(_parser.extract_func_signature(rows, 33))\ .is_equal('func a4(set_name:String,path:String="",load_on_init:bool=false,set_auto_save:bool=false,set_network_sync:bool=false):') - assert_that(_parser.extract_func_signature(rows, 32))\ + assert_that(_parser.extract_func_signature(rows, 43))\ .is_equal('func a5(value : Array,expected : String,test_parameters : Array = [[ ["a"], "a" ],[ ["a", "very", "long", "argument"], "a very long argument" ],]):') diff --git a/addons/gdUnit4/test/core/parse/GdTestParameterSetTest.gd b/addons/gdUnit4/test/core/parse/GdTestParameterSetTest.gd index 652301d1..a27b6b2a 100644 --- a/addons/gdUnit4/test/core/parse/GdTestParameterSetTest.gd +++ b/addons/gdUnit4/test/core/parse/GdTestParameterSetTest.gd @@ -5,28 +5,38 @@ extends GdUnitTestSuite # TestSuite generated from const __source = 'res://addons/gdUnit4/src/core/parse/GdTestParameterSet.gd' + +@warning_ignore("unused_parameter") func test_example_a(a :int, b :int, test_parameters =[[1,2], [3,4]] ) -> void: pass + +@warning_ignore("unused_parameter") func test_example_b(a :Vector2, b :Vector2, test_parameters =[ [Vector2.ZERO, Vector2.ONE], [Vector2(1.1, 3.2), Vector2.DOWN]] ) -> void: pass + +@warning_ignore("unused_parameter") func test_example_c(a :Object, b :Object, test_parameters =[ [Resource.new(), Resource.new()], [Resource.new(), null] ] ) -> void: pass + func build_param(value :float) -> Vector3: return Vector3(value, value, value) + +@warning_ignore("unused_parameter") func test_example_d(a :Vector3, b :Vector3, test_parameters =[ [build_param(1), build_param(3)], [Vector3.BACK, Vector3.UP] ] ) -> void: pass + class TestObj extends RefCounted: var _value :String @@ -36,10 +46,13 @@ class TestObj extends RefCounted: func _to_string() -> String: return _value + +@warning_ignore("unused_parameter") func test_example_e(a: Object, b :Object, expected :String, test_parameters := [ [TestObj.new("abc"), TestObj.new("def"), "abcdef"]]): pass + # verify the used 'test_parameters' is completly resolved func test_extract_parameters() -> void: var script :GDScript = load("res://addons/gdUnit4/test/core/parse/GdTestParameterSetTest.gd") diff --git a/addons/gdUnit4/test/core/resources/Area4D.txt b/addons/gdUnit4/test/core/resources/Area4D.txt index 16c3949b..e3da456d 100644 --- a/addons/gdUnit4/test/core/resources/Area4D.txt +++ b/addons/gdUnit4/test/core/resources/Area4D.txt @@ -4,7 +4,7 @@ const SOUND := 1 const ATMOSPHERE := 2 var _meta := Dictionary() -func _init(x :int, atmospere :AtmosphereData = null): +func _init(_x :int, atmospere :AtmosphereData = null): _meta[ATMOSPHERE] = atmospere func get_sound() -> SoundData: diff --git a/addons/gdUnit4/test/core/resources/AtmosphereData.txt b/addons/gdUnit4/test/core/resources/AtmosphereData.txt index c8b1abcd..3a699749 100644 --- a/addons/gdUnit4/test/core/resources/AtmosphereData.txt +++ b/addons/gdUnit4/test/core/resources/AtmosphereData.txt @@ -18,5 +18,5 @@ func set_data(type := AIR, toxigen := 0.0) : _type = type _toxigen = toxigen -static func to_atmosphere(value :Dictionary) -> AtmosphereData: +static func to_atmosphere(_value :Dictionary) -> AtmosphereData: return null diff --git a/addons/gdUnit4/test/core/resources/SoundData.txt b/addons/gdUnit4/test/core/resources/SoundData.txt index 662f5064..7e61df07 100644 --- a/addons/gdUnit4/test/core/resources/SoundData.txt +++ b/addons/gdUnit4/test/core/resources/SoundData.txt @@ -1,3 +1,4 @@ class SoundData: +@warning_ignore("unused_private_class_variable") var _sample :String var _randomnes :float diff --git a/addons/gdUnit4/test/core/resources/sources/test_person.gd b/addons/gdUnit4/test/core/resources/sources/test_person.gd index a4ee520c..c4a86ca3 100644 --- a/addons/gdUnit4/test/core/resources/sources/test_person.gd +++ b/addons/gdUnit4/test/core/resources/sources/test_person.gd @@ -3,9 +3,9 @@ extends RefCounted var _first_name :String var _last_name :String -func _init(first_name :String,last_name :String): - _first_name = first_name - _last_name = last_name +func _init(first_name_ :String,last_name_ :String): + _first_name = first_name_ + _last_name = last_name_ func first_name() -> String: return _first_name diff --git a/addons/gdUnit4/test/core/resources/test_script_with_arguments.gd b/addons/gdUnit4/test/core/resources/test_script_with_arguments.gd index af849a6f..b9f54554 100644 --- a/addons/gdUnit4/test/core/resources/test_script_with_arguments.gd +++ b/addons/gdUnit4/test/core/resources/test_script_with_arguments.gd @@ -4,22 +4,33 @@ extends Node func test_no_args(): pass +@warning_ignore("unused_parameter") func test_with_timeout(timeout=2000): pass - + + +@warning_ignore("unused_parameter") func test_with_fuzzer(fuzzer := Fuzzers.rangei(-10, 22)): pass + +@warning_ignore("unused_parameter") func test_with_fuzzer_iterations(fuzzer := Fuzzers.rangei(-10, 22), fuzzer_iterations = 10): pass + +@warning_ignore("unused_parameter") func test_with_multible_fuzzers(fuzzer_a := Fuzzers.rangei(-10, 22), fuzzer_b := Fuzzers.rangei(23, 42), fuzzer_iterations = 10): pass + +@warning_ignore("unused_parameter") func test_multiline_arguments_a(fuzzer_a := Fuzzers.rangei(-10, 22), fuzzer_b := Fuzzers.rangei(23, 42), fuzzer_iterations = 42): pass + +@warning_ignore("unused_parameter") func test_multiline_arguments_b( fuzzer_a := Fuzzers.rangei(-10, 22), fuzzer_b := Fuzzers.rangei(23, 42), @@ -27,6 +38,8 @@ func test_multiline_arguments_b( ): pass + +@warning_ignore("unused_parameter") func test_multiline_arguments_c( timeout=2000, fuzzer_a := Fuzzers.rangei(-10, 22), diff --git a/addons/gdUnit4/test/core/resources/testsuites/GdUnitFuzzerTest.resource b/addons/gdUnit4/test/core/resources/testsuites/GdUnitFuzzerTest.resource index 7a9a7588..4ffc7b23 100644 --- a/addons/gdUnit4/test/core/resources/testsuites/GdUnitFuzzerTest.resource +++ b/addons/gdUnit4/test/core/resources/testsuites/GdUnitFuzzerTest.resource @@ -1,6 +1,6 @@ # this test suite simulates long running test cases extends GdUnitTestSuite - +@warning_ignore('unused_parameter') var _stack : Array @@ -13,6 +13,7 @@ func before_test(): _stack.clear() +@warning_ignore('unused_parameter') func test_multi_yielding_with_fuzzer(fuzzer := Fuzzers.rangei(0, 1000), fuzzer_iterations = 10): # verify the used stack is cleaned by 'before_test' assert_array(_stack).is_empty() @@ -29,6 +30,7 @@ func test_multi_yielding_with_fuzzer(fuzzer := Fuzzers.rangei(0, 1000), fuzzer_i await get_tree().process_frame prints("Go") +@warning_ignore('unused_parameter') func test_multi_yielding_with_fuzzer_fail_after_3_iterations(fuzzer := Fuzzers.rangei(0, 1000), fuzzer_iterations = 10): prints("test iteration %d" % fuzzer.iteration_index()) # should never be greater than 3 because we interuppted after three iterations diff --git a/addons/gdUnit4/test/core/resources/testsuites/TestSuiteErrorOnTestTimeout.resource b/addons/gdUnit4/test/core/resources/testsuites/TestSuiteErrorOnTestTimeout.resource index d706d884..b91b3eed 100644 --- a/addons/gdUnit4/test/core/resources/testsuites/TestSuiteErrorOnTestTimeout.resource +++ b/addons/gdUnit4/test/core/resources/testsuites/TestSuiteErrorOnTestTimeout.resource @@ -14,6 +14,7 @@ func after_test(): assert_str("test after").is_equal("test after") # configure test with timeout of 2s +@warning_ignore('unused_parameter') func test_case1(timeout=2000): assert_str("test_case1").is_equal("test_case1") # wait 3s to let the test fail by timeout diff --git a/addons/gdUnit4/test/core/resources/testsuites/TestSuiteInvalidParameterizedTests.resource b/addons/gdUnit4/test/core/resources/testsuites/TestSuiteInvalidParameterizedTests.resource index 12c460c1..bdf871af 100644 --- a/addons/gdUnit4/test/core/resources/testsuites/TestSuiteInvalidParameterizedTests.resource +++ b/addons/gdUnit4/test/core/resources/testsuites/TestSuiteInvalidParameterizedTests.resource @@ -4,6 +4,7 @@ extends GdUnitTestSuite func test_no_parameters(): assert_that(true).is_equal(true) +@warning_ignore('unused_parameter') func test_parameterized_success(a: int, b :int, c :int, expected :int, test_parameters := [ [1, 2, 3, 6], [3, 4, 5, 12], @@ -11,6 +12,7 @@ func test_parameterized_success(a: int, b :int, c :int, expected :int, test_para assert_that(a+b+c).is_equal(expected) +@warning_ignore('unused_parameter') func test_parameterized_failed(a: int, b :int, c :int, expected :int, test_parameters := [ [1, 2, 3, 6], [3, 4, 5, 11], @@ -18,30 +20,35 @@ func test_parameterized_failed(a: int, b :int, c :int, expected :int, test_param assert_that(a+b+c).is_equal(expected) +@warning_ignore('unused_parameter') func test_parameterized_to_less_args(a: int, b :int, expected :int, test_parameters := [ [1, 2, 3, 6], [3, 4, 5, 11], [6, 7, 8, 21] ]): pass +@warning_ignore('unused_parameter') func test_parameterized_to_many_args(a: int, b :int, c :int, d :int, expected :int, test_parameters := [ [1, 2, 3, 6], [3, 4, 5, 11], [6, 7, 8, 21] ]): pass +@warning_ignore('unused_parameter') func test_parameterized_to_less_args_at_index_1(a: int, b :int, expected :int, test_parameters := [ [1, 2, 6], [3, 4, 5, 11], [6, 7, 21] ]): pass +@warning_ignore('unused_parameter') func test_parameterized_invalid_struct(a: int, b :int, expected :int, test_parameters := [ [1, 2, 6], ["foo"], [6, 7, 21] ]): pass +@warning_ignore('unused_parameter') func test_parameterized_invalid_args(a: int, b :int, expected :int, test_parameters := [ [1, 2, 6], [3, "4", 11], diff --git a/addons/gdUnit4/test/core/resources/testsuites/TestSuiteParameterizedTests.resource b/addons/gdUnit4/test/core/resources/testsuites/TestSuiteParameterizedTests.resource index a852f8fd..5d610c40 100644 --- a/addons/gdUnit4/test/core/resources/testsuites/TestSuiteParameterizedTests.resource +++ b/addons/gdUnit4/test/core/resources/testsuites/TestSuiteParameterizedTests.resource @@ -3,12 +3,14 @@ extends GdUnitTestSuite @warning_ignore('unused_parameter') @warning_ignore('return_value_discarded') +@warning_ignore('unused_parameter') func test_parameterized_bool_value(a: int, expected :bool, test_parameters := [ [0, false], [1, true]]): assert_that(bool(a)).is_equal(expected) +@warning_ignore('unused_parameter') func test_parameterized_int_values(a: int, b :int, c :int, expected :int, test_parameters := [ [1, 2, 3, 6], [3, 4, 5, 12], @@ -16,6 +18,7 @@ func test_parameterized_int_values(a: int, b :int, c :int, expected :int, test_p assert_that(a+b+c).is_equal(expected) +@warning_ignore('unused_parameter') func test_parameterized_int_values_fail(a: int, b :int, c :int, expected :int, test_parameters := [ [1, 2, 3, 6], [3, 4, 5, 11], @@ -23,6 +26,7 @@ func test_parameterized_int_values_fail(a: int, b :int, c :int, expected :int, t assert_that(a+b+c).is_equal(expected) +@warning_ignore('unused_parameter') func test_parameterized_float_values(a: float, b :float, expected :float, test_parameters := [ [2.2, 2.2, 4.4], [2.2, 2.3, 4.5], @@ -30,6 +34,7 @@ func test_parameterized_float_values(a: float, b :float, expected :float, test_p assert_float(a+b).is_equal(expected) +@warning_ignore('unused_parameter') func test_parameterized_string_values(a: String, b :String, expected :String, test_parameters := [ ["2.2", "2.2", "2.22.2"], ["foo", "bar", "foobar"], @@ -37,6 +42,7 @@ func test_parameterized_string_values(a: String, b :String, expected :String, te assert_that(a+b).is_equal(expected) +@warning_ignore('unused_parameter') func test_parameterized_Vector2_values(a: Vector2, b :Vector2, expected :Vector2, test_parameters := [ [Vector2.ONE, Vector2.ONE, Vector2(2, 2)], [Vector2.LEFT, Vector2.RIGHT, Vector2.ZERO], @@ -44,6 +50,7 @@ func test_parameterized_Vector2_values(a: Vector2, b :Vector2, expected :Vector2 assert_that(a+b).is_equal(expected) +@warning_ignore('unused_parameter') func test_parameterized_Vector3_values(a: Vector3, b :Vector3, expected :Vector3, test_parameters := [ [Vector3.ONE, Vector3.ONE, Vector3(2, 2, 2)], [Vector3.LEFT, Vector3.RIGHT, Vector3.ZERO], @@ -60,12 +67,14 @@ class TestObj extends Resource: func _to_string() -> String: return _value +@warning_ignore('unused_parameter') func test_parameterized_obj_values(a: Object, b :Object, expected :String, test_parameters := [ [TestObj.new("abc"), TestObj.new("def"), "abcdef"]]): assert_that(a.to_string()+b.to_string()).is_equal(expected) +@warning_ignore('unused_parameter') func test_dictionary_div_number_types( value : Dictionary, expected : Dictionary, diff --git a/addons/gdUnit4/test/extractors/GdUnitFuncValueExtractorTest.gd b/addons/gdUnit4/test/extractors/GdUnitFuncValueExtractorTest.gd index 56532215..88f1c8fa 100644 --- a/addons/gdUnit4/test/extractors/GdUnitFuncValueExtractorTest.gd +++ b/addons/gdUnit4/test/extractors/GdUnitFuncValueExtractorTest.gd @@ -6,41 +6,43 @@ extends GdUnitTestSuite const __source = 'res://addons/gdUnit4/src/extractors/GdUnitFuncValueExtractor.gd' class TestNode extends Resource: - var _name :String var _parent = null var _children := Array() func _init(name :String,parent = null): - _name = name + set_name(name) _parent = parent if _parent: _parent._children.append(self) + func _notification(what): if what == NOTIFICATION_PREDELETE: _parent = null _children.clear() - func get_name() -> String: - return _name func get_parent() -> TestNode: return _parent + func get_children() -> Array: return _children + func test_extract_value_success() -> void: var node = auto_free(TestNode.new("node_a")) assert_str(GdUnitFuncValueExtractor.new("get_name", []).extract_value(node)).is_equal("node_a") + func test_extract_value_func_not_exists() -> void: var node = TestNode.new("node_a") assert_str(GdUnitFuncValueExtractor.new("get_foo", []).extract_value(node)).is_equal("n.a.") + func test_extract_value_on_null_value() -> void: assert_str(GdUnitFuncValueExtractor.new("get_foo", []).extract_value(null)).is_null() @@ -52,6 +54,7 @@ func test_extract_value_chanined() -> void: assert_str(GdUnitFuncValueExtractor.new("get_name", []).extract_value(node)).is_equal("node_a") assert_str(GdUnitFuncValueExtractor.new("get_parent.get_name", []).extract_value(node)).is_equal("parent") + func test_extract_value_chanined_array_values() -> void: var parent = TestNode.new("parent") auto_free(TestNode.new("node_a", parent)) diff --git a/addons/gdUnit4/test/fuzzers/FuzzerToolTest.gd b/addons/gdUnit4/test/fuzzers/FuzzerToolTest.gd index 340ffd16..babdd397 100644 --- a/addons/gdUnit4/test/fuzzers/FuzzerToolTest.gd +++ b/addons/gdUnit4/test/fuzzers/FuzzerToolTest.gd @@ -11,15 +11,15 @@ class NestedFuzzer extends Fuzzer: func next_value()->Dictionary: return {} -static func _s_max_value() -> int: - return MAX_VALUE + static func _s_max_value() -> int: + return MAX_VALUE func min_value() -> int: return MIN_VALUE -func fuzzer() -> Fuzzer: - return Fuzzers.rangei(min_value(), _s_max_value()) - +func get_fuzzer() -> Fuzzer: + return Fuzzers.rangei(min_value(), NestedFuzzer._s_max_value()) + func non_fuzzer() -> Resource: return Image.new() @@ -38,7 +38,7 @@ func test_create_fuzzer_argument_with_constants(): assert_int(fuzzer.next_value()).is_between(-10, 22) func test_create_fuzzer_argument_with_custom_function(): - var fuzzer_arg := GdFunctionArgument.new("fuzzer", GdObjects.TYPE_FUZZER, "fuzzer()") + var fuzzer_arg := GdFunctionArgument.new("fuzzer", GdObjects.TYPE_FUZZER, "get_fuzzer()") var fuzzer := FuzzerTool.create_fuzzer(self.get_script(), fuzzer_arg) assert_that(fuzzer).is_not_null() assert_that(fuzzer).is_instanceof(Fuzzer) diff --git a/addons/gdUnit4/test/fuzzers/GdUnitFuzzerValueInjectionTest.gd b/addons/gdUnit4/test/fuzzers/GdUnitFuzzerValueInjectionTest.gd index 4423343d..d25eab5e 100644 --- a/addons/gdUnit4/test/fuzzers/GdUnitFuzzerValueInjectionTest.gd +++ b/addons/gdUnit4/test/fuzzers/GdUnitFuzzerValueInjectionTest.gd @@ -47,6 +47,8 @@ func after(): assert_int(current).override_failure_message("Expecting %s itertions but is %s checked test case %s" % [expected, current, test_case]).is_equal(expected) var _fuzzer_instance_before : Fuzzer = null + +@warning_ignore("shadowed_variable", "unused_parameter") func test_fuzzer_has_same_instance_peer_iteration(fuzzer=TestFuzzer.new(), fuzzer_iterations = 10): _current_iterations["test_fuzzer_has_same_instance_peer_iteration"] += 1 assert_object(fuzzer).is_not_null() @@ -54,18 +56,22 @@ func test_fuzzer_has_same_instance_peer_iteration(fuzzer=TestFuzzer.new(), fuzze assert_that(fuzzer).is_same(_fuzzer_instance_before) _fuzzer_instance_before = fuzzer +@warning_ignore("shadowed_variable", "unused_parameter") func test_fuzzer_iterations_default(fuzzer := Fuzzers.rangei(-23, 22)): _current_iterations["test_fuzzer_iterations_default"] += 1 assert_object(fuzzer).is_not_null() +@warning_ignore("shadowed_variable", "unused_parameter") func test_fuzzer_iterations_custom_value(fuzzer := Fuzzers.rangei(-23, 22), fuzzer_iterations = 234, fuzzer_seed = 100): _current_iterations["test_fuzzer_iterations_custom_value"] += 1 +@warning_ignore("shadowed_variable", "unused_parameter") func test_fuzzer_inject_value(fuzzer := Fuzzers.rangei(-23, 22), fuzzer_iterations = 100): _current_iterations["test_fuzzer_inject_value"] += 1 assert_object(fuzzer).is_not_null() assert_int(fuzzer.next_value()).is_between(-23, 22) +@warning_ignore("shadowed_variable", "unused_parameter") func test_fuzzer_with_timeout(fuzzer := Fuzzers.rangei(-23, 22), fuzzer_iterations = 20, timeout = 100): discard_error_interupted_by_timeout() assert_int(fuzzer.next_value()).is_between(-23, 22) @@ -76,6 +82,8 @@ func test_fuzzer_with_timeout(fuzzer := Fuzzers.rangei(-23, 22), fuzzer_iteratio assert_int(fuzzer.iteration_index()).is_less_equal(10) var expected_value := [22, 3, -14, -16, 21, 20, 4, -23, -19, -5] + +@warning_ignore("shadowed_variable", "unused_parameter") func test_fuzzer_inject_value_with_seed(fuzzer := Fuzzers.rangei(-23, 22), fuzzer_iterations = 10, fuzzer_seed = 187772): assert_object(fuzzer).is_not_null() var iteration_index = fuzzer.iteration_index()-1 @@ -88,6 +96,8 @@ func test_fuzzer_inject_value_with_seed(fuzzer := Fuzzers.rangei(-23, 22), fuzze var expected_value_a := [22, -14, 21, 4, -19, -11, 5, 21, -6, -9] var expected_value_b := [35, 38, 34, 39, 35, 41, 37, 35, 34, 39] + +@warning_ignore("shadowed_variable", "unused_parameter") func test_multiple_fuzzers_inject_value_with_seed(fuzzer_a := Fuzzers.rangei(-23, 22), fuzzer_b := Fuzzers.rangei(33, 44), fuzzer_iterations = 10, fuzzer_seed = 187772): _current_iterations["test_multiple_fuzzers_inject_value_with_seed"] += 1 assert_object(fuzzer_a).is_not_null() @@ -109,6 +119,7 @@ func test_multiple_fuzzers_inject_value_with_seed(fuzzer_a := Fuzzers.rangei(-23 .override_failure_message("Expect value %s checked test iteration %s\n but was %s" % [expected_b, iteration_index_b, current_b])\ .is_equal(expected_b) +@warning_ignore("shadowed_variable", "unused_parameter") func test_fuzzer_error_after_eight_iterations(fuzzer=TestFuzzer.new(), fuzzer_iterations = 10): assert_object(fuzzer).is_not_null() # should fail after 8 iterations @@ -119,10 +130,12 @@ func test_fuzzer_error_after_eight_iterations(fuzzer=TestFuzzer.new(), fuzzer_it else: assert_int(fuzzer.next_value()).is_between(0, 9) +@warning_ignore("shadowed_variable", "unused_parameter") func test_fuzzer_custom_func(fuzzer=fuzzer()): assert_object(fuzzer).is_not_null() assert_int(fuzzer.next_value()).is_between(1, 10) +@warning_ignore("shadowed_variable", "unused_parameter") func test_multiline_fuzzer_args( fuzzer_a := Fuzzers.rangev2(Vector2(-47, -47), Vector2(47, 47)), fuzzer_b := Fuzzers.rangei(0, 9), diff --git a/addons/gdUnit4/test/fuzzers/TestExternalFuzzer.gd b/addons/gdUnit4/test/fuzzers/TestExternalFuzzer.gd index c4648ffb..cc53b0a4 100644 --- a/addons/gdUnit4/test/fuzzers/TestExternalFuzzer.gd +++ b/addons/gdUnit4/test/fuzzers/TestExternalFuzzer.gd @@ -3,6 +3,6 @@ extends Fuzzer func _init(): pass - + func next_value()->Dictionary: return {} diff --git a/addons/gdUnit4/test/mocker/GdUnitMockBuilderTest.gd b/addons/gdUnit4/test/mocker/GdUnitMockBuilderTest.gd index 8278687f..ebcadcc6 100644 --- a/addons/gdUnit4/test/mocker/GdUnitMockBuilderTest.gd +++ b/addons/gdUnit4/test/mocker/GdUnitMockBuilderTest.gd @@ -7,7 +7,7 @@ const __source = 'res://addons/gdUnit4/src/mocking/GdUnitMockBuilder.gd' # helper to get function descriptor -static func get_function_description(clazz_name :String, method_name :String) -> GdFunctionDescriptor: +func get_function_description(clazz_name :String, method_name :String) -> GdFunctionDescriptor: var method_list :Array = ClassDB.class_get_method_list(clazz_name) for method_descriptor in method_list: if method_descriptor["name"] == method_name: @@ -21,6 +21,7 @@ func test_double_return_typed_function_without_arg() -> void: var fd := get_function_description("Object", "get_class") var expected := [ '@warning_ignore("native_method_override")', + '@warning_ignore("shadowed_variable")', 'func get_class() -> String:', ' var args :Array = ["get_class", ]', ' ', @@ -49,6 +50,7 @@ func test_double_return_typed_function_with_args() -> void: var fd := get_function_description("Object", "is_connected") var expected := [ '@warning_ignore("native_method_override")', + '@warning_ignore("shadowed_variable")', 'func is_connected(signal_, callable_) -> bool:', ' var args :Array = ["is_connected", signal_, callable_]', ' ', @@ -78,6 +80,7 @@ func test_double_return_untyped_function_with_args() -> void: var fd := get_function_description("Object", "disconnect") var expected := [ '@warning_ignore("native_method_override")', + '@warning_ignore("shadowed_variable")', 'func disconnect(signal_, callable_) -> void:', ' var args :Array = ["disconnect", signal_, callable_]', ' ', @@ -104,6 +107,7 @@ func test_double_int_function_with_varargs() -> void: var fd := get_function_description("Object", "emit_signal") var expected := [ '@warning_ignore("native_method_override")', + '@warning_ignore("shadowed_variable")', 'func emit_signal(signal_, vararg0_="__null__", vararg1_="__null__", vararg2_="__null__", vararg3_="__null__", vararg4_="__null__", vararg5_="__null__", vararg6_="__null__", vararg7_="__null__", vararg8_="__null__", vararg9_="__null__") -> Error:', ' var varargs :Array = __filter_vargs([vararg0_, vararg1_, vararg2_, vararg3_, vararg4_, vararg5_, vararg6_, vararg7_, vararg8_, vararg9_])', ' var args :Array = ["emit_signal", signal_] + varargs', @@ -145,6 +149,7 @@ func test_double_untyped_function_with_varargs() -> void: [GdFunctionArgument.new("signal_", TYPE_SIGNAL)], GdFunctionDescriptor._build_varargs(true)) var expected := [ + '@warning_ignore("shadowed_variable")', 'func emit_custom(signal_, vararg0_="__null__", vararg1_="__null__", vararg2_="__null__", vararg3_="__null__", vararg4_="__null__", vararg5_="__null__", vararg6_="__null__", vararg7_="__null__", vararg8_="__null__", vararg9_="__null__") -> void:', ' var varargs :Array = __filter_vargs([vararg0_, vararg1_, vararg2_, vararg3_, vararg4_, vararg5_, vararg6_, vararg7_, vararg8_, vararg9_])', ' var args :Array = ["emit_custom", signal_] + varargs', @@ -185,6 +190,7 @@ func test_double_virtual_script_function_without_arg() -> void: var fd := get_function_description("Node", "_ready") var expected := [ '@warning_ignore("native_method_override")', + '@warning_ignore("shadowed_variable")', 'func _ready() -> void:', ' var args :Array = ["_ready", ]', ' ', @@ -212,6 +218,7 @@ func test_double_virtual_script_function_with_arg() -> void: var fd := get_function_description("Node", "_input") var expected := [ '@warning_ignore("native_method_override")', + '@warning_ignore("shadowed_variable")', 'func _input(event_) -> void:', ' var args :Array = ["_input", event_]', ' ', diff --git a/addons/gdUnit4/test/mocker/GdUnitMockerTest.gd b/addons/gdUnit4/test/mocker/GdUnitMockerTest.gd index ddb1bae4..10115063 100644 --- a/addons/gdUnit4/test/mocker/GdUnitMockerTest.gd +++ b/addons/gdUnit4/test/mocker/GdUnitMockerTest.gd @@ -70,12 +70,13 @@ func test_is_mockable__overriden_func_get_class(): .is_true() +@warning_ignore("unused_parameter") func test_mock_godot_class_fullcheck(fuzzer=GodotClassNameFuzzer.new(), fuzzer_iterations=200): var clazz_name = fuzzer.next_value() # try to create a mock if GdUnitMockBuilder.is_mockable(clazz_name): - var mock = mock(clazz_name, CALL_REAL_FUNC) - assert_that(mock)\ + var m = mock(clazz_name, CALL_REAL_FUNC) + assert_that(m)\ .override_failure_message("The class %s should be mockable" % clazz_name)\ .is_not_null() @@ -100,8 +101,8 @@ func test_mock_fail(): func test_mock_special_classes(): - var mock = mock("JavaClass") as JavaClass - assert_that(mock).is_not_null() + var m = mock("JavaClass") as JavaClass + assert_that(m).is_not_null() func test_mock_Node(): @@ -133,21 +134,21 @@ func test_mock_Node(): func test_mock_source_with_class_name_by_resource_path() -> void: - var resource_path := 'res://addons/gdUnit4/test/mocker/resources/GD-256/world.gd' - var m = mock(resource_path) + var resource_path_ := 'res://addons/gdUnit4/test/mocker/resources/GD-256/world.gd' + var m = mock(resource_path_) var head :String = m.get_script().source_code.substr(0, 200) assert_str(head)\ .contains("class_name DoubledMunderwoodPathingWorld")\ - .contains("extends '%s'" % resource_path) + .contains("extends '%s'" % resource_path_) func test_mock_source_with_class_name_by_class() -> void: - var resource_path := 'res://addons/gdUnit4/test/mocker/resources/GD-256/world.gd' + var resource_path_ := 'res://addons/gdUnit4/test/mocker/resources/GD-256/world.gd' var m = mock(Munderwood_Pathing_World) var head :String = m.get_script().source_code.substr(0, 200) assert_str(head)\ .contains("class_name DoubledMunderwoodPathingWorld")\ - .contains("extends '%s'" % resource_path) + .contains("extends '%s'" % resource_path_) func test_mock_extends_godot_class() -> void: @@ -230,402 +231,395 @@ func _test_mock_verify_emit_signal(): func test_mock_custom_class_by_class_name(): - var mock = mock(CustomResourceTestClass) - assert_that(mock).is_not_null() + var m = mock(CustomResourceTestClass) + assert_that(m).is_not_null() # test we have initial no interactions checked this mock - verify_no_interactions(mock) + verify_no_interactions(m) # test mocked function returns default typed value - assert_that(mock.foo()).is_equal("") + assert_that(m.foo()).is_equal("") # now mock return value for function 'foo' to 'overwriten value' - do_return("overriden value").checked(mock).foo() + do_return("overriden value").checked(m).foo() # verify the return value is overwritten - assert_that(mock.foo()).is_equal("overriden value") + assert_that(m.foo()).is_equal("overriden value") # now mock return values by custom arguments - do_return("arg_1").checked(mock).bar(1) - do_return("arg_2").checked(mock).bar(2) + do_return("arg_1").checked(m).bar(1) + do_return("arg_2").checked(m).bar(2) - assert_that(mock.bar(1)).is_equal("arg_1") - assert_that(mock.bar(2)).is_equal("arg_2") + assert_that(m.bar(1)).is_equal("arg_1") + assert_that(m.bar(2)).is_equal("arg_2") func test_mock_custom_class_by_resource_path(): - var mock = mock("res://addons/gdUnit4/test/mocker/resources/CustomResourceTestClass.gd") - assert_that(mock).is_not_null() + var m = mock("res://addons/gdUnit4/test/mocker/resources/CustomResourceTestClass.gd") + assert_that(m).is_not_null() # test we have initial no interactions checked this mock - verify_no_interactions(mock) + verify_no_interactions(m) # test mocked function returns default typed value - assert_that(mock.foo()).is_equal("") + assert_that(m.foo()).is_equal("") # now mock return value for function 'foo' to 'overwriten value' - do_return("overriden value").checked(mock).foo() + do_return("overriden value").checked(m).foo() # verify the return value is overwritten - assert_that(mock.foo()).is_equal("overriden value") + assert_that(m.foo()).is_equal("overriden value") # now mock return values by custom arguments - do_return("arg_1").checked(mock).bar(1) - do_return("arg_2").checked(mock).bar(2) + do_return("arg_1").checked(m).bar(1) + do_return("arg_2").checked(m).bar(2) - assert_that(mock.bar(1)).is_equal("arg_1") - assert_that(mock.bar(2)).is_equal("arg_2") + assert_that(m.bar(1)).is_equal("arg_1") + assert_that(m.bar(2)).is_equal("arg_2") func test_mock_custom_class_func_foo_use_real_func(): - var mock = mock(CustomResourceTestClass, CALL_REAL_FUNC) - assert_that(mock).is_not_null() + var m = mock(CustomResourceTestClass, CALL_REAL_FUNC) + assert_that(m).is_not_null() # test mocked function returns value from real function - assert_that(mock.foo()).is_equal("foo") + assert_that(m.foo()).is_equal("foo") # now mock return value for function 'foo' to 'overwriten value' - do_return("overridden value").checked(mock).foo() + do_return("overridden value").checked(m).foo() # verify the return value is overwritten - assert_that(mock.foo()).is_equal("overridden value") + assert_that(m.foo()).is_equal("overridden value") func test_mock_custom_class_void_func(): - var mock = mock(CustomResourceTestClass) - assert_that(mock).is_not_null() + var m = mock(CustomResourceTestClass) + assert_that(m).is_not_null() # test mocked void function returns null by default - assert_that(mock.foo_void()).is_null() + assert_that(m.foo_void()).is_null() # try now mock return value for a void function. results into an error - do_return("overridden value").checked(mock).foo_void() + do_return("overridden value").checked(m).foo_void() # verify it has no affect for void func - assert_that(mock.foo_void()).is_null() + assert_that(m.foo_void()).is_null() func test_mock_custom_class_void_func_real_func(): - var mock = mock(CustomResourceTestClass, CALL_REAL_FUNC) - assert_that(mock).is_not_null() + var m = mock(CustomResourceTestClass, CALL_REAL_FUNC) + assert_that(m).is_not_null() # test mocked void function returns null by default - assert_that(mock.foo_void()).is_null() + assert_that(m.foo_void()).is_null() # try now mock return value for a void function. results into an error - do_return("overridden value").checked(mock).foo_void() + do_return("overridden value").checked(m).foo_void() # verify it has no affect for void func - assert_that(mock.foo_void()).is_null() + assert_that(m.foo_void()).is_null() func test_mock_custom_class_func_foo_call_times(): - var mock = mock(CustomResourceTestClass) - assert_that(mock).is_not_null() - verify(mock, 0).foo() - mock.foo() - verify(mock, 1).foo() - mock.foo() - verify(mock, 2).foo() - mock.foo() - mock.foo() - verify(mock, 4).foo() + var m = mock(CustomResourceTestClass) + assert_that(m).is_not_null() + verify(m, 0).foo() + m.foo() + verify(m, 1).foo() + m.foo() + verify(m, 2).foo() + m.foo() + m.foo() + verify(m, 4).foo() func test_mock_custom_class_func_foo_call_times_real_func(): - var mock = mock(CustomResourceTestClass, CALL_REAL_FUNC) - assert_that(mock).is_not_null() - verify(mock, 0).foo() - mock.foo() - verify(mock, 1).foo() - mock.foo() - verify(mock, 2).foo() - mock.foo() - mock.foo() - verify(mock, 4).foo() + var m = mock(CustomResourceTestClass, CALL_REAL_FUNC) + assert_that(m).is_not_null() + verify(m, 0).foo() + m.foo() + verify(m, 1).foo() + m.foo() + verify(m, 2).foo() + m.foo() + m.foo() + verify(m, 4).foo() func test_mock_custom_class_func_foo_full_test(): - var mock = mock(CustomResourceTestClass) - assert_that(mock).is_not_null() - verify(mock, 0).foo() - assert_that(mock.foo()).is_equal("") - verify(mock, 1).foo() - do_return("new value").checked(mock).foo() - verify(mock, 1).foo() - assert_that(mock.foo()).is_equal("new value") - verify(mock, 2).foo() + var m = mock(CustomResourceTestClass) + assert_that(m).is_not_null() + verify(m, 0).foo() + assert_that(m.foo()).is_equal("") + verify(m, 1).foo() + do_return("new value").checked(m).foo() + verify(m, 1).foo() + assert_that(m.foo()).is_equal("new value") + verify(m, 2).foo() func test_mock_custom_class_func_foo_full_test_real_func(): - var mock = mock(CustomResourceTestClass, CALL_REAL_FUNC) - assert_that(mock).is_not_null() - verify(mock, 0).foo() - assert_that(mock.foo()).is_equal("foo") - verify(mock, 1).foo() - do_return("new value").checked(mock).foo() - verify(mock, 1).foo() - assert_that(mock.foo()).is_equal("new value") - verify(mock, 2).foo() + var m = mock(CustomResourceTestClass, CALL_REAL_FUNC) + assert_that(m).is_not_null() + verify(m, 0).foo() + assert_that(m.foo()).is_equal("foo") + verify(m, 1).foo() + do_return("new value").checked(m).foo() + verify(m, 1).foo() + assert_that(m.foo()).is_equal("new value") + verify(m, 2).foo() func test_mock_custom_class_func_bar(): - var mock = mock(CustomResourceTestClass) - assert_that(mock).is_not_null() - assert_that(mock.bar(10)).is_equal("") + var m = mock(CustomResourceTestClass) + assert_that(m).is_not_null() + assert_that(m.bar(10)).is_equal("") # verify 'bar' with args [10] is called one time at this point - verify(mock, 1).bar(10) + verify(m, 1).bar(10) # verify 'bar' with args [10, 20] is never called at this point - verify(mock, 0).bar(10, 29) + verify(m, 0).bar(10, 29) # verify 'bar' with args [23] is never called at this point - verify(mock, 0).bar(23) + verify(m, 0).bar(23) # now mock return value for function 'bar' with args [10] to 'overwriten value' - do_return("overridden value").checked(mock).bar(10) + do_return("overridden value").checked(m).bar(10) # verify the return value is overwritten - assert_that(mock.bar(10)).is_equal("overridden value") + assert_that(m.bar(10)).is_equal("overridden value") # finally verify function call times - verify(mock, 2).bar(10) - verify(mock, 0).bar(10, 29) - verify(mock, 0).bar(23) + verify(m, 2).bar(10) + verify(m, 0).bar(10, 29) + verify(m, 0).bar(23) func test_mock_custom_class_func_bar_real_func(): - var mock = mock(CustomResourceTestClass, CALL_REAL_FUNC) - assert_that(mock).is_not_null() - assert_that(mock.bar(10)).is_equal("test_33") + var m = mock(CustomResourceTestClass, CALL_REAL_FUNC) + assert_that(m).is_not_null() + assert_that(m.bar(10)).is_equal("test_33") # verify 'bar' with args [10] is called one time at this point - verify(mock, 1).bar(10) + verify(m, 1).bar(10) # verify 'bar' with args [10, 20] is never called at this point - verify(mock, 0).bar(10, 29) + verify(m, 0).bar(10, 29) # verify 'bar' with args [23] is never called at this point - verify(mock, 0).bar(23) + verify(m, 0).bar(23) # now mock return value for function 'bar' with args [10] to 'overwriten value' - do_return("overridden value").checked(mock).bar(10) + do_return("overridden value").checked(m).bar(10) # verify the return value is overwritten - assert_that(mock.bar(10)).is_equal("overridden value") + assert_that(m.bar(10)).is_equal("overridden value") # verify the real implementation is used - assert_that(mock.bar(10, 29)).is_equal("test_39") - assert_that(mock.bar(10, 20, "other")).is_equal("other_30") + assert_that(m.bar(10, 29)).is_equal("test_39") + assert_that(m.bar(10, 20, "other")).is_equal("other_30") # finally verify function call times - verify(mock, 2).bar(10) - verify(mock, 1).bar(10, 29) - verify(mock, 0).bar(10, 20) - verify(mock, 1).bar(10, 20, "other") + verify(m, 2).bar(10) + verify(m, 1).bar(10, 29) + verify(m, 0).bar(10, 20) + verify(m, 1).bar(10, 20, "other") func test_mock_custom_class_extends_Node(): - var mock = mock(CustomNodeTestClass) - assert_that(mock).is_not_null() + var m = mock(CustomNodeTestClass) + assert_that(m).is_not_null() # test mocked function returns null as default - assert_that(mock.get_child_count()).is_equal(0) - assert_that(mock.get_children()).contains_exactly([]) + assert_that(m.get_child_count()).is_equal(0) + assert_that(m.get_children()).contains_exactly([]) # test seters has no affect var node = auto_free(Node.new()) - mock.add_child(node) - assert_that(mock.get_child_count()).is_equal(0) - assert_that(mock.get_children()).contains_exactly([]) - verify(mock, 1).add_child(node) - verify(mock, 2).get_child_count() - verify(mock, 2).get_children() + m.add_child(node) + assert_that(m.get_child_count()).is_equal(0) + assert_that(m.get_children()).contains_exactly([]) + verify(m, 1).add_child(node) + verify(m, 2).get_child_count() + verify(m, 2).get_children() func test_mock_custom_class_extends_Node_real_func(): - var mock = mock(CustomNodeTestClass, CALL_REAL_FUNC) - assert_that(mock).is_not_null() + var m = mock(CustomNodeTestClass, CALL_REAL_FUNC) + assert_that(m).is_not_null() # test mocked function returns default mock value - assert_that(mock.get_child_count()).is_equal(0) - assert_that(mock.get_children()).is_equal([]) + assert_that(m.get_child_count()).is_equal(0) + assert_that(m.get_children()).is_equal([]) # test real seters used var nodeA = auto_free(Node.new()) var nodeB = auto_free(Node.new()) var nodeC = auto_free(Node.new()) - mock.add_child(nodeA) - mock.add_child(nodeB) - assert_that(mock.get_child_count()).is_equal(2) - assert_that(mock.get_children()).contains_exactly([nodeA, nodeB]) - verify(mock, 1).add_child(nodeA) - verify(mock, 1).add_child(nodeB) - verify(mock, 0).add_child(nodeC) - verify(mock, 2).get_child_count() - verify(mock, 2).get_children() + m.add_child(nodeA) + m.add_child(nodeB) + assert_that(m.get_child_count()).is_equal(2) + assert_that(m.get_children()).contains_exactly([nodeA, nodeB]) + verify(m, 1).add_child(nodeA) + verify(m, 1).add_child(nodeB) + verify(m, 0).add_child(nodeC) + verify(m, 2).get_child_count() + verify(m, 2).get_children() func test_mock_custom_class_extends_other_custom_class(): - var mock = mock(CustomClassExtendsCustomClass) + var m = mock(CustomClassExtendsCustomClass) assert_that(mock).is_not_null() # foo() form parent class - verify(mock, 0).foo() + verify(m, 0).foo() # foo2() overriden - verify(mock, 0).foo2() + verify(m, 0).foo2() # bar2() from class - verify(mock, 0).bar2() + verify(m, 0).bar2() - assert_that(mock.foo()).is_empty() - assert_that(mock.foo2()).is_null() - assert_that(mock.bar2()).is_empty() + assert_that(m.foo()).is_empty() + assert_that(m.foo2()).is_null() + assert_that(m.bar2()).is_empty() - verify(mock, 1).foo() - verify(mock, 1).foo2() - verify(mock, 1).bar2() + verify(m, 1).foo() + verify(m, 1).foo2() + verify(m, 1).bar2() # override returns - do_return("abc1").checked(mock).foo() - do_return("abc2").checked(mock).foo2() - do_return("abc3").checked(mock).bar2() + do_return("abc1").checked(m).foo() + do_return("abc2").checked(m).foo2() + do_return("abc3").checked(m).bar2() - assert_that(mock.foo()).is_equal("abc1") - assert_that(mock.foo2()).is_equal("abc2") - assert_that(mock.bar2()).is_equal("abc3") + assert_that(m.foo()).is_equal("abc1") + assert_that(m.foo2()).is_equal("abc2") + assert_that(m.bar2()).is_equal("abc3") func test_mock_custom_class_extends_other_custom_class_call_real_func(): - var mock = mock(CustomClassExtendsCustomClass, CALL_REAL_FUNC) - assert_that(mock).is_not_null() + var m = mock(CustomClassExtendsCustomClass, CALL_REAL_FUNC) + assert_that(m).is_not_null() # foo() form parent class - verify(mock, 0).foo() + verify(m, 0).foo() # foo2() overriden - verify(mock, 0).foo2() + verify(m, 0).foo2() # bar2() from class - verify(mock, 0).bar2() + verify(m, 0).bar2() - assert_that(mock.foo()).is_equal("foo") - assert_that(mock.foo2()).is_equal("foo2 overriden") - assert_that(mock.bar2()).is_equal("test_65") + assert_that(m.foo()).is_equal("foo") + assert_that(m.foo2()).is_equal("foo2 overriden") + assert_that(m.bar2()).is_equal("test_65") - verify(mock, 1).foo() - verify(mock, 1).foo2() - verify(mock, 1).bar2() + verify(m, 1).foo() + verify(m, 1).foo2() + verify(m, 1).bar2() # override returns - do_return("abc1").checked(mock).foo() - do_return("abc2").checked(mock).foo2() - do_return("abc3").checked(mock).bar2() + do_return("abc1").checked(m).foo() + do_return("abc2").checked(m).foo2() + do_return("abc3").checked(m).bar2() - assert_that(mock.foo()).is_equal("abc1") - assert_that(mock.foo2()).is_equal("abc2") - assert_that(mock.bar2()).is_equal("abc3") + assert_that(m.foo()).is_equal("abc1") + assert_that(m.foo2()).is_equal("abc2") + assert_that(m.bar2()).is_equal("abc3") func test_mock_static_func(): - var mock = mock(CustomNodeTestClass) - assert_that(mock).is_not_null() + var m = mock(CustomNodeTestClass) + assert_that(m).is_not_null() # initial not called - verify(mock, 0).static_test() - verify(mock, 0).static_test_void() + verify(m, 0).static_test() + verify(m, 0).static_test_void() - assert_that(mock.static_test()).is_equal("") - assert_that(mock.static_test_void()).is_null() + assert_that(m.static_test()).is_equal("") + assert_that(m.static_test_void()).is_null() - verify(mock, 1).static_test() - verify(mock, 1).static_test_void() - mock.static_test() - mock.static_test_void() - mock.static_test_void() - verify(mock, 2).static_test() - verify(mock, 3).static_test_void() + verify(m, 1).static_test() + verify(m, 1).static_test_void() + m.static_test() + m.static_test_void() + m.static_test_void() + verify(m, 2).static_test() + verify(m, 3).static_test_void() func test_mock_static_func_real_func(): - var mock = mock(CustomNodeTestClass, CALL_REAL_FUNC) - assert_that(mock).is_not_null() + var m = mock(CustomNodeTestClass, CALL_REAL_FUNC) + assert_that(m).is_not_null() # initial not called - verify(mock, 0).static_test() - verify(mock, 0).static_test_void() + verify(m, 0).static_test() + verify(m, 0).static_test_void() - assert_that(mock.static_test()).is_equal(CustomNodeTestClass.STATIC_FUNC_RETURN_VALUE) - assert_that(mock.static_test_void()).is_null() + assert_that(m.static_test()).is_equal(CustomNodeTestClass.STATIC_FUNC_RETURN_VALUE) + assert_that(m.static_test_void()).is_null() - verify(mock, 1).static_test() - verify(mock, 1).static_test_void() - mock.static_test() - mock.static_test_void() - mock.static_test_void() - verify(mock, 2).static_test() - verify(mock, 3).static_test_void() - - -func _test_mock_mode_deep_stub(): - var mocked_shape = mock(DeepStubTestClass.XShape) - #var t := DeepStubTestClass.new() - #t.add(mocked_shape) - #assert_bool(t.validate()).is_true() + verify(m, 1).static_test() + verify(m, 1).static_test_void() + m.static_test() + m.static_test_void() + m.static_test_void() + verify(m, 2).static_test() + verify(m, 3).static_test_void() func test_mock_custom_class_assert_has_no_side_affect(): - var mock = mock(CustomNodeTestClass) - assert_that(mock).is_not_null() + var m = mock(CustomNodeTestClass) + assert_that(m).is_not_null() var node = Node.new() # verify the assertions has no side affect checked mocked object - verify(mock, 0).add_child(node) + verify(m, 0).add_child(node) # expect no change checked childrens - assert_that(mock.get_children()).contains_exactly([]) + assert_that(m.get_children()).contains_exactly([]) - mock.add_child(node) + m.add_child(node) # try thre times 'assert_called' to see it has no affect to the mock - verify(mock, 1).add_child(node) - verify(mock, 1).add_child(node) - verify(mock, 1).add_child(node) - assert_that(mock.get_children()).contains_exactly([]) + verify(m, 1).add_child(node) + verify(m, 1).add_child(node) + verify(m, 1).add_child(node) + assert_that(m.get_children()).contains_exactly([]) # needs to be manually freed node.free() func test_mock_custom_class_assert_has_no_side_affect_real_func(): - var mock = mock(CustomNodeTestClass, CALL_REAL_FUNC) - assert_that(mock).is_not_null() + var m = mock(CustomNodeTestClass, CALL_REAL_FUNC) + assert_that(m).is_not_null() var node = Node.new() # verify the assertions has no side affect checked mocked object - verify(mock, 0).add_child(node) + verify(m, 0).add_child(node) # expect no change checked childrens - assert_that(mock.get_children()).contains_exactly([]) + assert_that(m.get_children()).contains_exactly([]) - mock.add_child(node) + m.add_child(node) # try thre times 'assert_called' to see it has no affect to the mock - verify(mock, 1).add_child(node) - verify(mock, 1).add_child(node) - verify(mock, 1).add_child(node) - assert_that(mock.get_children()).contains_exactly([node]) + verify(m, 1).add_child(node) + verify(m, 1).add_child(node) + verify(m, 1).add_child(node) + assert_that(m.get_children()).contains_exactly([node]) # This test verifies a function is calling other internally functions # to collect the access times and the override return value is working as expected func test_mock_advanced_func_path(): - var mock = mock(AdvancedTestClass, CALL_REAL_FUNC) + var m = mock(AdvancedTestClass, CALL_REAL_FUNC) # initial nothing is called - verify(mock, 0).select(AdvancedTestClass.A) - verify(mock, 0).select(AdvancedTestClass.B) - verify(mock, 0).select(AdvancedTestClass.C) - verify(mock, 0).a() - verify(mock, 0).b() - verify(mock, 0).c() + verify(m, 0).select(AdvancedTestClass.A) + verify(m, 0).select(AdvancedTestClass.B) + verify(m, 0).select(AdvancedTestClass.C) + verify(m, 0).a() + verify(m, 0).b() + verify(m, 0).c() # the function select() swiches based checked input argument to function a(), b() or c() # call select where called internally func a() and returned "a" - assert_that(mock.select(AdvancedTestClass.A)).is_equal("a") + assert_that(m.select(AdvancedTestClass.A)).is_equal("a") # verify when call select() is also calling original func a() - verify(mock, 1).select(AdvancedTestClass.A) - verify(mock, 1).a() + verify(m, 1).select(AdvancedTestClass.A) + verify(m, 1).a() # call select again wiht overriden return value for func a() - do_return("overridden a func").checked(mock).a() - assert_that(mock.select(AdvancedTestClass.A)).is_equal("overridden a func") + do_return("overridden a func").checked(m).a() + assert_that(m.select(AdvancedTestClass.A)).is_equal("overridden a func") # verify at this time select() and a() is called two times - verify(mock, 2).select(AdvancedTestClass.A) - verify(mock, 0).select(AdvancedTestClass.B) - verify(mock, 0).select(AdvancedTestClass.C) - verify(mock, 2).a() - verify(mock, 0).b() - verify(mock, 0).c() + verify(m, 2).select(AdvancedTestClass.A) + verify(m, 0).select(AdvancedTestClass.B) + verify(m, 0).select(AdvancedTestClass.C) + verify(m, 2).a() + verify(m, 0).b() + verify(m, 0).c() # finally use select to switch to internally func c() - assert_that(mock.select(AdvancedTestClass.C)).is_equal("c") - verify(mock, 2).select(AdvancedTestClass.A) - verify(mock, 0).select(AdvancedTestClass.B) - verify(mock, 1).select(AdvancedTestClass.C) - verify(mock, 2).a() - verify(mock, 0).b() - verify(mock, 1).c() + assert_that(m.select(AdvancedTestClass.C)).is_equal("c") + verify(m, 2).select(AdvancedTestClass.A) + verify(m, 0).select(AdvancedTestClass.B) + verify(m, 1).select(AdvancedTestClass.C) + verify(m, 2).a() + verify(m, 0).b() + verify(m, 1).c() func _test_mock_godot_class_calls_sub_function(): - var mock = mock(MeshInstance3D, CALL_REAL_FUNC) - verify(mock, 0)._mesh_changed() - mock.set_mesh(QuadMesh.new()) - verify(mock, 1).set_mesh(any_class(Mesh)) - verify(mock, 1)._mesh_changed() + var m = mock(MeshInstance3D, CALL_REAL_FUNC) + verify(m, 0)._mesh_changed() + m.set_mesh(QuadMesh.new()) + verify(m, 1).set_mesh(any_class(Mesh)) + verify(m, 1)._mesh_changed() func test_mock_class_with_inner_classs(): @@ -870,12 +864,12 @@ func test_mock_snake_case_named_godot_class_by_name(): func test_mock_snake_case_named_class_by_class(): - var mock = mock(snake_case_class_name) - assert_object(mock).is_not_null() + var m = mock(snake_case_class_name) + assert_object(m).is_not_null() - mock.custom_func() - verify(mock).custom_func() - verify_no_more_interactions(mock) + m.custom_func() + verify(m).custom_func() + verify_no_more_interactions(m) # try checked Godot class var mocked_tcp_server = mock(TCPServer) @@ -889,21 +883,21 @@ func test_mock_snake_case_named_class_by_class(): func test_mock_func_with_default_build_in_type(): - var mock = mock(ClassWithDefaultBuildIntTypes) - assert_object(mock).is_not_null() + var m = mock(ClassWithDefaultBuildIntTypes) + assert_object(m).is_not_null() # call with default arg - mock.foo("abc") - mock.bar("def") - verify(mock).foo("abc", Color.RED) - verify(mock).bar("def", Vector3.FORWARD, AABB()) - verify_no_more_interactions(mock) + m.foo("abc") + m.bar("def") + verify(m).foo("abc", Color.RED) + verify(m).bar("def", Vector3.FORWARD, AABB()) + verify_no_more_interactions(m) # call with custom color arg - mock.foo("abc", Color.BLUE) - mock.bar("def", Vector3.DOWN, AABB(Vector3.ONE, Vector3.ZERO)) - verify(mock).foo("abc", Color.BLUE) - verify(mock).bar("def", Vector3.DOWN, AABB(Vector3.ONE, Vector3.ZERO)) - verify_no_more_interactions(mock) + m.foo("abc", Color.BLUE) + m.bar("def", Vector3.DOWN, AABB(Vector3.ONE, Vector3.ZERO)) + verify(m).foo("abc", Color.BLUE) + verify(m).bar("def", Vector3.DOWN, AABB(Vector3.ONE, Vector3.ZERO)) + verify_no_more_interactions(m) func test_mock_virtual_function_is_not_called_twice() -> void: @@ -918,24 +912,24 @@ func test_mock_virtual_function_is_not_called_twice() -> void: # get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_ready,NULL,0); # } - var mock = mock(ClassWithOverridenVirtuals, CALL_REAL_FUNC) - assert_object(mock).is_not_null() + var m = mock(ClassWithOverridenVirtuals, CALL_REAL_FUNC) + assert_object(m).is_not_null() # inital constructor - assert_that(mock._x).is_equal("_init") + assert_that(m._x).is_equal("_init") # add_child calls internally by "default" _ready() where is a virtual function - add_child(mock) + add_child(m) # verify _ready func is only once called - assert_that(mock._x).is_equal("_ready") + assert_that(m._x).is_equal("_ready") # now simulate an input event calls '_input' var action = InputEventKey.new() action.pressed = false action.keycode = KEY_ENTER get_tree().root.push_input(action) - assert_that(mock._x).is_equal("ui_accept") + assert_that(m._x).is_equal("ui_accept") func test_mock_scene_by_path(): @@ -1003,7 +997,7 @@ func test_mock_scene_execute_func_yielded() -> void: class Base: - func _init(value :String): + func _init(_value :String): pass diff --git a/addons/gdUnit4/test/mocker/resources/AdvancedTestClass.gd b/addons/gdUnit4/test/mocker/resources/AdvancedTestClass.gd index 047b1b4e..b180fc4e 100644 --- a/addons/gdUnit4/test/mocker/resources/AdvancedTestClass.gd +++ b/addons/gdUnit4/test/mocker/resources/AdvancedTestClass.gd @@ -3,6 +3,7 @@ class_name AdvancedTestClass extends Resource class SoundData: + @warning_ignore("unused_private_class_variable") var _sample :String var _randomnes :float @@ -26,7 +27,7 @@ class AtmosphereData: _type = type _toxigen = toxigen - static func to_atmosphere(value :Dictionary) -> AtmosphereData: + static func to_atmosphere(_value :Dictionary) -> AtmosphereData: return null class Area4D extends Resource: @@ -35,7 +36,7 @@ class Area4D extends Resource: const ATMOSPHERE := 2 var _meta := Dictionary() - func _init(x :int, atmospere :AtmosphereData = null): + func _init(_x :int, atmospere :AtmosphereData = null): _meta[ATMOSPHERE] = atmospere func get_sound() -> SoundData: diff --git a/addons/gdUnit4/test/mocker/resources/ClassWithCustomFormattings.gd b/addons/gdUnit4/test/mocker/resources/ClassWithCustomFormattings.gd index 22a7fc12..11f8e02e 100644 --- a/addons/gdUnit4/test/mocker/resources/ClassWithCustomFormattings.gd +++ b/addons/gdUnit4/test/mocker/resources/ClassWithCustomFormattings.gd @@ -2,26 +2,35 @@ extends Object var _message +@warning_ignore("unused_parameter") func _init(message:String, path:String="", load_on_init:bool=false, set_auto_save:bool=false, set_network_sync:bool=false ) -> void: _message = message + +@warning_ignore("unused_parameter") func a1(set_name:String, path:String="", load_on_init:bool=false, set_auto_save:bool=false, set_network_sync:bool=false ) -> void: pass + +@warning_ignore("unused_parameter") func a2(set_name:String, path:String="", load_on_init:bool=false, set_auto_save:bool=false, set_network_sync:bool=false ) -> void: pass + +@warning_ignore("unused_parameter") func a3(set_name:String, path:String="", load_on_init:bool=false, set_auto_save:bool=false, set_network_sync:bool=false ) : pass + +@warning_ignore("unused_parameter") func a4(set_name:String, path:String="", load_on_init:bool=false, @@ -30,6 +39,8 @@ func a4(set_name:String, ): pass + +@warning_ignore("unused_parameter") func a5( value : Array, expected : String, diff --git a/addons/gdUnit4/test/mocker/resources/ClassWithDefaultBuildIntTypes.gd b/addons/gdUnit4/test/mocker/resources/ClassWithDefaultBuildIntTypes.gd index 32fa1946..f5c1e257 100644 --- a/addons/gdUnit4/test/mocker/resources/ClassWithDefaultBuildIntTypes.gd +++ b/addons/gdUnit4/test/mocker/resources/ClassWithDefaultBuildIntTypes.gd @@ -1,8 +1,8 @@ class_name ClassWithDefaultBuildIntTypes extends RefCounted -func foo(value :String, color := Color.RED): +func foo(_value :String, _color := Color.RED): pass -func bar(value :String, direction := Vector3.FORWARD, aabb := AABB()): +func bar(_value :String, _direction := Vector3.FORWARD, _aabb := AABB()): pass diff --git a/addons/gdUnit4/test/mocker/resources/ClassWithVariables.gd b/addons/gdUnit4/test/mocker/resources/ClassWithVariables.gd index a27b3dc4..bcc058b1 100644 --- a/addons/gdUnit4/test/mocker/resources/ClassWithVariables.gd +++ b/addons/gdUnit4/test/mocker/resources/ClassWithVariables.gd @@ -34,7 +34,7 @@ class ClassA: func foo()->String: return "" -var _data:= Dictionary() -func foo( value :int = T1): - var c = a + b + +func foo(_value :int = T1): + var _c = a + b pass diff --git a/addons/gdUnit4/test/mocker/resources/OverridenGetClassTestClass.gd b/addons/gdUnit4/test/mocker/resources/OverridenGetClassTestClass.gd index ce3cd07c..5ae8a1a6 100644 --- a/addons/gdUnit4/test/mocker/resources/OverridenGetClassTestClass.gd +++ b/addons/gdUnit4/test/mocker/resources/OverridenGetClassTestClass.gd @@ -2,6 +2,7 @@ class_name OverridenGetClassTestClass extends Resource +@warning_ignore("native_method_override") func get_class() -> String: return "OverridenGetClassTestClass" diff --git a/addons/gdUnit4/test/mocker/resources/TestPersion.gd b/addons/gdUnit4/test/mocker/resources/TestPersion.gd index b8debabd..70b3ffbb 100644 --- a/addons/gdUnit4/test/mocker/resources/TestPersion.gd +++ b/addons/gdUnit4/test/mocker/resources/TestPersion.gd @@ -8,13 +8,13 @@ class Address: var _street :String var _code :int - func _init(street :String,code :int): + func _init(street :String, code :int): _street = street _code = code -func _init(name :String,street :String,code :int): - _name = name +func _init(name_ :String, street :String, code :int): + _name = name_ _value = 1024 _address = Address.new(street, code) diff --git a/addons/gdUnit4/test/mocker/resources/scenes/Spell.gd b/addons/gdUnit4/test/mocker/resources/scenes/Spell.gd index cb9ba356..f803a76c 100644 --- a/addons/gdUnit4/test/mocker/resources/scenes/Spell.gd +++ b/addons/gdUnit4/test/mocker/resources/scenes/Spell.gd @@ -5,6 +5,7 @@ signal spell_explode const SPELL_LIVE_TIME = 1000 +@warning_ignore("unused_private_class_variable") var _spell_fired :bool = false var _spell_live_time :float = 0 var _spell_pos :Vector3 = Vector3.ZERO diff --git a/addons/gdUnit4/test/mocker/resources/scenes/TestScene.gd b/addons/gdUnit4/test/mocker/resources/scenes/TestScene.gd index d40afbd1..21757ba6 100644 --- a/addons/gdUnit4/test/mocker/resources/scenes/TestScene.gd +++ b/addons/gdUnit4/test/mocker/resources/scenes/TestScene.gd @@ -8,6 +8,7 @@ const COLOR_CYCLE := [Color.ROYAL_BLUE, Color.CHARTREUSE, Color.YELLOW_GREEN] @onready var _box2 = $VBoxContainer/PanelContainer/HBoxContainer/Panel2 @onready var _box3 = $VBoxContainer/PanelContainer/HBoxContainer/Panel3 +@warning_ignore("unused_private_class_variable") @export var _initial_color := Color.RED diff --git a/addons/gdUnit4/test/monitor/GodotGdErrorMonitorTest.gd b/addons/gdUnit4/test/monitor/GodotGdErrorMonitorTest.gd index f1563623..9c6b25e5 100644 --- a/addons/gdUnit4/test/monitor/GodotGdErrorMonitorTest.gd +++ b/addons/gdUnit4/test/monitor/GodotGdErrorMonitorTest.gd @@ -19,12 +19,12 @@ const script_error = """ func test_parse_script_error_line_number() -> void: - var line := GodotGdErrorMonitor.new()._parse_error_line_number(script_error.dedent()) + var line := GodotGdErrorMonitor._parse_error_line_number(script_error.dedent()) assert_int(line).is_equal(22) func test_parse_push_error_line_number() -> void: - var line := GodotGdErrorMonitor.new()._parse_error_line_number(error_report.dedent()) + var line := GodotGdErrorMonitor._parse_error_line_number(error_report.dedent()) assert_int(line).is_equal(-1) diff --git a/addons/gdUnit4/test/resources/issues/gd-166/issue.gd b/addons/gdUnit4/test/resources/issues/gd-166/issue.gd index 55da45f9..1123f6bc 100644 --- a/addons/gdUnit4/test/resources/issues/gd-166/issue.gd +++ b/addons/gdUnit4/test/resources/issues/gd-166/issue.gd @@ -11,9 +11,11 @@ var type = -1 : var type_name + func _set_type(t:int): type = t -func _set_type_name(type :int): - type_name = Type.to_str(type) + +func _set_type_name(type_ :int): + type_name = Type.to_str(type_) print("type was set to %s" % type_name) diff --git a/addons/gdUnit4/test/spy/GdUnitSpyBuilderTest.gd b/addons/gdUnit4/test/spy/GdUnitSpyBuilderTest.gd index 81e12bfa..5a32a53e 100644 --- a/addons/gdUnit4/test/spy/GdUnitSpyBuilderTest.gd +++ b/addons/gdUnit4/test/spy/GdUnitSpyBuilderTest.gd @@ -6,7 +6,7 @@ extends GdUnitTestSuite const __source = 'res://addons/gdUnit4/src/spy/GdUnitSpyBuilder.gd' # helper to get function descriptor -static func get_function_description(clazz_name :String, method_name :String) -> GdFunctionDescriptor: +func get_function_description(clazz_name :String, method_name :String) -> GdFunctionDescriptor: var method_list :Array = ClassDB.class_get_method_list(clazz_name) for method_descriptor in method_list: if method_descriptor["name"] == method_name: @@ -32,6 +32,7 @@ func test_double_return_typed_function_without_arg() -> void: var fd := get_function_description("Object", "get_class") var expected := [ '@warning_ignore("native_method_override")', + '@warning_ignore("shadowed_variable")', 'func get_class() -> String:', ' var args :Array = ["get_class", ]', ' ', @@ -55,6 +56,7 @@ func test_double_return_typed_function_with_args() -> void: var fd := get_function_description("Object", "is_connected") var expected := [ '@warning_ignore("native_method_override")', + '@warning_ignore("shadowed_variable")', 'func is_connected(signal_, callable_) -> bool:', ' var args :Array = ["is_connected", signal_, callable_]', ' ', @@ -78,6 +80,7 @@ func test_double_return_void_function_with_args() -> void: var fd := get_function_description("Object", "disconnect") var expected := [ '@warning_ignore("native_method_override")', + '@warning_ignore("shadowed_variable")', 'func disconnect(signal_, callable_) -> void:', ' var args :Array = ["disconnect", signal_, callable_]', ' ', @@ -100,6 +103,7 @@ func test_double_return_void_function_without_args() -> void: var fd := get_function_description("Object", "free") var expected := [ '@warning_ignore("native_method_override")', + '@warning_ignore("shadowed_variable")', 'func free() -> void:', ' var args :Array = ["free", ]', ' ', @@ -122,6 +126,7 @@ func test_double_return_typed_function_with_args_and_varargs() -> void: var fd := get_function_description("Object", "emit_signal") var expected := [ '@warning_ignore("native_method_override")', + '@warning_ignore("shadowed_variable")', 'func emit_signal(signal_, vararg0_="__null__", vararg1_="__null__", vararg2_="__null__", vararg3_="__null__", vararg4_="__null__", vararg5_="__null__", vararg6_="__null__", vararg7_="__null__", vararg8_="__null__", vararg9_="__null__") -> Error:', ' var varargs :Array = __filter_vargs([vararg0_, vararg1_, vararg2_, vararg3_, vararg4_, vararg5_, vararg6_, vararg7_, vararg8_, vararg9_])', ' var args :Array = ["emit_signal", signal_] + varargs', @@ -143,6 +148,7 @@ func test_double_return_void_function_only_varargs() -> void: # void bar(s...) vararg var fd := GdFunctionDescriptor.new( "bar", 23, false, false, false, TYPE_NIL, "void", [], GdFunctionDescriptor._build_varargs(true)) var expected := [ + '@warning_ignore("shadowed_variable")', 'func bar(vararg0_="__null__", vararg1_="__null__", vararg2_="__null__", vararg3_="__null__", vararg4_="__null__", vararg5_="__null__", vararg6_="__null__", vararg7_="__null__", vararg8_="__null__", vararg9_="__null__") -> void:', ' var varargs :Array = __filter_vargs([vararg0_, vararg1_, vararg2_, vararg3_, vararg4_, vararg5_, vararg6_, vararg7_, vararg8_, vararg9_])', ' var args :Array = ["bar", ] + varargs', @@ -164,6 +170,7 @@ func test_double_return_typed_function_only_varargs() -> void: # String bar(s...) vararg var fd := GdFunctionDescriptor.new( "bar", 23, false, false, false, TYPE_STRING, "String", [], GdFunctionDescriptor._build_varargs(true)) var expected := [ + '@warning_ignore("shadowed_variable")', 'func bar(vararg0_="__null__", vararg1_="__null__", vararg2_="__null__", vararg3_="__null__", vararg4_="__null__", vararg5_="__null__", vararg6_="__null__", vararg7_="__null__", vararg8_="__null__", vararg9_="__null__") -> String:', ' var varargs :Array = __filter_vargs([vararg0_, vararg1_, vararg2_, vararg3_, vararg4_, vararg5_, vararg6_, vararg7_, vararg8_, vararg9_])', ' var args :Array = ["bar", ] + varargs', @@ -185,6 +192,7 @@ func test_double_static_return_void_function_without_args() -> void: # void foo() var fd := GdFunctionDescriptor.new( "foo", 23, false, true, false, TYPE_NIL, "", []) var expected := [ + '@warning_ignore("shadowed_variable")', 'static func foo() -> void:', ' var args :Array = ["foo", ]', ' ', @@ -208,6 +216,7 @@ func test_double_static_return_void_function_with_args() -> void: GdFunctionArgument.new("arg2", TYPE_STRING, '"default"') ]) var expected := [ + '@warning_ignore("shadowed_variable")', 'static func foo(arg1, arg2="default") -> void:', ' var args :Array = ["foo", arg1, arg2]', ' ', @@ -232,6 +241,7 @@ func test_double_static_script_function_with_args_return_bool() -> void: GdFunctionArgument.new("arg2", TYPE_STRING, '"default"') ]) var expected := [ + '@warning_ignore("shadowed_variable")', 'static func foo(arg1, arg2="default") -> bool:', ' var args :Array = ["foo", arg1, arg2]', ' ', @@ -255,6 +265,7 @@ func test_double_virtual_return_void_function_with_arg() -> void: var fd := get_function_description("Node", "_input") var expected := [ '@warning_ignore("native_method_override")', + '@warning_ignore("shadowed_variable")', 'func _input(event_) -> void:', ' var args :Array = ["_input", event_]', ' ', @@ -277,6 +288,7 @@ func test_double_virtual_return_void_function_without_arg() -> void: var fd := get_function_description("Node", "_ready") var expected := [ '@warning_ignore("native_method_override")', + '@warning_ignore("shadowed_variable")', 'func _ready() -> void:', ' var args :Array = ["_ready", ]', ' ', @@ -300,6 +312,6 @@ class NodeWithOutVirtualFunc extends Node: #func _input(event :InputEvent) -> void: func test_spy_on_script_respect_virtual_functions(): - var spy = auto_free(GdUnitSpyBuilder.spy_on_script(auto_free(NodeWithOutVirtualFunc.new()), [], true).new()) - assert_that(spy.has_method("_ready")).is_true() - assert_that(spy.has_method("_input")).is_false() + var do_spy = auto_free(GdUnitSpyBuilder.spy_on_script(auto_free(NodeWithOutVirtualFunc.new()), [], true).new()) + assert_that(do_spy.has_method("_ready")).is_true() + assert_that(do_spy.has_method("_input")).is_false() diff --git a/addons/gdUnit4/test/spy/GdUnitSpyTest.gd b/addons/gdUnit4/test/spy/GdUnitSpyTest.gd index 887ed233..6fa7daa4 100644 --- a/addons/gdUnit4/test/spy/GdUnitSpyTest.gd +++ b/addons/gdUnit4/test/spy/GdUnitSpyTest.gd @@ -115,11 +115,11 @@ func test_spy_on_custom_class(): # GD-291 https://github.com/MikeSchulze/gdUnit4/issues/291 func test_spy_class_with_custom_formattings() -> void: var resource = load("res://addons/gdUnit4/test/mocker/resources/ClassWithCustomFormattings.gd") - var spy = spy(auto_free(resource.new("test"))) - spy.a1("set_name", "", true) - verify(spy, 1).a1("set_name", "", true) - verify_no_more_interactions(spy) - verify_no_interactions(spy, GdUnitAssert.EXPECT_FAIL) + var do_spy = spy(auto_free(resource.new("test"))) + do_spy.a1("set_name", "", true) + verify(do_spy, 1).a1("set_name", "", true) + verify_no_more_interactions(do_spy) + verify_no_interactions(do_spy, GdUnitAssert.EXPECT_FAIL) assert_int(GdAssertReports.get_last_error_line_number()).is_equal(122) @@ -384,12 +384,12 @@ func test_spy_snake_case_named_class_by_resource_path(): func test_spy_snake_case_named_class_by_class(): - var spy = spy(snake_case_class_name.new()) - assert_object(spy).is_not_null() + var do_spy = spy(snake_case_class_name.new()) + assert_object(do_spy).is_not_null() - spy.custom_func() - verify(spy).custom_func() - verify_no_more_interactions(spy) + do_spy.custom_func() + verify(do_spy).custom_func() + verify_no_more_interactions(do_spy) # try checked Godot class var spy_tcp_server = spy(TCPServer.new()) diff --git a/addons/gdUnit4/test/ui/parts/InspectorTreeMainPanelTest.gd b/addons/gdUnit4/test/ui/parts/InspectorTreeMainPanelTest.gd index a7d17a9e..39a15700 100644 --- a/addons/gdUnit4/test/ui/parts/InspectorTreeMainPanelTest.gd +++ b/addons/gdUnit4/test/ui/parts/InspectorTreeMainPanelTest.gd @@ -29,7 +29,7 @@ func after_test(): _inspector.free() -static func toDto(test_suite :Node) -> GdUnitTestSuiteDto: +func toDto(test_suite :Node) -> GdUnitTestSuiteDto: var dto := GdUnitTestSuiteDto.new() return dto.deserialize(dto.serialize(test_suite)) as GdUnitTestSuiteDto @@ -59,8 +59,8 @@ func mark_as_failure(inspector, test_cases :Array) -> void: item = item.get_next() parent = parent.get_next() -func get_item_state(parent :TreeItem, name :String) -> int: - var item = _inspector._find_by_name(parent, name) +func get_item_state(parent :TreeItem, item_name :String) -> int: + var item = _inspector._find_by_name(parent, item_name) return item.get_meta(_inspector.META_GDUNIT_STATE) func test_collect_failures_and_errors() -> void: diff --git a/addons/gdUnit4/test/update/GdUnitUpdateTest.gd b/addons/gdUnit4/test/update/GdUnitUpdateTest.gd index 8f539c19..4dfff500 100644 --- a/addons/gdUnit4/test/update/GdUnitUpdateTest.gd +++ b/addons/gdUnit4/test/update/GdUnitUpdateTest.gd @@ -11,7 +11,7 @@ func after_test(): func test__prepare_update_deletes_old_content() -> void: - var update :GdUnitUpdate = auto_free(GdUnitUpdate.new()) + var _update :GdUnitUpdate = auto_free(GdUnitUpdate.new()) diff --git a/addons/gdUnit4/test/update/bbcodeView.gd b/addons/gdUnit4/test/update/bbcodeView.gd index 07030cff..19de9544 100644 --- a/addons/gdUnit4/test/update/bbcodeView.gd +++ b/addons/gdUnit4/test/update/bbcodeView.gd @@ -42,5 +42,5 @@ func _on_RichTextLabel_meta_hover_started(meta :String): _text.set_tooltip(properties.get("tool_tip")) -func _on_RichTextLabel_meta_hover_ended(meta :String): +func _on_RichTextLabel_meta_hover_ended(_meta :String): _text.set_tooltip("")