diff --git a/.gdlintrc b/.gdlintrc index 9e882526..ce5a2f67 100644 --- a/.gdlintrc +++ b/.gdlintrc @@ -1,18 +1,18 @@ class-definitions-order: -- tools -- classnames -- extends -- docstrings -- signals -- enums -- consts -- exports -- pubvars -- prvvars -- onreadypubvars -- onreadyprvvars -- staticvars -- others + - tools + - classnames + - extends + - docstrings + - signals + - enums + - consts + - exports + - pubvars + - prvvars + - onreadypubvars + - onreadyprvvars + - staticvars + - others class-load-variable-name: (([A-Z][a-z0-9]*)+|_?[a-z][a-z0-9]*(_[a-z0-9]+)*) class-name: ([A-Z][a-z0-9]*)+ class-variable-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)* @@ -20,7 +20,7 @@ comparison-with-itself: null constant-name: _?[A-Z][A-Z0-9]*(_[A-Z0-9]+)* disable: [] duplicated-load: null -enum-element-name: '[A-Z][A-Z0-9]*(_[A-Z0-9]+)*' +enum-element-name: "[A-Z][A-Z0-9]*(_[A-Z0-9]+)*" enum-name: ([A-Z][a-z0-9]*)+ excluded_directories: !!set .git: null @@ -29,18 +29,18 @@ function-argument-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)* function-arguments-number: 10 function-name: (_on_([A-Z][a-z0-9]*)+(_[a-z0-9]+)*|_?[a-z][a-z0-9]*(_[a-z0-9]+)*) function-preload-variable-name: ([A-Z][a-z0-9]*)+ -function-variable-name: '[a-z][a-z0-9]*(_[a-z0-9]+)*' +function-variable-name: "[a-z][a-z0-9]*(_[a-z0-9]+)*" load-constant-name: (([A-Z][a-z0-9]*)+|_?[A-Z][A-Z0-9]*(_[A-Z0-9]+)*) loop-variable-name: _?[a-z][a-z0-9]*(_[a-z0-9]+)* max-file-lines: 1000 max-line-length: 140 -max-public-methods: 20 +max-public-methods: 40 max-returns: 6 mixed-tabs-and-spaces: null no-elif-return: null no-else-return: null private-method-call: null -signal-name: '[a-z][a-z0-9]*(_[a-z0-9]+)*' +signal-name: "[a-z][a-z0-9]*(_[a-z0-9]+)*" sub-class-name: _?([A-Z][a-z0-9]*)+ tab-characters: 1 trailing-whitespace: null diff --git a/.github/workflows/gdlint.yml b/.github/workflows/gdlint.yml index 96e53b05..29047599 100644 --- a/.github/workflows/gdlint.yml +++ b/.github/workflows/gdlint.yml @@ -7,14 +7,13 @@ on: os: required: false type: string - default: 'ubuntu-22.04' + default: "ubuntu-22.04" workflow_dispatch: inputs: os: required: false type: string - default: 'ubuntu-22.04' - + default: "ubuntu-22.04" jobs: gdlint: @@ -37,6 +36,7 @@ jobs: run: | mkdir -p reports/gdlint/ gdlint addons/gdUnit4/bin/ | tee reports/gdlint/gdlint.txt + gdlint addons/gdUnit4/src/asserts | tee reports/gdlint/gdlint_asserts.txt - name: Upload GDLint Report if: failure() diff --git a/addons/gdUnit4/src/GdUnitAssert.gd b/addons/gdUnit4/src/GdUnitAssert.gd index af3b86c5..1674d26c 100644 --- a/addons/gdUnit4/src/GdUnitAssert.gd +++ b/addons/gdUnit4/src/GdUnitAssert.gd @@ -3,33 +3,6 @@ class_name GdUnitAssert extends RefCounted -# Scans the current stack trace for the root cause to extract the line number -static func _get_line_number() -> int: - var stack_trace := get_stack() - if stack_trace == null or stack_trace.is_empty(): - return -1 - for index in stack_trace.size(): - var stack_info :Dictionary = stack_trace[index] - var function :String = stack_info.get("function") - # we catch helper asserts to skip over to return the correct line number - if function.begins_with("assert_"): - continue - if function.begins_with("test_"): - return stack_info.get("line") - var source :String = stack_info.get("source") - if source.is_empty() \ - or source.begins_with("user://") \ - or source.ends_with("GdUnitAssert.gd") \ - or source.ends_with("AssertImpl.gd") \ - or source.ends_with("GdUnitTestSuite.gd") \ - or source.ends_with("GdUnitSceneRunnerImpl.gd") \ - or source.ends_with("GdUnitObjectInteractions.gd") \ - or source.ends_with("GdUnitAwaiter.gd"): - continue - return stack_info.get("line") - return -1 - - ## Verifies that the current value is null. func is_null(): return self diff --git a/addons/gdUnit4/src/GdUnitAwaiter.gd b/addons/gdUnit4/src/GdUnitAwaiter.gd index c1fc2ccf..cc6bf3fb 100644 --- a/addons/gdUnit4/src/GdUnitAwaiter.gd +++ b/addons/gdUnit4/src/GdUnitAwaiter.gd @@ -11,7 +11,7 @@ const GdUnitAssertImpl = preload("res://addons/gdUnit4/src/asserts/GdUnitAssertI # timeout: the timeout in ms, default is set to 2000ms func await_signal_on(source :Object, signal_name :String, args :Array = [], timeout_millis :int = 2000) -> Variant: # fail fast if the given source instance invalid - var line_number := GdUnitAssert._get_line_number() + var line_number := GdUnitAssertions.get_line_number() if not is_instance_valid(source): GdUnitAssertImpl.new(signal_name)\ .report_error(GdAssertMessages.error_await_signal_on_invalid_instance(source, signal_name, args), line_number) @@ -35,7 +35,7 @@ func await_signal_on(source :Object, signal_name :String, args :Array = [], time # args: the expected signal arguments as an array # timeout: the timeout in ms, default is set to 2000ms func await_signal_idle_frames(source :Object, signal_name :String, args :Array = [], timeout_millis :int = 2000) -> Variant: - var line_number := GdUnitAssert._get_line_number() + var line_number := GdUnitAssertions.get_line_number() # fail fast if the given source instance invalid if not is_instance_valid(source): GdUnitAssertImpl.new(signal_name)\ diff --git a/addons/gdUnit4/src/asserts/CallBackValueProvider.gd b/addons/gdUnit4/src/asserts/CallBackValueProvider.gd index 0b4a72cf..27242e80 100644 --- a/addons/gdUnit4/src/asserts/CallBackValueProvider.gd +++ b/addons/gdUnit4/src/asserts/CallBackValueProvider.gd @@ -1,5 +1,5 @@ # a value provider unsing a callback to get `next` value from a certain function -class_name CallBackValueProvider +class_name CallBackValueProvider extends ValueProvider var _cb :Callable diff --git a/addons/gdUnit4/src/asserts/DefaultValueProvider.gd b/addons/gdUnit4/src/asserts/DefaultValueProvider.gd index aa35d8f0..036a482d 100644 --- a/addons/gdUnit4/src/asserts/DefaultValueProvider.gd +++ b/addons/gdUnit4/src/asserts/DefaultValueProvider.gd @@ -1,11 +1,12 @@ # default value provider, simple returns the initial value -class_name DefaultValueProvider +class_name DefaultValueProvider extends ValueProvider var _value func _init(value): _value = value - + + func get_value(): return _value diff --git a/addons/gdUnit4/src/asserts/GdAssertMessages.gd b/addons/gdUnit4/src/asserts/GdAssertMessages.gd index 42a8ceb5..bb54e605 100644 --- a/addons/gdUnit4/src/asserts/GdAssertMessages.gd +++ b/addons/gdUnit4/src/asserts/GdAssertMessages.gd @@ -22,28 +22,30 @@ static func _format_dict(value :Dictionary) -> String: static func input_event_as_text(event :InputEvent) -> String: var text := "" if event is InputEventKey: - text += "InputEventKey : key='%s', pressed=%s, keycode=%d, physical_keycode=%s" % [event.as_text(), event.pressed, event.keycode, event.physical_keycode] + text += "InputEventKey : key='%s', pressed=%s, keycode=%d, physical_keycode=%s" % [ + event.as_text(), event.pressed, event.keycode, event.physical_keycode] else: text += event.as_text() if event is InputEventMouse: text += ", global_position %s" % event.global_position if event is InputEventWithModifiers: - text += ", shift=%s, alt=%s, control=%s, meta=%s, command=%s" % [event.shift_pressed, event.alt_pressed, event.ctrl_pressed, event.meta_pressed, event.command_or_control_autoremap] + text += ", shift=%s, alt=%s, control=%s, meta=%s, command=%s" % [ + event.shift_pressed, event.alt_pressed, event.ctrl_pressed, event.meta_pressed, event.command_or_control_autoremap] return text static func _colored_string_div(characters :String) -> String: - return _colored_array_div(characters.to_ascii_buffer()) + return colored_array_div(characters.to_ascii_buffer()) -static func _colored_array_div(characters :PackedByteArray) -> String: +static func colored_array_div(characters :PackedByteArray) -> String: if characters.is_empty(): return "" var result = PackedByteArray() var index = 0 var missing_chars := PackedByteArray() var additional_chars := PackedByteArray() - + while index < characters.size(): var character := characters[index] match character: @@ -62,7 +64,7 @@ static func _colored_array_div(characters :PackedByteArray) -> String: additional_chars = PackedByteArray() result.append(character) index += 1 - + result.append_array(format_chars(missing_chars, SUB_COLOR)) result.append_array(format_chars(additional_chars, ADD_COLOR)) return result.get_string_from_utf8() @@ -106,7 +108,7 @@ static func _colored_value(value, _delimiter ="\n") -> String: if value is InputEvent: return "[color=%s]<%s>[/color]" % [VALUE_COLOR, input_event_as_text(value)] if value.has_method("_to_string"): - return "[color=%s]<%s>[/color]" % [VALUE_COLOR, value._to_string()] + return "[color=%s]<%s>[/color]" % [VALUE_COLOR, str(value)] return "[color=%s]<%s>[/color]" % [VALUE_COLOR, value.get_class()] TYPE_DICTIONARY: return "'[color=%s]%s[/color]'" % [VALUE_COLOR, _format_dict(value)] @@ -146,9 +148,9 @@ static func orphan_detected_on_test(count :int): static func fuzzer_interuped(iterations: int, error: String) -> String: return "%s %s %s\n %s" % [ - _error("Found an error after"), - _colored_value(iterations + 1), - _error("test iterations"), + _error("Found an error after"), + _colored_value(iterations + 1), + _error("test iterations"), error] @@ -156,6 +158,7 @@ static func test_timeout(timeout :int) -> String: return "%s\n %s" % [_error("Timeout !"), _colored_value("Test timed out after %s" % LocalTime.elapsed(timeout))] +# gdlint:disable = mixed-tabs-and-spaces static func test_suite_skipped(hint :String, skip_count) -> String: return """ %s @@ -201,7 +204,8 @@ static func error_not_equal(current, expected) -> String: static func error_not_equal_case_insensetiv(current, expected) -> String: - return "%s\n %s\n not equal to (case insensitiv)\n %s" % [_error("Expecting:"), _colored_value(expected, true), _colored_value(current, true)] + return "%s\n %s\n not equal to (case insensitiv)\n %s" % [ + _error("Expecting:"), _colored_value(expected, true), _colored_value(current, true)] static func error_is_empty(current) -> String: @@ -217,7 +221,7 @@ static func error_is_same(current, expected) -> String: @warning_ignore("unused_parameter") -static func error_not_same(current, expected) -> String: +static func error_not_same(_current, expected) -> String: return "%s\n %s" % [_error("Expecting not same:"), _colored_value(expected)] @@ -285,9 +289,11 @@ static func error_is_value(operation, current, expected, expected2=null) -> Stri Comparator.GREATER_EQUAL: return "%s\n %s but was '%s'" % [_error("Expecting to be greater than or equal:"), _colored_value(expected), _nerror(current)] Comparator.BETWEEN_EQUAL: - return "%s\n %s\n in range between\n %s <> %s" % [_error("Expecting:"), _colored_value(current), _colored_value(expected), _colored_value(expected2)] + return "%s\n %s\n in range between\n %s <> %s" % [ + _error("Expecting:"), _colored_value(current), _colored_value(expected), _colored_value(expected2)] Comparator.NOT_BETWEEN_EQUAL: - return "%s\n %s\n not in range between\n %s <> %s" % [_error("Expecting:"), _colored_value(current), _colored_value(expected), _colored_value(expected2)] + return "%s\n %s\n not in range between\n %s <> %s" % [ + _error("Expecting:"), _colored_value(current), _colored_value(expected), _colored_value(expected2)] return "TODO create expected message" @@ -332,15 +338,23 @@ static func error_has_length(current, expected: int, compare_operator) -> String var current_length = current.length() if current != null else null match compare_operator: Comparator.EQUAL: - return "%s\n %s but was '%s' in\n %s" % [_error("Expecting size:"), _colored_value(expected), _nerror(current_length), _colored_value(current)] + return "%s\n %s but was '%s' in\n %s" % [ + _error("Expecting size:"), _colored_value(expected), _nerror(current_length), _colored_value(current)] Comparator.LESS_THAN: - return "%s\n %s but was '%s' in\n %s" % [_error("Expecting size to be less than:"), _colored_value(expected), _nerror(current_length), _colored_value(current)] + return "%s\n %s but was '%s' in\n %s" % [ + _error("Expecting size to be less than:"), _colored_value(expected), _nerror(current_length), _colored_value(current)] Comparator.LESS_EQUAL: - return "%s\n %s but was '%s' in\n %s" % [_error("Expecting size to be less than or equal:"), _colored_value(expected), _nerror(current_length), _colored_value(current)] + return "%s\n %s but was '%s' in\n %s" % [ + _error("Expecting size to be less than or equal:"), _colored_value(expected), + _nerror(current_length), _colored_value(current)] Comparator.GREATER_THAN: - return "%s\n %s but was '%s' in\n %s" % [_error("Expecting size to be greater than:"), _colored_value(expected), _nerror(current_length), _colored_value(current)] + return "%s\n %s but was '%s' in\n %s" % [ + _error("Expecting size to be greater than:"), _colored_value(expected), + _nerror(current_length), _colored_value(current)] Comparator.GREATER_EQUAL: - return "%s\n %s but was '%s' in\n %s" % [_error("Expecting size to be greater than or equal:"), _colored_value(expected), _nerror(current_length), _colored_value(current)] + return "%s\n %s but was '%s' in\n %s" % [ + _error("Expecting size to be greater than or equal:"), _colored_value(expected), + _nerror(current_length), _colored_value(current)] return "TODO create expected message" @@ -348,7 +362,8 @@ static func error_has_length(current, expected: int, compare_operator) -> String static func error_arr_contains(current, expected :Array, not_expect :Array, not_found :Array, by_reference :bool) -> String: var failure_message = "Expecting contains SAME elements:" if by_reference else "Expecting contains elements:" - var error := "%s\n %s\n do contains (in any order)\n %s" % [_error(failure_message), _colored_value(current, ", "), _colored_value(expected, ", ")] + var error := "%s\n %s\n do contains (in any order)\n %s" % [ + _error(failure_message), _colored_value(current, ", "), _colored_value(expected, ", ")] if not not_expect.is_empty(): error += "\nbut some elements where not expected:\n %s" % _colored_value(not_expect, ", ") if not not_found.is_empty(): @@ -358,12 +373,17 @@ static func error_arr_contains(current, expected :Array, not_expect :Array, not_ static func error_arr_contains_exactly(current, expected, not_expect, not_found, compare_mode :GdObjects.COMPARE_MODE) -> String: - var failure_message = "Expecting contains exactly elements:" if compare_mode == GdObjects.COMPARE_MODE.PARAMETER_DEEP_TEST else "Expecting contains SAME exactly elements:" + var failure_message = ( + "Expecting contains exactly elements:" if compare_mode == GdObjects.COMPARE_MODE.PARAMETER_DEEP_TEST + else "Expecting contains SAME exactly elements:" + ) if not_expect.is_empty() and not_found.is_empty(): var diff := _find_first_diff(current, expected) - return "%s\n %s\n do contains (in same order)\n %s\n but has different order %s" % [_error(failure_message), _colored_value(current, ", "), _colored_value(expected, ", "), diff] - - var error := "%s\n %s\n do contains (in same order)\n %s" % [_error(failure_message), _colored_value(current, ", "), _colored_value(expected, ", ")] + return "%s\n %s\n do contains (in same order)\n %s\n but has different order %s" % [ + _error(failure_message), _colored_value(current, ", "), _colored_value(expected, ", "), diff] + + var error := "%s\n %s\n do contains (in same order)\n %s" % [ + _error(failure_message), _colored_value(current, ", "), _colored_value(expected, ", ")] if not not_expect.is_empty(): error += "\nbut some elements where not expected:\n %s" % _colored_value(not_expect, ", ") if not not_found.is_empty(): @@ -372,9 +392,19 @@ static func error_arr_contains_exactly(current, expected, not_expect, not_found, return error -static func error_arr_contains_exactly_in_any_order(current, expected :Array, not_expect :Array, not_found :Array, compare_mode :GdObjects.COMPARE_MODE) -> String: - var failure_message = "Expecting contains exactly elements:" if compare_mode == GdObjects.COMPARE_MODE.PARAMETER_DEEP_TEST else "Expecting contains SAME exactly elements:" - var error := "%s\n %s\n do contains exactly (in any order)\n %s" % [_error(failure_message), _colored_value(current, ", "), _colored_value(expected, ", ")] +static func error_arr_contains_exactly_in_any_order( + current, + expected :Array, + not_expect :Array, + not_found :Array, + compare_mode :GdObjects.COMPARE_MODE) -> String: + + var failure_message = ( + "Expecting contains exactly elements:" if compare_mode == GdObjects.COMPARE_MODE.PARAMETER_DEEP_TEST + else "Expecting contains SAME exactly elements:" + ) + var error := "%s\n %s\n do contains exactly (in any order)\n %s" % [ + _error(failure_message), _colored_value(current, ", "), _colored_value(expected, ", ")] if not not_expect.is_empty(): error += "\nbut some elements where not expected:\n %s" % _colored_value(not_expect, ", ") if not not_found.is_empty(): @@ -385,7 +415,8 @@ static func error_arr_contains_exactly_in_any_order(current, expected :Array, no static func error_arr_not_contains(current :Array, expected :Array, found :Array, compare_mode :GdObjects.COMPARE_MODE) -> String: var failure_message = "Expecting:" if compare_mode == GdObjects.COMPARE_MODE.PARAMETER_DEEP_TEST else "Expecting SAME:" - var error := "%s\n %s\n do not contains\n %s" % [_error(failure_message), _colored_value(current, ", "), _colored_value(expected, ", ")] + var error := "%s\n %s\n do not contains\n %s" % [ + _error(failure_message), _colored_value(current, ", "), _colored_value(expected, ", ")] if not found.is_empty(): error += "\n but found elements:\n %s" % _colored_value(found, ", ") return error @@ -393,18 +424,30 @@ static func error_arr_not_contains(current :Array, expected :Array, found :Array # - DictionaryAssert specific messages ---------------------------------------------- static func error_contains_keys(current :Array, expected :Array, keys_not_found :Array, compare_mode :GdObjects.COMPARE_MODE) -> String: - var failure := "Expecting contains keys:" if compare_mode == GdObjects.COMPARE_MODE.PARAMETER_DEEP_TEST else "Expecting contains SAME keys:" - return "%s\n %s\n to contains:\n %s\n but can't find key's:\n %s" % [_error(failure), _colored_value(current, ", "), _colored_value(expected, ", "), _colored_value(keys_not_found, ", ")] + var failure := ( + "Expecting contains keys:" if compare_mode == GdObjects.COMPARE_MODE.PARAMETER_DEEP_TEST + else "Expecting contains SAME keys:" + ) + return "%s\n %s\n to contains:\n %s\n but can't find key's:\n %s" % [ + _error(failure), _colored_value(current, ", "), _colored_value(expected, ", "), _colored_value(keys_not_found, ", ")] static func error_not_contains_keys(current :Array, expected :Array, keys_not_found :Array, compare_mode :GdObjects.COMPARE_MODE) -> String: - var failure := "Expecting NOT contains keys:" if compare_mode == GdObjects.COMPARE_MODE.PARAMETER_DEEP_TEST else "Expecting NOT contains SAME keys" - return "%s\n %s\n do not contains:\n %s\n but contains key's:\n %s" % [_error(failure), _colored_value(current, ", "), _colored_value(expected, ", "), _colored_value(keys_not_found, ", ")] + var failure := ( + "Expecting NOT contains keys:" if compare_mode == GdObjects.COMPARE_MODE.PARAMETER_DEEP_TEST + else "Expecting NOT contains SAME keys" + ) + return "%s\n %s\n do not contains:\n %s\n but contains key's:\n %s" % [ + _error(failure), _colored_value(current, ", "), _colored_value(expected, ", "), _colored_value(keys_not_found, ", ")] static func error_contains_key_value(key, value, current_value, compare_mode :GdObjects.COMPARE_MODE) -> String: - var failure := "Expecting contains key and value:" if compare_mode == GdObjects.COMPARE_MODE.PARAMETER_DEEP_TEST else "Expecting contains SAME key and value:" - return "%s\n %s : %s\n but contains\n %s : %s" % [_error(failure), _colored_value(key), _colored_value(value), _colored_value(key), _colored_value(current_value)] + var failure := ( + "Expecting contains key and value:" if compare_mode == GdObjects.COMPARE_MODE.PARAMETER_DEEP_TEST + else "Expecting contains SAME key and value:" + ) + return "%s\n %s : %s\n but contains\n %s : %s" % [ + _error(failure), _colored_value(key), _colored_value(value), _colored_value(key), _colored_value(current_value)] # - ResultAssert specific errors ---------------------------------------------------- @@ -454,17 +497,22 @@ static func error_interrupted(func_name :String, expected, elapsed :String) -> S static func error_wait_signal(signal_name :String, args :Array, elapsed :String) -> String: if args.is_empty(): - return "%s %s but timed out after %s" % [_error("Expecting emit signal:"), _colored_value(signal_name + "()"), elapsed] - return "%s %s but timed out after %s" % [_error("Expecting emit signal:"), _colored_value(signal_name + "(" + str(args) + ")"), elapsed] + return "%s %s but timed out after %s" % [ + _error("Expecting emit signal:"), _colored_value(signal_name + "()"), elapsed] + return "%s %s but timed out after %s" % [ + _error("Expecting emit signal:"), _colored_value(signal_name + "(" + str(args) + ")"), elapsed] static func error_signal_emitted(signal_name :String, args :Array, elapsed :String) -> String: if args.is_empty(): - return "%s %s but is emitted after %s" % [_error("Expecting do not emit signal:"), _colored_value(signal_name + "()"), elapsed] - return "%s %s but is emitted after %s" % [_error("Expecting do not emit signal:"), _colored_value(signal_name + "(" + str(args) + ")"), elapsed] + return "%s %s but is emitted after %s" % [ + _error("Expecting do not emit signal:"), _colored_value(signal_name + "()"), elapsed] + return "%s %s but is emitted after %s" % [ + _error("Expecting do not emit signal:"), _colored_value(signal_name + "(" + str(args) + ")"), elapsed] static func error_await_signal_on_invalid_instance(source, signal_name :String, args :Array) -> String: - return "%s\n await_signal_on(%s, %s, %s)" % [_error("Invalid source! Can't await on signal:"), _colored_value(source), signal_name, args] + return "%s\n await_signal_on(%s, %s, %s)" % [ + _error("Invalid source! Can't await on signal:"), _colored_value(source), signal_name, args] static func result_type(type :int) -> String: match type: @@ -499,7 +547,8 @@ static func error_validate_interactions(current_interactions :Dictionary, expect var times :int = current_interactions[args] interactions.append(_format_arguments(args, times)) var expected_interaction := _format_arguments(expected_interactions.keys()[0], expected_interactions.values()[0]) - return "%s\n%s\n%s\n%s" % [_error("Expecting interaction on:"), expected_interaction, _error("But found interactions on:"), "\n".join(interactions)] + return "%s\n%s\n%s\n%s" % [ + _error("Expecting interaction on:"), expected_interaction, _error("But found interactions on:"), "\n".join(interactions)] static func _format_arguments(args :Array, times :int) -> String: @@ -545,7 +594,8 @@ static func format_chars(characters :PackedByteArray, type :Color) -> PackedByte if characters.size() == 0:# or characters[0] == 10: return characters var result := PackedByteArray() - var message := "[bgcolor=#%s][color=with]%s[/color][/bgcolor]" % [type.to_html(), characters.get_string_from_utf8().replace("\n", "")] + var message := "[bgcolor=#%s][color=with]%s[/color][/bgcolor]" % [ + type.to_html(), characters.get_string_from_utf8().replace("\n", "")] result.append_array(message.to_utf8_buffer()) return result diff --git a/addons/gdUnit4/src/asserts/GdUnitArrayAssertImpl.gd b/addons/gdUnit4/src/asserts/GdUnitArrayAssertImpl.gd index 419f0172..e488ac88 100644 --- a/addons/gdUnit4/src/asserts/GdUnitArrayAssertImpl.gd +++ b/addons/gdUnit4/src/asserts/GdUnitArrayAssertImpl.gd @@ -7,10 +7,11 @@ var _current_value_provider :ValueProvider func _init(current): _current_value_provider = DefaultValueProvider.new(current) - _base = ResourceLoader.load("res://addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd", "GDScript", ResourceLoader.CACHE_MODE_REUSE).new(current) + _base = ResourceLoader.load("res://addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd", "GDScript", + ResourceLoader.CACHE_MODE_REUSE).new(current) # save the actual assert instance on the current thread context GdUnitThreadManager.get_current_context().set_assert(self) - if not __validate_value_type(current): + if not _validate_value_type(current): report_error("GdUnitArrayAssert inital error, unexpected type <%s>" % GdObjects.typeof_as_string(current)) @@ -30,7 +31,7 @@ func report_error(error :String) -> GdUnitArrayAssert: _base.report_error(error) return self -func _failure_message() -> String: +func failure_message() -> String: return _base._current_error_message @@ -39,14 +40,11 @@ func override_failure_message(message :String) -> GdUnitArrayAssert: return self -func __validate_value_type(value) -> bool: - return ( - value == null - or GdArrayTools.is_array_type(value) - ) +func _validate_value_type(value) -> bool: + return value == null or GdArrayTools.is_array_type(value) -func __current() -> Variant: +func current_value() -> Variant: return _current_value_provider.get_value() @@ -57,27 +55,27 @@ func max_length(left, right) -> int: func _array_equals_div(current, expected, case_sensitive :bool = false) -> Array: - var current_ := PackedStringArray(Array(current)) - var expected_ := PackedStringArray(Array(expected)) - var index_report_ := Array() - for index in current_.size(): - var c := current_[index] - if index < expected_.size(): - var e := expected_[index] + var current_value := PackedStringArray(Array(current)) + var expected_value := PackedStringArray(Array(expected)) + var index_report := Array() + for index in current_value.size(): + var c := current_value[index] + if index < expected_value.size(): + var e := expected_value[index] if not GdObjects.equals(c, e, case_sensitive): var length := max_length(c, e) - current_[index] = GdAssertMessages.format_invalid(c.lpad(length)) - expected_[index] = e.lpad(length) - index_report_.push_back({"index" : index, "current" :c, "expected": e}) + current_value[index] = GdAssertMessages.format_invalid(c.lpad(length)) + expected_value[index] = e.lpad(length) + index_report.push_back({"index" : index, "current" :c, "expected": e}) else: - current_[index] = GdAssertMessages.format_invalid(c) - index_report_.push_back({"index" : index, "current" :c, "expected": ""}) - - for index in range(current.size(), expected_.size()): - var value := expected_[index] - expected_[index] = GdAssertMessages.format_invalid(value) - index_report_.push_back({"index" : index, "current" : "", "expected": value}) - return [current_, expected_, index_report_] + current_value[index] = GdAssertMessages.format_invalid(c) + index_report.push_back({"index" : index, "current" :c, "expected": ""}) + + for index in range(current.size(), expected_value.size()): + var value := expected_value[index] + expected_value[index] = GdAssertMessages.format_invalid(value) + index_report.push_back({"index" : index, "current" : "", "expected": value}) + return [current_value, expected_value, index_report] func _array_div(compare_mode :GdObjects.COMPARE_MODE, left :Array[Variant], right :Array[Variant], _same_order := false) -> Array[Variant]: @@ -96,66 +94,66 @@ func _array_div(compare_mode :GdObjects.COMPARE_MODE, left :Array[Variant], righ func _contains(expected, compare_mode :GdObjects.COMPARE_MODE) -> GdUnitArrayAssert: - if not __validate_value_type(expected): + if not _validate_value_type(expected): return report_error("ERROR: expected value: <%s>\n is not a Array Type!" % GdObjects.typeof_as_string(expected)) var by_reference := compare_mode == GdObjects.COMPARE_MODE.OBJECT_REFERENCE - var current_ = __current() - if current_ == null: - return report_error(GdAssertMessages.error_arr_contains(current_, expected, [], expected, by_reference)) - var diffs := _array_div(compare_mode, current_, expected) + var current_value = current_value() + if current_value == null: + return report_error(GdAssertMessages.error_arr_contains(current_value, expected, [], expected, by_reference)) + var diffs := _array_div(compare_mode, current_value, expected) #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, by_reference)) + return report_error(GdAssertMessages.error_arr_contains(current_value, expected, [], not_found, by_reference)) return report_success() func _contains_exactly(expected, compare_mode :GdObjects.COMPARE_MODE) -> GdUnitArrayAssert: - if not __validate_value_type(expected): + if not _validate_value_type(expected): return report_error("ERROR: expected value: <%s>\n is not a Array Type!" % GdObjects.typeof_as_string(expected)) - var current_ = __current() - if current_ == null: - return report_error(GdAssertMessages.error_arr_contains_exactly(current_, expected, [], expected, compare_mode)) + var current_value = current_value() + if current_value == null: + return report_error(GdAssertMessages.error_arr_contains_exactly(current_value, expected, [], expected, compare_mode)) # has same content in same order - if GdObjects.equals(Array(current_), Array(expected), false, compare_mode): + if GdObjects.equals(Array(current_value), Array(expected), false, compare_mode): return report_success() # check has same elements but in different order - if GdObjects.equals_sorted(Array(current_), Array(expected), false, compare_mode): - return report_error(GdAssertMessages.error_arr_contains_exactly(current_, expected, [], [], compare_mode)) + if GdObjects.equals_sorted(Array(current_value), Array(expected), false, compare_mode): + return report_error(GdAssertMessages.error_arr_contains_exactly(current_value, expected, [], [], compare_mode)) # find the difference - var diffs := _array_div(compare_mode, current_, expected, GdObjects.COMPARE_MODE.PARAMETER_DEEP_TEST) + var diffs := _array_div(compare_mode, current_value, expected, GdObjects.COMPARE_MODE.PARAMETER_DEEP_TEST) var not_expect := diffs[0] as Array[Variant] var not_found := diffs[1] as Array[Variant] - return report_error(GdAssertMessages.error_arr_contains_exactly(current_, expected, not_expect, not_found, compare_mode)) + return report_error(GdAssertMessages.error_arr_contains_exactly(current_value, expected, not_expect, not_found, compare_mode)) func _contains_exactly_in_any_order(expected, compare_mode :GdObjects.COMPARE_MODE) -> GdUnitArrayAssert: - if not __validate_value_type(expected): + if not _validate_value_type(expected): return report_error("ERROR: expected value: <%s>\n is not a Array Type!" % GdObjects.typeof_as_string(expected)) - var current_ = __current() - if current_ == null: - return report_error(GdAssertMessages.error_arr_contains_exactly_in_any_order(current_, expected, [], expected, compare_mode)) + var current_value = current_value() + if current_value == null: + return report_error(GdAssertMessages.error_arr_contains_exactly_in_any_order(current_value, expected, [], expected, compare_mode)) # find the difference - var diffs := _array_div(compare_mode, current_, expected, false) + var diffs := _array_div(compare_mode, current_value, expected, false) var not_expect := diffs[0] as Array var not_found := diffs[1] as Array if not_expect.is_empty() and not_found.is_empty(): return report_success() - return report_error(GdAssertMessages.error_arr_contains_exactly_in_any_order(current_, expected, not_expect, not_found, compare_mode)) + return report_error(GdAssertMessages.error_arr_contains_exactly_in_any_order(current_value, expected, not_expect, not_found, compare_mode)) func _not_contains(expected, compare_mode :GdObjects.COMPARE_MODE) -> GdUnitArrayAssert: - if not __validate_value_type(expected): + if not _validate_value_type(expected): return report_error("ERROR: expected value: <%s>\n is not a Array Type!" % GdObjects.typeof_as_string(expected)) - var current_ = __current() - if current_ == null: - return report_error(GdAssertMessages.error_arr_contains_exactly_in_any_order(current_, expected, [], expected, compare_mode)) - var diffs := _array_div(compare_mode, current_, expected) + var current_value = current_value() + if current_value == null: + return report_error(GdAssertMessages.error_arr_contains_exactly_in_any_order(current_value, expected, [], expected, compare_mode)) + var diffs := _array_div(compare_mode, current_value, expected) var found := diffs[0] as Array - if found.size() == current_.size(): + if found.size() == current_value.size(): return report_success() var diffs2 := _array_div(compare_mode, expected, diffs[1]) - return report_error(GdAssertMessages.error_arr_not_contains(current_, expected, diffs2[0], compare_mode)) + return report_error(GdAssertMessages.error_arr_not_contains(current_value, expected, diffs2[0], compare_mode)) func is_null() -> GdUnitArrayAssert: @@ -170,13 +168,13 @@ func is_not_null() -> GdUnitArrayAssert: # Verifies that the current String is equal to the given one. func is_equal(expected) -> GdUnitArrayAssert: - if not __validate_value_type(expected): + if not _validate_value_type(expected): return report_error("ERROR: expected value: <%s>\n is not a Array Type!" % GdObjects.typeof_as_string(expected)) - var current_ = __current() - if current_ == null and expected != null: + var current_value = current_value() + if current_value == null and expected != null: return report_error(GdAssertMessages.error_equal(null, expected)) - if not GdObjects.equals(current_, expected): - var diff := _array_equals_div(current_, expected) + if not GdObjects.equals(current_value, expected): + var diff := _array_equals_div(current_value, expected) var expected_as_list = GdArrayTools.as_string(diff[0], false) var current_as_list = GdArrayTools.as_string(diff[1], false) var index_report = diff[2] @@ -186,13 +184,13 @@ func is_equal(expected) -> GdUnitArrayAssert: # Verifies that the current Array is equal to the given one, ignoring case considerations. func is_equal_ignoring_case(expected) -> GdUnitArrayAssert: - if not __validate_value_type(expected): + if not _validate_value_type(expected): return report_error("ERROR: expected value: <%s>\n is not a Array Type!" % GdObjects.typeof_as_string(expected)) - var current_ = __current() - if current_ == null and expected != null: + var current_value = current_value() + if current_value == null and expected != null: return report_error(GdAssertMessages.error_equal(null, GdArrayTools.as_string(expected))) - if not GdObjects.equals(current_, expected, true): - var diff := _array_equals_div(current_, expected, true) + if not GdObjects.equals(current_value, expected, true): + var diff := _array_equals_div(current_value, expected, true) var expected_as_list := GdArrayTools.as_string(diff[0]) var current_as_list := GdArrayTools.as_string(diff[1]) var index_report = diff[2] @@ -201,62 +199,62 @@ func is_equal_ignoring_case(expected) -> GdUnitArrayAssert: func is_not_equal(expected) -> GdUnitArrayAssert: - if not __validate_value_type(expected): + if not _validate_value_type(expected): return report_error("ERROR: expected value: <%s>\n is not a Array Type!" % GdObjects.typeof_as_string(expected)) - var current_ = __current() - if GdObjects.equals(current_, expected): - return report_error(GdAssertMessages.error_not_equal(current_, expected)) + var current_value = current_value() + if GdObjects.equals(current_value, expected): + return report_error(GdAssertMessages.error_not_equal(current_value, expected)) return report_success() func is_not_equal_ignoring_case(expected) -> GdUnitArrayAssert: - if not __validate_value_type(expected): + if not _validate_value_type(expected): return report_error("ERROR: expected value: <%s>\n is not a Array Type!" % GdObjects.typeof_as_string(expected)) - var current_ = __current() - if GdObjects.equals(current_, expected, true): - var c := GdArrayTools.as_string(current_) + var current_value = current_value() + if GdObjects.equals(current_value, expected, true): + var c := GdArrayTools.as_string(current_value) var e := GdArrayTools.as_string(expected) return report_error(GdAssertMessages.error_not_equal_case_insensetiv(c, e)) return report_success() func is_empty() -> GdUnitArrayAssert: - var current_ = __current() - if current_ == null or current_.size() > 0: - return report_error(GdAssertMessages.error_is_empty(current_)) + var current_value = current_value() + if current_value == null or current_value.size() > 0: + return report_error(GdAssertMessages.error_is_empty(current_value)) return report_success() func is_not_empty() -> GdUnitArrayAssert: - var current_ = __current() - if current_ != null and current_.size() == 0: + var current_value = current_value() + if current_value != null and current_value.size() == 0: return report_error(GdAssertMessages.error_is_not_empty()) return report_success() @warning_ignore("unused_parameter", "shadowed_global_identifier") func is_same(expected) -> GdUnitArrayAssert: - if not __validate_value_type(expected): + if not _validate_value_type(expected): return report_error("ERROR: expected value: <%s>\n is not a Array Type!" % GdObjects.typeof_as_string(expected)) - var current = __current() + var current = current_value() if not is_same(current, expected): report_error(GdAssertMessages.error_is_same(current, expected)) return self func is_not_same(expected) -> GdUnitArrayAssert: - if not __validate_value_type(expected): + if not _validate_value_type(expected): return report_error("ERROR: expected value: <%s>\n is not a Array Type!" % GdObjects.typeof_as_string(expected)) - var current = __current() + var current = current_value() if is_same(current, expected): report_error(GdAssertMessages.error_not_same(current, expected)) return self func has_size(expected: int) -> GdUnitArrayAssert: - var current_ = __current() - if current_ == null or current_.size() != expected: - return report_error(GdAssertMessages.error_has_size(current_, expected)) + var current_value = current_value() + if current_value == null or current_value.size() != expected: + return report_error(GdAssertMessages.error_has_size(current_value, expected)) return report_success() @@ -299,8 +297,9 @@ func is_instanceof(expected) -> GdUnitAssert: func extract(func_name :String, args := Array()) -> GdUnitArrayAssert: var extracted_elements := Array() - var extractor :GdUnitValueExtractor = ResourceLoader.load("res://addons/gdUnit4/src/extractors/GdUnitFuncValueExtractor.gd", "GDScript", ResourceLoader.CACHE_MODE_REUSE).new(func_name, args) - var current = __current() + var extractor :GdUnitValueExtractor = ResourceLoader.load("res://addons/gdUnit4/src/extractors/GdUnitFuncValueExtractor.gd", + "GDScript", ResourceLoader.CACHE_MODE_REUSE).new(func_name, args) + var current = current_value() if current == null: _current_value_provider = DefaultValueProvider.new(null) else: @@ -311,8 +310,8 @@ func extract(func_name :String, args := Array()) -> GdUnitArrayAssert: func extractv( - extr0 :GdUnitValueExtractor, - extr1 :GdUnitValueExtractor = null, + extr0 :GdUnitValueExtractor, + extr1 :GdUnitValueExtractor = null, extr2 :GdUnitValueExtractor = null, extr3 :GdUnitValueExtractor = null, extr4 :GdUnitValueExtractor = null, @@ -323,16 +322,26 @@ func extractv( extr9 :GdUnitValueExtractor = null) -> GdUnitArrayAssert: var extractors :Variant = GdArrayTools.filter_value([extr0, extr1, extr2, extr3, extr4, extr5, extr6, extr7, extr8, extr9], null) var extracted_elements := Array() - var current = __current() + var current = current_value() if current == null: _current_value_provider = DefaultValueProvider.new(null) else: - for element in __current(): - var ev :Array[Variant] = [GdUnitTuple.NO_ARG, GdUnitTuple.NO_ARG, GdUnitTuple.NO_ARG, GdUnitTuple.NO_ARG, GdUnitTuple.NO_ARG, GdUnitTuple.NO_ARG, GdUnitTuple.NO_ARG, GdUnitTuple.NO_ARG, GdUnitTuple.NO_ARG, GdUnitTuple.NO_ARG] + for element in current_value(): + var ev :Array[Variant] = [ + GdUnitTuple.NO_ARG, + GdUnitTuple.NO_ARG, + GdUnitTuple.NO_ARG, + GdUnitTuple.NO_ARG, + GdUnitTuple.NO_ARG, + GdUnitTuple.NO_ARG, + GdUnitTuple.NO_ARG, + GdUnitTuple.NO_ARG, + GdUnitTuple.NO_ARG, + GdUnitTuple.NO_ARG + ] for index in extractors.size(): var extractor :GdUnitValueExtractor = extractors[index] ev[index] = extractor.extract_value(element) - if extractors.size() > 1: extracted_elements.append(GdUnitTuple.new(ev[0], ev[1], ev[2], ev[3], ev[4], ev[5], ev[6], ev[7], ev[8], ev[9])) else: diff --git a/addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd b/addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd index a39a5bf0..30694b0c 100644 --- a/addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd +++ b/addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd @@ -13,25 +13,21 @@ func _init(current :Variant) -> void: GdAssertReports.reset_last_error_line_number() -func _failure_message() -> String: +func failure_message() -> String: return _current_error_message -func __current() -> Variant: +func current_value() -> Variant: return _current -func __validate_value_type(value, type :Variant.Type) -> bool: - return value == null or typeof(value) == type - - func report_success() -> GdUnitAssert: GdAssertReports.report_success() return self func report_error(error_message :String, failure_line_number: int = -1) -> GdUnitAssert: - var line_number := failure_line_number if failure_line_number != -1 else GdUnitAssert._get_line_number() + var line_number := failure_line_number if failure_line_number != -1 else GdUnitAssertions.get_line_number() GdAssertReports.set_last_error_line_number(line_number) _current_error_message = error_message if _custom_failure_message.is_empty() else _custom_failure_message GdAssertReports.report_error(_current_error_message, line_number) @@ -48,28 +44,28 @@ func override_failure_message(message :String): func is_equal(expected) -> GdUnitAssert: - var current = __current() + var current = current_value() if not GdObjects.equals(current, expected): return report_error(GdAssertMessages.error_equal(current, expected)) return report_success() func is_not_equal(expected) -> GdUnitAssert: - var current = __current() + var current = current_value() if GdObjects.equals(current, expected): return report_error(GdAssertMessages.error_not_equal(current, expected)) return report_success() func is_null() -> GdUnitAssert: - var current = __current() + var current = current_value() if current != null: return report_error(GdAssertMessages.error_is_null(current)) return report_success() func is_not_null() -> GdUnitAssert: - var current = __current() + var current = current_value() if current == null: return report_error(GdAssertMessages.error_is_not_null()) return report_success() diff --git a/addons/gdUnit4/src/asserts/GdUnitAssertions.gd b/addons/gdUnit4/src/asserts/GdUnitAssertions.gd index 194692cd..a4527911 100644 --- a/addons/gdUnit4/src/asserts/GdUnitAssertions.gd +++ b/addons/gdUnit4/src/asserts/GdUnitAssertions.gd @@ -5,6 +5,7 @@ extends RefCounted func _init() -> void: # preload all gdunit assertions to speedup testsuite loading time + # gdlint:disable=private-method-call GdUnitAssertions.__lazy_load("res://addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd") GdUnitAssertions.__lazy_load("res://addons/gdUnit4/src/asserts/GdUnitBoolAssertImpl.gd") GdUnitAssertions.__lazy_load("res://addons/gdUnit4/src/asserts/GdUnitStringAssertImpl.gd") @@ -26,5 +27,37 @@ func _init() -> void: ### in order to noticeably reduce the loading time of the test suite. # We go this hard way to increase the loading performance to avoid reparsing all the used scripts # for more detailed info -> https://github.com/godotengine/godot/issues/67400 +# gdlint:disable=function-name static func __lazy_load(script_path :String) -> GDScript: return ResourceLoader.load(script_path, "GDScript", ResourceLoader.CACHE_MODE_REUSE) + + +static func validate_value_type(value, type :Variant.Type) -> bool: + return value == null or typeof(value) == type + +# Scans the current stack trace for the root cause to extract the line number +static func get_line_number() -> int: + var stack_trace := get_stack() + if stack_trace == null or stack_trace.is_empty(): + return -1 + for index in stack_trace.size(): + var stack_info :Dictionary = stack_trace[index] + var function :String = stack_info.get("function") + # we catch helper asserts to skip over to return the correct line number + if function.begins_with("assert_"): + continue + if function.begins_with("test_"): + return stack_info.get("line") + var source :String = stack_info.get("source") + if source.is_empty() \ + or source.begins_with("user://") \ + or source.ends_with("GdUnitAssert.gd") \ + or source.ends_with("GdUnitAssertions.gd") \ + or source.ends_with("AssertImpl.gd") \ + or source.ends_with("GdUnitTestSuite.gd") \ + or source.ends_with("GdUnitSceneRunnerImpl.gd") \ + or source.ends_with("GdUnitObjectInteractions.gd") \ + or source.ends_with("GdUnitAwaiter.gd"): + continue + return stack_info.get("line") + return -1 diff --git a/addons/gdUnit4/src/asserts/GdUnitBoolAssertImpl.gd b/addons/gdUnit4/src/asserts/GdUnitBoolAssertImpl.gd index d838c86f..c2cdd34f 100644 --- a/addons/gdUnit4/src/asserts/GdUnitBoolAssertImpl.gd +++ b/addons/gdUnit4/src/asserts/GdUnitBoolAssertImpl.gd @@ -4,10 +4,11 @@ var _base: GdUnitAssert func _init(current): - _base = ResourceLoader.load("res://addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd", "GDScript", ResourceLoader.CACHE_MODE_REUSE).new(current) + _base = ResourceLoader.load("res://addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd", "GDScript", + ResourceLoader.CACHE_MODE_REUSE).new(current) # save the actual assert instance on the current thread context GdUnitThreadManager.get_current_context().set_assert(self) - if not _base.__validate_value_type(current, TYPE_BOOL): + if not GdUnitAssertions.validate_value_type(current, TYPE_BOOL): report_error("GdUnitBoolAssert inital error, unexpected type <%s>" % GdObjects.typeof_as_string(current)) @@ -18,8 +19,8 @@ func _notification(event): _base = null -func __current(): - return _base.__current() +func current_value(): + return _base.current_value() func report_success() -> GdUnitBoolAssert: @@ -32,7 +33,7 @@ func report_error(error :String) -> GdUnitBoolAssert: return self -func _failure_message() -> String: +func failure_message() -> String: return _base._current_error_message @@ -64,12 +65,12 @@ func is_not_equal(expected) -> GdUnitBoolAssert: func is_true() -> GdUnitBoolAssert: - if __current() != true: - return report_error(GdAssertMessages.error_is_true(__current())) + if current_value() != true: + return report_error(GdAssertMessages.error_is_true(current_value())) return report_success() func is_false() -> GdUnitBoolAssert: - if __current() == true || __current() == null: - return report_error(GdAssertMessages.error_is_false(__current())) + if current_value() == true || current_value() == null: + return report_error(GdAssertMessages.error_is_false(current_value())) return report_success() diff --git a/addons/gdUnit4/src/asserts/GdUnitDictionaryAssertImpl.gd b/addons/gdUnit4/src/asserts/GdUnitDictionaryAssertImpl.gd index 514894ba..a7dfd6ea 100644 --- a/addons/gdUnit4/src/asserts/GdUnitDictionaryAssertImpl.gd +++ b/addons/gdUnit4/src/asserts/GdUnitDictionaryAssertImpl.gd @@ -4,10 +4,11 @@ var _base :GdUnitAssert func _init(current): - _base = ResourceLoader.load("res://addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd", "GDScript", ResourceLoader.CACHE_MODE_REUSE).new(current) + _base = ResourceLoader.load("res://addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd", "GDScript", + ResourceLoader.CACHE_MODE_REUSE).new(current) # save the actual assert instance on the current thread context GdUnitThreadManager.get_current_context().set_assert(self) - if not _base.__validate_value_type(current, TYPE_DICTIONARY): + if not GdUnitAssertions.validate_value_type(current, TYPE_DICTIONARY): report_error("GdUnitDictionaryAssert inital error, unexpected type <%s>" % GdObjects.typeof_as_string(current)) @@ -28,7 +29,7 @@ func report_error(error :String) -> GdUnitDictionaryAssert: return self -func _failure_message() -> String: +func failure_message() -> String: return _base._current_error_message @@ -37,8 +38,8 @@ func override_failure_message(message :String) -> GdUnitDictionaryAssert: return self -func __current() -> Variant: - return _base.__current() +func current_value() -> Variant: + return _base.current_value() func is_null() -> GdUnitDictionaryAssert: @@ -52,20 +53,20 @@ func is_not_null() -> GdUnitDictionaryAssert: func is_equal(expected) -> GdUnitDictionaryAssert: - var current = __current() + var current = current_value() if current == null: return report_error(GdAssertMessages.error_equal(null, GdAssertMessages._format_dict(expected))) if not GdObjects.equals(current, expected): var c := GdAssertMessages._format_dict(current) var e := GdAssertMessages._format_dict(expected) var diff := GdDiffTool.string_diff(c, e) - var curent_ = GdAssertMessages._colored_array_div(diff[1]) + var curent_ = GdAssertMessages.colored_array_div(diff[1]) return report_error(GdAssertMessages.error_equal(curent_, e)) return report_success() func is_not_equal(expected) -> GdUnitDictionaryAssert: - var current = __current() + var current = current_value() if GdObjects.equals(current, expected): return report_error(GdAssertMessages.error_not_equal(current, expected)) return report_success() @@ -73,14 +74,14 @@ func is_not_equal(expected) -> GdUnitDictionaryAssert: @warning_ignore("unused_parameter", "shadowed_global_identifier") func is_same(expected) -> GdUnitDictionaryAssert: - var current = __current() + var current = current_value() if current == null: return report_error(GdAssertMessages.error_equal(null, GdAssertMessages._format_dict(expected))) if not is_same(current, expected): var c := GdAssertMessages._format_dict(current) var e := GdAssertMessages._format_dict(expected) var diff := GdDiffTool.string_diff(c, e) - var curent_ = GdAssertMessages._colored_array_div(diff[1]) + var curent_ = GdAssertMessages.colored_array_div(diff[1]) return report_error(GdAssertMessages.error_is_same(curent_, e)) return report_success() @@ -88,7 +89,7 @@ func is_same(expected) -> GdUnitDictionaryAssert: @warning_ignore("unused_parameter", "shadowed_global_identifier") func is_not_same(expected) -> GdUnitDictionaryAssert: - var current = __current() + var current = current_value() if is_same(current, expected): return report_error(GdAssertMessages.error_not_same(current, expected)) return report_success() @@ -96,21 +97,21 @@ func is_not_same(expected) -> GdUnitDictionaryAssert: func is_empty() -> GdUnitDictionaryAssert: - var current = __current() + var current = current_value() if current == null or not current.is_empty(): return report_error(GdAssertMessages.error_is_empty(current)) return report_success() func is_not_empty() -> GdUnitDictionaryAssert: - var current = __current() + var current = current_value() if current == null or current.is_empty(): return report_error(GdAssertMessages.error_is_not_empty()) return report_success() func has_size(expected: int) -> GdUnitDictionaryAssert: - var current = __current() + var current = current_value() if current == null: return report_error(GdAssertMessages.error_is_not_null()) if current.size() != expected: @@ -119,7 +120,7 @@ func has_size(expected: int) -> GdUnitDictionaryAssert: func _contains_keys(expected :Array, compare_mode :GdObjects.COMPARE_MODE) -> GdUnitDictionaryAssert: - var current = __current() + var current = current_value() if current == null: return report_error(GdAssertMessages.error_is_not_null()) # find expected keys @@ -135,7 +136,7 @@ func _contains_keys(expected :Array, compare_mode :GdObjects.COMPARE_MODE) -> Gd func _contains_key_value(key, value, compare_mode :GdObjects.COMPARE_MODE) -> GdUnitDictionaryAssert: - var current = __current() + var current = current_value() var expected := [key] if current == null: return report_error(GdAssertMessages.error_is_not_null()) @@ -153,7 +154,7 @@ func _contains_key_value(key, value, compare_mode :GdObjects.COMPARE_MODE) -> Gd func _not_contains_keys(expected :Array, compare_mode :GdObjects.COMPARE_MODE) -> GdUnitDictionaryAssert: - var current = __current() + var current = current_value() if current == null: return report_error(GdAssertMessages.error_is_not_null()) var keys_found :Array = current.keys().filter(func(current_key): diff --git a/addons/gdUnit4/src/asserts/GdUnitFailureAssertImpl.gd b/addons/gdUnit4/src/asserts/GdUnitFailureAssertImpl.gd index 8be056e6..6b1cdaa6 100644 --- a/addons/gdUnit4/src/asserts/GdUnitFailureAssertImpl.gd +++ b/addons/gdUnit4/src/asserts/GdUnitFailureAssertImpl.gd @@ -24,7 +24,7 @@ func execute_and_await(assertion :Callable, do_await := true) -> GdUnitFailureAs _is_failed = true _failure_message = "Invalid Callable! It must be a callable of 'GdUnitAssert'" return - _failure_message = current_assert._failure_message() + _failure_message = current_assert.failure_message() return self @@ -38,12 +38,12 @@ func _on_test_failed(value :bool) -> void: @warning_ignore("unused_parameter") -func is_equal(expected :GdUnitAssert) -> GdUnitFailureAssert: +func is_equal(_expected :GdUnitAssert) -> GdUnitFailureAssert: return _report_error("Not implemented") @warning_ignore("unused_parameter") -func is_not_equal(expected :GdUnitAssert) -> GdUnitFailureAssert: +func is_not_equal(_expected :GdUnitAssert) -> GdUnitFailureAssert: return _report_error("Not implemented") @@ -79,7 +79,7 @@ func has_message(expected :String) -> GdUnitFailureAssert: var current_error := GdUnitTools.normalize_text(GdUnitTools.richtext_normalize(_failure_message)) if current_error != expected_error: var diffs := GdDiffTool.string_diff(current_error, expected_error) - var current := GdAssertMessages._colored_array_div(diffs[1]) + var current := GdAssertMessages.colored_array_div(diffs[1]) _report_error(GdAssertMessages.error_not_same_error(current, expected_error)) return self @@ -89,13 +89,13 @@ func starts_with_message(expected :String) -> GdUnitFailureAssert: var current_error := GdUnitTools.normalize_text(GdUnitTools.richtext_normalize(_failure_message)) if current_error.find(expected_error) != 0: var diffs := GdDiffTool.string_diff(current_error, expected_error) - var current := GdAssertMessages._colored_array_div(diffs[1]) + var current := GdAssertMessages.colored_array_div(diffs[1]) _report_error(GdAssertMessages.error_not_same_error(current, expected_error)) return self func _report_error(error_message :String, failure_line_number: int = -1) -> GdUnitAssert: - var line_number := failure_line_number if failure_line_number != -1 else GdUnitAssert._get_line_number() + var line_number := failure_line_number if failure_line_number != -1 else GdUnitAssertions.get_line_number() GdAssertReports.report_error(error_message, line_number) return self diff --git a/addons/gdUnit4/src/asserts/GdUnitFileAssertImpl.gd b/addons/gdUnit4/src/asserts/GdUnitFileAssertImpl.gd index b4e07008..b23212a7 100644 --- a/addons/gdUnit4/src/asserts/GdUnitFileAssertImpl.gd +++ b/addons/gdUnit4/src/asserts/GdUnitFileAssertImpl.gd @@ -6,10 +6,11 @@ var _base: GdUnitAssert func _init(current): - _base = ResourceLoader.load("res://addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd", "GDScript", ResourceLoader.CACHE_MODE_REUSE).new(current) + _base = ResourceLoader.load("res://addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd", "GDScript", + ResourceLoader.CACHE_MODE_REUSE).new(current) # save the actual assert instance on the current thread context GdUnitThreadManager.get_current_context().set_assert(self) - if not _base.__validate_value_type(current, TYPE_STRING): + if not GdUnitAssertions.validate_value_type(current, TYPE_STRING): report_error("GdUnitFileAssert inital error, unexpected type <%s>" % GdObjects.typeof_as_string(current)) @@ -20,8 +21,8 @@ func _notification(event): _base = null -func __current() -> String: - return _base.__current() as String +func current_value() -> String: + return _base.current_value() as String func report_success() -> GdUnitFileAssert: @@ -34,7 +35,7 @@ func report_error(error :String) -> GdUnitFileAssert: return self -func _failure_message() -> String: +func failure_message() -> String: return _base._current_error_message @@ -54,24 +55,24 @@ func is_not_equal(expected) -> GdUnitFileAssert: func is_file() -> GdUnitFileAssert: - var current := __current() + var current := current_value() if FileAccess.open(current, FileAccess.READ) == null: return report_error("Is not a file '%s', error code %s" % [current, FileAccess.get_open_error()]) return report_success() func exists() -> GdUnitFileAssert: - var current := __current() + var current := current_value() if not FileAccess.file_exists(current): return report_error("The file '%s' not exists" %current) return report_success() func is_script() -> GdUnitFileAssert: - var current := __current() + var current := current_value() if FileAccess.open(current, FileAccess.READ) == null: return report_error("Can't acces the file '%s'! Error code %s" % [current, FileAccess.get_open_error()]) - + var script = load(current) if not script is GDScript: return report_error("The file '%s' is not a GdScript" % current) @@ -79,16 +80,16 @@ func is_script() -> GdUnitFileAssert: func contains_exactly(expected_rows :Array) -> GdUnitFileAssert: - var current := __current() + var current := current_value() if FileAccess.open(current, FileAccess.READ) == null: return report_error("Can't acces the file '%s'! Error code %s" % [current, FileAccess.get_open_error()]) - + var script = load(current) if script is GDScript: var instance = script.new() var source_code = GdScriptParser.to_unix_format(instance.get_script().source_code) GdUnitTools.free_instance(instance) var rows := Array(source_code.split("\n")) - ResourceLoader.load("res://addons/gdUnit4/src/asserts/GdUnitArrayAssertImpl.gd", "GDScript", ResourceLoader.CACHE_MODE_REUSE).new(rows)\ - .contains_exactly(expected_rows) + ResourceLoader.load("res://addons/gdUnit4/src/asserts/GdUnitArrayAssertImpl.gd", "GDScript", + ResourceLoader.CACHE_MODE_REUSE).new(rows).contains_exactly(expected_rows) return self diff --git a/addons/gdUnit4/src/asserts/GdUnitFloatAssertImpl.gd b/addons/gdUnit4/src/asserts/GdUnitFloatAssertImpl.gd index d457b00a..c0cd4b4d 100644 --- a/addons/gdUnit4/src/asserts/GdUnitFloatAssertImpl.gd +++ b/addons/gdUnit4/src/asserts/GdUnitFloatAssertImpl.gd @@ -4,10 +4,11 @@ var _base: GdUnitAssert func _init(current): - _base = ResourceLoader.load("res://addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd", "GDScript", ResourceLoader.CACHE_MODE_REUSE).new(current) + _base = ResourceLoader.load("res://addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd", "GDScript", + ResourceLoader.CACHE_MODE_REUSE).new(current) # save the actual assert instance on the current thread context GdUnitThreadManager.get_current_context().set_assert(self) - if not _base.__validate_value_type(current, TYPE_FLOAT): + if not GdUnitAssertions.validate_value_type(current, TYPE_FLOAT): report_error("GdUnitFloatAssert inital error, unexpected type <%s>" % GdObjects.typeof_as_string(current)) @@ -18,8 +19,8 @@ func _notification(event): _base = null -func __current(): - return _base.__current() +func current_value(): + return _base.current_value() func report_success() -> GdUnitFloatAssert: @@ -32,7 +33,7 @@ func report_error(error :String) -> GdUnitFloatAssert: return self -func _failure_message() -> String: +func failure_message() -> String: return _base._current_error_message @@ -67,77 +68,77 @@ func is_equal_approx(expected :float, approx :float) -> GdUnitFloatAssert: func is_less(expected :float) -> GdUnitFloatAssert: - var current = __current() + var current = current_value() if current == null or current >= expected: return report_error(GdAssertMessages.error_is_value(Comparator.LESS_THAN, current, expected)) return report_success() func is_less_equal(expected :float) -> GdUnitFloatAssert: - var current = __current() + var current = current_value() if current == null or current > expected: return report_error(GdAssertMessages.error_is_value(Comparator.LESS_EQUAL, current, expected)) return report_success() func is_greater(expected :float) -> GdUnitFloatAssert: - var current = __current() + var current = current_value() if current == null or current <= expected: return report_error(GdAssertMessages.error_is_value(Comparator.GREATER_THAN, current, expected)) return report_success() func is_greater_equal(expected :float) -> GdUnitFloatAssert: - var current = __current() + var current = current_value() if current == null or current < expected: return report_error(GdAssertMessages.error_is_value(Comparator.GREATER_EQUAL, current, expected)) return report_success() func is_negative() -> GdUnitFloatAssert: - var current = __current() + var current = current_value() if current == null or current >= 0.0: return report_error(GdAssertMessages.error_is_negative(current)) return report_success() func is_not_negative() -> GdUnitFloatAssert: - var current = __current() + var current = current_value() if current == null or current < 0.0: return report_error(GdAssertMessages.error_is_not_negative(current)) return report_success() func is_zero() -> GdUnitFloatAssert: - var current = __current() + var current = current_value() if current == null or not is_equal_approx(0.00000000, current): return report_error(GdAssertMessages.error_is_zero(current)) return report_success() func is_not_zero() -> GdUnitFloatAssert: - var current = __current() + var current = current_value() if current == null or is_equal_approx(0.00000000, current): return report_error(GdAssertMessages.error_is_not_zero()) return report_success() func is_in(expected :Array) -> GdUnitFloatAssert: - var current = __current() + var current = current_value() if not expected.has(current): return report_error(GdAssertMessages.error_is_in(current, expected)) return report_success() func is_not_in(expected :Array) -> GdUnitFloatAssert: - var current = __current() + var current = current_value() if expected.has(current): return report_error(GdAssertMessages.error_is_not_in(current, expected)) return report_success() func is_between(from :float, to :float) -> GdUnitFloatAssert: - var current = __current() + var current = current_value() 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 0c9e4b9f..4902ba05 100644 --- a/addons/gdUnit4/src/asserts/GdUnitFuncAssertImpl.gd +++ b/addons/gdUnit4/src/asserts/GdUnitFuncAssertImpl.gd @@ -15,7 +15,7 @@ var _sleep_timer :Timer = null func _init(instance :Object, func_name :String, args := Array()): - _line_number = GdUnitAssert._get_line_number() + _line_number = GdUnitAssertions.get_line_number() GdAssertReports.reset_last_error_line_number() # save the actual assert instance on the current thread context GdUnitThreadManager.get_current_context().set_assert(self) @@ -49,7 +49,7 @@ func report_error(error_message :String) -> GdUnitFuncAssert: return self -func _failure_message() -> String: +func failure_message() -> String: return _current_error_message @@ -72,43 +72,43 @@ func wait_until(timeout := 2000) -> GdUnitFuncAssert: func is_null() -> GdUnitFuncAssert: - await _validate_callback(__is_null) + await _validate_callback(cb_is_null) return self func is_not_null() -> GdUnitFuncAssert: - await _validate_callback(__is_not_null) + await _validate_callback(cb_is_not_null) return self func is_false() -> GdUnitFuncAssert: - await _validate_callback(__is_false) + await _validate_callback(cb_is_false) return self func is_true() -> GdUnitFuncAssert: - await _validate_callback(__is_true) + await _validate_callback(cb_is_true) return self func is_equal(expected) -> GdUnitFuncAssert: - await _validate_callback(__is_equal, expected) + await _validate_callback(cb_is_equal, expected) return self func is_not_equal(expected) -> GdUnitFuncAssert: - await _validate_callback(__is_not_equal, expected) + await _validate_callback(cb_is_not_equal, expected) return self # we need actually to define this Callable as functions otherwise we results into leaked scripts here # this is actually a Godot bug and needs this kind of workaround -func __is_null(c, _e): return c == null -func __is_not_null(c, _e): return c != null -func __is_false(c, _e): return c == false -func __is_true(c, _e): return c == true -func __is_equal(c, e): return GdObjects.equals(c,e) -func __is_not_equal(c, e): return not GdObjects.equals(c, e) +func cb_is_null(c, _e): return c == null +func cb_is_not_null(c, _e): return c != null +func cb_is_false(c, _e): return c == false +func cb_is_true(c, _e): return c == true +func cb_is_equal(c, e): return GdObjects.equals(c,e) +func cb_is_not_equal(c, e): return not GdObjects.equals(c, e) func _validate_callback(predicate :Callable, expected = null): @@ -128,7 +128,7 @@ func _validate_callback(predicate :Callable, expected = null): _sleep_timer = Timer.new() _sleep_timer.set_name("gdunit_funcassert_sleep_timer_%d" % _sleep_timer.get_instance_id() ) Engine.get_main_loop().root.add_child(_sleep_timer) - + while true: var current = await next_current_value() # is interupted or predicate success @@ -137,14 +137,14 @@ func _validate_callback(predicate :Callable, expected = null): if is_instance_valid(_sleep_timer): _sleep_timer.start(0.05) await _sleep_timer.timeout - + _sleep_timer.stop() await Engine.get_main_loop().process_frame if _interrupted: # https://github.com/godotengine/godot/issues/73052 #var predicate_name = predicate.get_method() var predicate_name :String = str(predicate).split('::')[1] - report_error(GdAssertMessages.error_interrupted(predicate_name.strip_edges().trim_prefix("__"), expected, LocalTime.elapsed(_timeout))) + report_error(GdAssertMessages.error_interrupted(predicate_name.strip_edges().trim_prefix("cb_"), expected, LocalTime.elapsed(_timeout))) else: report_success() _sleep_timer.free() diff --git a/addons/gdUnit4/src/asserts/GdUnitGodotErrorAssertImpl.gd b/addons/gdUnit4/src/asserts/GdUnitGodotErrorAssertImpl.gd index 708155ec..dcd6a9b1 100644 --- a/addons/gdUnit4/src/asserts/GdUnitGodotErrorAssertImpl.gd +++ b/addons/gdUnit4/src/asserts/GdUnitGodotErrorAssertImpl.gd @@ -6,7 +6,8 @@ var _callable :Callable func _init(callable :Callable): # we only support Godot 4.1.x+ because of await issue https://github.com/godotengine/godot/issues/80292 - assert(Engine.get_version_info().hex >= 0x40100, "This assertion is not supported for Godot 4.0.x. Please upgrade to the minimum version Godot 4.1.0!") + assert(Engine.get_version_info().hex >= 0x40100, + "This assertion is not supported for Godot 4.0.x. Please upgrade to the minimum version Godot 4.1.0!") # save the actual assert instance on the current thread context GdUnitThreadManager.get_current_context().set_assert(self) GdAssertReports.reset_last_error_line_number() @@ -26,7 +27,7 @@ func _error_monitor() -> GodotGdErrorMonitor: return GdUnitThreadManager.get_current_context().get_execution_context().error_monitor -func _failure_message() -> String: +func failure_message() -> String: return _current_error_message @@ -36,7 +37,7 @@ func _report_success() -> GdUnitAssert: func _report_error(error_message :String, failure_line_number: int = -1) -> GdUnitAssert: - var line_number := failure_line_number if failure_line_number != -1 else GdUnitAssert._get_line_number() + var line_number := failure_line_number if failure_line_number != -1 else GdUnitAssertions.get_line_number() _current_error_message = error_message GdAssertReports.report_error(error_message, line_number) return self diff --git a/addons/gdUnit4/src/asserts/GdUnitIntAssertImpl.gd b/addons/gdUnit4/src/asserts/GdUnitIntAssertImpl.gd index 7f39c060..6fc16e12 100644 --- a/addons/gdUnit4/src/asserts/GdUnitIntAssertImpl.gd +++ b/addons/gdUnit4/src/asserts/GdUnitIntAssertImpl.gd @@ -4,10 +4,11 @@ var _base: GdUnitAssert func _init(current): - _base = ResourceLoader.load("res://addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd", "GDScript", ResourceLoader.CACHE_MODE_REUSE).new(current) + _base = ResourceLoader.load("res://addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd", "GDScript", + ResourceLoader.CACHE_MODE_REUSE).new(current) # save the actual assert instance on the current thread context GdUnitThreadManager.get_current_context().set_assert(self) - if not _base.__validate_value_type(current, TYPE_INT): + if not GdUnitAssertions.validate_value_type(current, TYPE_INT): report_error("GdUnitIntAssert inital error, unexpected type <%s>" % GdObjects.typeof_as_string(current)) @@ -18,8 +19,8 @@ func _notification(event): _base = null -func __current() -> Variant: - return _base.__current() +func current_value() -> Variant: + return _base.current_value() func report_success() -> GdUnitIntAssert: @@ -32,7 +33,7 @@ func report_error(error :String) -> GdUnitIntAssert: return self -func _failure_message() -> String: +func failure_message() -> String: return _base._current_error_message @@ -62,91 +63,91 @@ func is_not_equal(expected :int) -> GdUnitIntAssert: func is_less(expected :int) -> GdUnitIntAssert: - var current = __current() + var current = current_value() if current == null or current >= expected: return report_error(GdAssertMessages.error_is_value(Comparator.LESS_THAN, current, expected)) return report_success() func is_less_equal(expected :int) -> GdUnitIntAssert: - var current = __current() + var current = current_value() if current == null or current > expected: return report_error(GdAssertMessages.error_is_value(Comparator.LESS_EQUAL, current, expected)) return report_success() func is_greater(expected :int) -> GdUnitIntAssert: - var current = __current() + var current = current_value() if current == null or current <= expected: return report_error(GdAssertMessages.error_is_value(Comparator.GREATER_THAN, current, expected)) return report_success() func is_greater_equal(expected :int) -> GdUnitIntAssert: - var current = __current() + var current = current_value() if current == null or current < expected: return report_error(GdAssertMessages.error_is_value(Comparator.GREATER_EQUAL, current, expected)) return report_success() func is_even() -> GdUnitIntAssert: - var current = __current() + var current = current_value() if current == null or current % 2 != 0: return report_error(GdAssertMessages.error_is_even(current)) return report_success() func is_odd() -> GdUnitIntAssert: - var current = __current() + var current = current_value() if current == null or current % 2 == 0: return report_error(GdAssertMessages.error_is_odd(current)) return report_success() func is_negative() -> GdUnitIntAssert: - var current = __current() + var current = current_value() if current == null or current >= 0: return report_error(GdAssertMessages.error_is_negative(current)) return report_success() func is_not_negative() -> GdUnitIntAssert: - var current = __current() + var current = current_value() if current == null or current < 0: return report_error(GdAssertMessages.error_is_not_negative(current)) return report_success() func is_zero() -> GdUnitIntAssert: - var current = __current() + var current = current_value() if current != 0: return report_error(GdAssertMessages.error_is_zero(current)) return report_success() func is_not_zero() -> GdUnitIntAssert: - var current = __current() + var current = current_value() if current == 0: return report_error(GdAssertMessages.error_is_not_zero()) return report_success() func is_in(expected :Array) -> GdUnitIntAssert: - var current = __current() + var current = current_value() if not expected.has(current): return report_error(GdAssertMessages.error_is_in(current, expected)) return report_success() func is_not_in(expected :Array) -> GdUnitIntAssert: - var current = __current() + var current = current_value() if expected.has(current): return report_error(GdAssertMessages.error_is_not_in(current, expected)) return report_success() func is_between(from :int, to :int) -> GdUnitIntAssert: - var current = __current() + var current = current_value() 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/GdUnitObjectAssertImpl.gd b/addons/gdUnit4/src/asserts/GdUnitObjectAssertImpl.gd index 18c67bf7..e3ee8790 100644 --- a/addons/gdUnit4/src/asserts/GdUnitObjectAssertImpl.gd +++ b/addons/gdUnit4/src/asserts/GdUnitObjectAssertImpl.gd @@ -4,14 +4,15 @@ var _base :GdUnitAssert func _init(current): - _base = ResourceLoader.load("res://addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd", "GDScript", ResourceLoader.CACHE_MODE_REUSE).new(current) + _base = ResourceLoader.load("res://addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd", "GDScript", + ResourceLoader.CACHE_MODE_REUSE).new(current) # save the actual assert instance on the current thread context GdUnitThreadManager.get_current_context().set_assert(self) if (current != null - and (_base.__validate_value_type(current, TYPE_BOOL) - or _base.__validate_value_type(current, TYPE_INT) - or _base.__validate_value_type(current, TYPE_FLOAT) - or _base.__validate_value_type(current, TYPE_STRING))): + and (GdUnitAssertions.validate_value_type(current, TYPE_BOOL) + or GdUnitAssertions.validate_value_type(current, TYPE_INT) + or GdUnitAssertions.validate_value_type(current, TYPE_FLOAT) + or GdUnitAssertions.validate_value_type(current, TYPE_STRING))): report_error("GdUnitObjectAssert inital error, unexpected type <%s>" % GdObjects.typeof_as_string(current)) @@ -22,8 +23,8 @@ func _notification(event): _base = null -func __current() -> Variant: - return _base.__current() +func current_value() -> Variant: + return _base.current_value() func report_success() -> GdUnitObjectAssert: @@ -36,7 +37,7 @@ func report_error(error :String) -> GdUnitObjectAssert: return self -func _failure_message() -> String: +func failure_message() -> String: return _base._current_error_message @@ -67,7 +68,7 @@ func is_not_null() -> GdUnitObjectAssert: @warning_ignore("shadowed_global_identifier") func is_same(expected) -> GdUnitObjectAssert: - var current :Variant = __current() + var current :Variant = current_value() if not is_same(current, expected): report_error(GdAssertMessages.error_is_same(current, expected)) return self @@ -76,7 +77,7 @@ func is_same(expected) -> GdUnitObjectAssert: func is_not_same(expected) -> GdUnitObjectAssert: - var current = __current() + var current = current_value() if is_same(current, expected): report_error(GdAssertMessages.error_not_same(current, expected)) return self @@ -85,7 +86,7 @@ func is_not_same(expected) -> GdUnitObjectAssert: func is_instanceof(type :Object) -> GdUnitObjectAssert: - var current :Object = __current() + var current :Object = current_value() if not is_instance_of(current, type): var result_expected: = GdObjects.extract_class_name(type) var result_current: = GdObjects.extract_class_name(current) @@ -96,7 +97,7 @@ func is_instanceof(type :Object) -> GdUnitObjectAssert: func is_not_instanceof(type) -> GdUnitObjectAssert: - var current :Variant = __current() + var current :Variant = current_value() if is_instance_of(current, type): var result: = GdObjects.extract_class_name(type) if result.is_success(): diff --git a/addons/gdUnit4/src/asserts/GdUnitResultAssertImpl.gd b/addons/gdUnit4/src/asserts/GdUnitResultAssertImpl.gd index ccc92e56..9598b3eb 100644 --- a/addons/gdUnit4/src/asserts/GdUnitResultAssertImpl.gd +++ b/addons/gdUnit4/src/asserts/GdUnitResultAssertImpl.gd @@ -4,10 +4,11 @@ var _base :GdUnitAssert func _init(current): - _base = ResourceLoader.load("res://addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd", "GDScript", ResourceLoader.CACHE_MODE_REUSE).new(current) + _base = ResourceLoader.load("res://addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd", "GDScript", + ResourceLoader.CACHE_MODE_REUSE).new(current) # save the actual assert instance on the current thread context GdUnitThreadManager.get_current_context().set_assert(self) - if not __validate_value_type(current): + if not validate_value_type(current): report_error("GdUnitResultAssert inital error, unexpected type <%s>" % GdObjects.typeof_as_string(current)) @@ -18,12 +19,12 @@ func _notification(event): _base = null -func __validate_value_type(value) -> bool: +func validate_value_type(value) -> bool: return value == null or value is GdUnitResult -func __current() -> GdUnitResult: - return _base.__current() as GdUnitResult +func current_value() -> GdUnitResult: + return _base.current_value() as GdUnitResult func report_success() -> GdUnitResultAssert: @@ -36,7 +37,7 @@ func report_error(error :String) -> GdUnitResultAssert: return self -func _failure_message() -> String: +func failure_message() -> String: return _base._current_error_message @@ -55,7 +56,7 @@ func is_not_null() -> GdUnitResultAssert: func is_empty() -> GdUnitResultAssert: - var result := __current() + var result := current_value() if result == null or not result.is_empty(): report_error(GdAssertMessages.error_result_is_empty(result)) else: @@ -64,7 +65,7 @@ func is_empty() -> GdUnitResultAssert: func is_success() -> GdUnitResultAssert: - var result := __current() + var result := current_value() if result == null or not result.is_success(): report_error(GdAssertMessages.error_result_is_success(result)) else: @@ -73,7 +74,7 @@ func is_success() -> GdUnitResultAssert: func is_warning() -> GdUnitResultAssert: - var result := __current() + var result := current_value() if result == null or not result.is_warn(): report_error(GdAssertMessages.error_result_is_warning(result)) else: @@ -82,7 +83,7 @@ func is_warning() -> GdUnitResultAssert: func is_error() -> GdUnitResultAssert: - var result := __current() + var result := current_value() if result == null or not result.is_error(): report_error(GdAssertMessages.error_result_is_error(result)) else: @@ -91,7 +92,7 @@ func is_error() -> GdUnitResultAssert: func contains_message(expected :String) -> GdUnitResultAssert: - var result := __current() + var result := current_value() if result == null: report_error(GdAssertMessages.error_result_has_message("", expected)) return self @@ -107,7 +108,7 @@ func contains_message(expected :String) -> GdUnitResultAssert: func is_value(expected) -> GdUnitResultAssert: - var result := __current() + var result := current_value() var value = null if result == null else result.value() if not GdObjects.equals(value, expected): report_error(GdAssertMessages.error_result_is_value(value, expected)) diff --git a/addons/gdUnit4/src/asserts/GdUnitSignalAssertImpl.gd b/addons/gdUnit4/src/asserts/GdUnitSignalAssertImpl.gd index fc18ad5e..4ef2eeb0 100644 --- a/addons/gdUnit4/src/asserts/GdUnitSignalAssertImpl.gd +++ b/addons/gdUnit4/src/asserts/GdUnitSignalAssertImpl.gd @@ -16,7 +16,7 @@ func _init(emitter :Object): var context := GdUnitThreadManager.get_current_context() context.set_assert(self) _signal_collector = context.get_signal_collector() - _line_number = GdUnitAssert._get_line_number() + _line_number = GdUnitAssertions.get_line_number() _emitter = emitter GdAssertReports.reset_last_error_line_number() @@ -27,7 +27,7 @@ func report_success() -> GdUnitAssert: func report_warning(message :String) -> GdUnitAssert: - GdAssertReports.report_warning(message, GdUnitAssert._get_line_number()) + GdAssertReports.report_warning(message, GdUnitAssertions.get_line_number()) return self @@ -37,7 +37,7 @@ func report_error(error_message :String) -> GdUnitAssert: return self -func _failure_message() -> String: +func failure_message() -> String: return _current_error_message @@ -68,13 +68,13 @@ func is_signal_exists(signal_name :String) -> GdUnitSignalAssert: # Verifies that given signal is emitted until waiting time func is_emitted(name :String, args := []) -> GdUnitSignalAssert: - _line_number = GdUnitAssert._get_line_number() + _line_number = GdUnitAssertions.get_line_number() return await _wail_until_signal(name, args, false) # Verifies that given signal is NOT emitted until waiting time func is_not_emitted(name :String, args := []) -> GdUnitSignalAssert: - _line_number = GdUnitAssert._get_line_number() + _line_number = GdUnitAssertions.get_line_number() return await _wail_until_signal(name, args, true) @@ -101,7 +101,7 @@ func _wail_until_signal(signal_name :String, expected_args :Array, expect_not_em 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(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))) timer.free() diff --git a/addons/gdUnit4/src/asserts/GdUnitStringAssertImpl.gd b/addons/gdUnit4/src/asserts/GdUnitStringAssertImpl.gd index ae272edf..8c1814fd 100644 --- a/addons/gdUnit4/src/asserts/GdUnitStringAssertImpl.gd +++ b/addons/gdUnit4/src/asserts/GdUnitStringAssertImpl.gd @@ -4,7 +4,8 @@ var _base :GdUnitAssert func _init(current): - _base = ResourceLoader.load("res://addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd", "GDScript", ResourceLoader.CACHE_MODE_REUSE).new(current) + _base = ResourceLoader.load("res://addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd", "GDScript", + ResourceLoader.CACHE_MODE_REUSE).new(current) # save the actual assert instance on the current thread context GdUnitThreadManager.get_current_context().set_assert(self) if current != null and typeof(current) != TYPE_STRING and typeof(current) != TYPE_STRING_NAME: @@ -18,12 +19,12 @@ func _notification(event): _base = null -func _failure_message() -> String: +func failure_message() -> String: return _base._current_error_message -func __current(): - var current = _base.__current() +func current_value(): + var current = _base.current_value() if current == null: return null return current as String @@ -55,92 +56,92 @@ func is_not_null() -> GdUnitStringAssert: func is_equal(expected) -> GdUnitStringAssert: - var current = __current() + var current = current_value() if current == null: return report_error(GdAssertMessages.error_equal(current, expected)) if not GdObjects.equals(current, expected): var diffs := GdDiffTool.string_diff(current, expected) - var formatted_current := GdAssertMessages._colored_array_div(diffs[1]) + var formatted_current := GdAssertMessages.colored_array_div(diffs[1]) return report_error(GdAssertMessages.error_equal(formatted_current, expected)) return report_success() func is_equal_ignoring_case(expected) -> GdUnitStringAssert: - var current = __current() + var current = current_value() if current == null: return report_error(GdAssertMessages.error_equal_ignoring_case(current, expected)) if not GdObjects.equals(current, expected, true): var diffs := GdDiffTool.string_diff(current, expected) - var formatted_current := GdAssertMessages._colored_array_div(diffs[1]) + var formatted_current := GdAssertMessages.colored_array_div(diffs[1]) return report_error(GdAssertMessages.error_equal_ignoring_case(formatted_current, expected)) return report_success() func is_not_equal(expected) -> GdUnitStringAssert: - var current = __current() + var current = current_value() if GdObjects.equals(current, expected): return report_error(GdAssertMessages.error_not_equal(current, expected)) return report_success() func is_not_equal_ignoring_case(expected) -> GdUnitStringAssert: - var current = __current() + var current = current_value() if GdObjects.equals(current, expected, true): return report_error(GdAssertMessages.error_not_equal(current, expected)) return report_success() func is_empty() -> GdUnitStringAssert: - var current = __current() + var current = current_value() if current == null or not current.is_empty(): return report_error(GdAssertMessages.error_is_empty(current)) return report_success() func is_not_empty() -> GdUnitStringAssert: - var current = __current() + var current = current_value() if current == null or current.is_empty(): return report_error(GdAssertMessages.error_is_not_empty()) return report_success() func contains(expected :String) -> GdUnitStringAssert: - var current = __current() + var current = current_value() if current == null or current.find(expected) == -1: return report_error(GdAssertMessages.error_contains(current, expected)) return report_success() func not_contains(expected :String) -> GdUnitStringAssert: - var current = __current() + var current = current_value() if current != null and current.find(expected) != -1: return report_error(GdAssertMessages.error_not_contains(current, expected)) return report_success() func contains_ignoring_case(expected :String) -> GdUnitStringAssert: - var current = __current() + var current = current_value() if current == null or current.findn(expected) == -1: return report_error(GdAssertMessages.error_contains_ignoring_case(current, expected)) return report_success() func not_contains_ignoring_case(expected :String) -> GdUnitStringAssert: - var current = __current() + var current = current_value() if current != null and current.findn(expected) != -1: return report_error(GdAssertMessages.error_not_contains_ignoring_case(current, expected)) return report_success() func starts_with(expected :String) -> GdUnitStringAssert: - var current = __current() + var current = current_value() if current == null or current.find(expected) != 0: return report_error(GdAssertMessages.error_starts_with(current, expected)) return report_success() func ends_with(expected :String) -> GdUnitStringAssert: - var current = __current() + var current = current_value() if current == null: return report_error(GdAssertMessages.error_ends_with(current, expected)) var find = current.length() - expected.length() @@ -149,8 +150,9 @@ func ends_with(expected :String) -> GdUnitStringAssert: return report_success() +# gdlint:disable=max-returns func has_length(expected :int, comparator :int = Comparator.EQUAL) -> GdUnitStringAssert: - var current = __current() + var current = current_value() if current == null: return report_error(GdAssertMessages.error_has_length(current, expected, comparator)) match comparator: diff --git a/addons/gdUnit4/src/asserts/GdUnitVectorAssertImpl.gd b/addons/gdUnit4/src/asserts/GdUnitVectorAssertImpl.gd index 43a63f1d..9fbe25cb 100644 --- a/addons/gdUnit4/src/asserts/GdUnitVectorAssertImpl.gd +++ b/addons/gdUnit4/src/asserts/GdUnitVectorAssertImpl.gd @@ -5,7 +5,8 @@ var _current_type :int func _init(current :Variant): - _base = ResourceLoader.load("res://addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd", "GDScript", ResourceLoader.CACHE_MODE_REUSE).new(current) + _base = ResourceLoader.load("res://addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd", "GDScript", + ResourceLoader.CACHE_MODE_REUSE).new(current) # save the actual assert instance on the current thread context GdUnitThreadManager.get_current_context().set_assert(self) if not _validate_value_type(current): @@ -21,14 +22,17 @@ func _notification(event): func _validate_value_type(value) -> bool: - return (value == null + return ( + value == null or typeof(value) in [ TYPE_VECTOR2, TYPE_VECTOR2I, TYPE_VECTOR3, TYPE_VECTOR3I, TYPE_VECTOR4, - TYPE_VECTOR4I]) + TYPE_VECTOR4I + ] + ) func _validate_is_vector_type(value :Variant) -> bool: @@ -39,8 +43,8 @@ func _validate_is_vector_type(value :Variant) -> bool: return false -func __current() -> Variant: - return _base.__current() +func current_value() -> Variant: + return _base.current_value() func report_success() -> GdUnitVectorAssert: @@ -53,7 +57,7 @@ func report_error(error :String) -> GdUnitVectorAssert: return self -func _failure_message() -> String: +func failure_message() -> String: return _base._current_error_message @@ -90,7 +94,7 @@ func is_not_equal(expected :Variant) -> GdUnitVectorAssert: func is_equal_approx(expected :Variant, approx :Variant) -> GdUnitVectorAssert: if not _validate_is_vector_type(expected) or not _validate_is_vector_type(approx): return self - var current = __current() + var current = current_value() var from = expected - approx var to = expected + approx if current == null or (not _is_equal_approx(current, from, to)): @@ -117,7 +121,7 @@ func _is_equal_approx(current, from, to) -> bool: func is_less(expected :Variant) -> GdUnitVectorAssert: if not _validate_is_vector_type(expected): return self - var current = __current() + var current = current_value() if current == null or current >= expected: return report_error(GdAssertMessages.error_is_value(Comparator.LESS_THAN, current, expected)) return report_success() @@ -126,7 +130,7 @@ func is_less(expected :Variant) -> GdUnitVectorAssert: func is_less_equal(expected :Variant) -> GdUnitVectorAssert: if not _validate_is_vector_type(expected): return self - var current = __current() + var current = current_value() if current == null or current > expected: return report_error(GdAssertMessages.error_is_value(Comparator.LESS_EQUAL, current, expected)) return report_success() @@ -135,7 +139,7 @@ func is_less_equal(expected :Variant) -> GdUnitVectorAssert: func is_greater(expected :Variant) -> GdUnitVectorAssert: if not _validate_is_vector_type(expected): return self - var current = __current() + var current = current_value() if current == null or current <= expected: return report_error(GdAssertMessages.error_is_value(Comparator.GREATER_THAN, current, expected)) return report_success() @@ -144,7 +148,7 @@ func is_greater(expected :Variant) -> GdUnitVectorAssert: func is_greater_equal(expected :Variant) -> GdUnitVectorAssert: if not _validate_is_vector_type(expected): return self - var current = __current() + var current = current_value() if current == null or current < expected: return report_error(GdAssertMessages.error_is_value(Comparator.GREATER_EQUAL, current, expected)) return report_success() @@ -153,7 +157,7 @@ func is_greater_equal(expected :Variant) -> GdUnitVectorAssert: func is_between(from :Variant, to :Variant) -> GdUnitVectorAssert: if not _validate_is_vector_type(from) or not _validate_is_vector_type(to): return self - var current = __current() + var current = current_value() if current == null or not (current >= from and current <= to): return report_error(GdAssertMessages.error_is_value(Comparator.BETWEEN_EQUAL, current, from, to)) return report_success() @@ -162,7 +166,7 @@ func is_between(from :Variant, to :Variant) -> GdUnitVectorAssert: func is_not_between(from :Variant, to :Variant) -> GdUnitVectorAssert: if not _validate_is_vector_type(from) or not _validate_is_vector_type(to): return self - var current = __current() + var current = current_value() if (current != null and current >= from and current <= to): return report_error(GdAssertMessages.error_is_value(Comparator.NOT_BETWEEN_EQUAL, current, from, to)) return report_success() diff --git a/addons/gdUnit4/test/asserts/GdUnitAssertImplTest.gd b/addons/gdUnit4/test/asserts/GdUnitAssertImplTest.gd index 4315dd0f..7cc9e6f9 100644 --- a/addons/gdUnit4/test/asserts/GdUnitAssertImplTest.gd +++ b/addons/gdUnit4/test/asserts/GdUnitAssertImplTest.gd @@ -6,7 +6,7 @@ extends GdUnitTestSuite const __source = 'res://addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd' func before(): - assert_int(GdUnitAssert._get_line_number()).is_equal(9) + assert_int(GdUnitAssertions.get_line_number()).is_equal(9) assert_failure(func(): assert_int(10).is_equal(42)) \ .is_failed() \ .has_line(10) \ diff --git a/addons/gdUnit4/test/asserts/GdUnitSignalAssertImplTest.gd b/addons/gdUnit4/test/asserts/GdUnitSignalAssertImplTest.gd index 7808b88f..a5c77d28 100644 --- a/addons/gdUnit4/test/asserts/GdUnitSignalAssertImplTest.gd +++ b/addons/gdUnit4/test/asserts/GdUnitSignalAssertImplTest.gd @@ -53,7 +53,7 @@ func verify_failed(cb :Callable) -> GdUnitStringAssert: GdAssertReports.expect_fail(false) var a :GdUnitSignalAssert = GdUnitThreadManager.get_current_context().get_assert() - return assert_str(GdUnitTools.richtext_normalize(a._failure_message())) + return assert_str(GdUnitTools.richtext_normalize(a.failure_message())) func test_invalid_arg() -> void: