Skip to content

Commit

Permalink
GD-139: Do code cleanup to remove errors and warnings (#141)
Browse files Browse the repository at this point in the history
# Why
By default addons are excluded from code validation, after inclusion the
plugin displays over 1800 warnings and some errors

![image](https://user-images.githubusercontent.com/347037/223846970-74dc362b-dcd2-48a0-9a6b-7137e4c1671b.png)


# What
- fix the errors
- reduce the warnings
- update inline documentation  
- apply formatting rules

# Open issues
-Only 23 warnings left, covered by the listed Godot issues

![image](https://user-images.githubusercontent.com/347037/224134816-2f3729bd-4aac-4cc5-af6d-3934b49a1b2f.png)

- invalid warnings about enum
[74593](godotengine/godot#74593)
  - INT_AS_ENUM_WITHOUT_CAST
  - INT_AS_ENUM_WITHOUT_MATCH 
- disable warnings not work
[56592](godotengine/godot#56592)
   - shadowed_global_identifier
  • Loading branch information
MikeSchulze authored Mar 9, 2023
1 parent f25c7dd commit 5f7bcbf
Show file tree
Hide file tree
Showing 149 changed files with 2,109 additions and 1,378 deletions.
11 changes: 9 additions & 2 deletions addons/gdUnit4/bin/GdUnitBuildTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand All @@ -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:
Expand All @@ -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 <source_path> -scl <line_number>", 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)
Expand Down
8 changes: 4 additions & 4 deletions addons/gdUnit4/bin/GdUnitCmdTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions addons/gdUnit4/bin/ProjectScanner.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()
Expand Down
15 changes: 10 additions & 5 deletions addons/gdUnit4/src/Fuzzers.gd
Original file line number Diff line number Diff line change
@@ -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)
57 changes: 40 additions & 17 deletions addons/gdUnit4/src/GdUnitArrayAssert.gd
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
28 changes: 20 additions & 8 deletions addons/gdUnit4/src/GdUnitAssert.gd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Base interface of all GdUnit asserts
## Base interface of all GdUnit asserts
class_name GdUnitAssert
extends RefCounted

Expand All @@ -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
24 changes: 17 additions & 7 deletions addons/gdUnit4/src/GdUnitBoolAssert.gd
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 5f7bcbf

Please sign in to comment.