Skip to content

Commit

Permalink
GD-614: Fixed using un-type test parameters (#615)
Browse files Browse the repository at this point in the history
# Why
Using untyped test parameters, e.g. `fuzzer_iterations = 10` ends up in
a runtime error of invalid type assignment.

# What
Enforce test parameter to convert to expected type to avoid invalid type
assignment.
  • Loading branch information
MikeSchulze authored Dec 16, 2024
1 parent ac6c1f1 commit a94c626
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions addons/gdUnit4/src/core/GdUnitTestSuiteScanner.gd
Original file line number Diff line number Diff line change
Expand Up @@ -191,19 +191,19 @@ func _handle_test_case_arguments(test_suite: GdUnitTestSuite, script: GDScript,
elif arg.has_default():
match arg.name():
_TestCase.ARGUMENT_TIMEOUT:
timeout = arg.default()
timeout = convert(arg.default(), TYPE_INT)
_TestCase.ARGUMENT_SKIP:
var result :Variant = _expression_runner.execute(script, arg.plain_value())
var result: Variant = _expression_runner.execute(script, arg.plain_value())
if result is bool:
is_skipped = result
else:
push_error("Test expression '%s' cannot be evaluated because it is not of type bool!" % arg.plain_value())
_TestCase.ARGUMENT_SKIP_REASON:
skip_reason = arg.plain_value()
Fuzzer.ARGUMENT_ITERATIONS:
iterations = arg.default()
iterations = convert(arg.default(), TYPE_INT)
Fuzzer.ARGUMENT_SEED:
seed_value = arg.default()
seed_value = convert(arg.default(), TYPE_INT)
# create new test
@warning_ignore("return_value_discarded")
test.configure(fd.name(), fd.line_number(), fd.source_path(), timeout, fuzzers, iterations, seed_value)
Expand Down
5 changes: 5 additions & 0 deletions addons/gdUnit4/test/fuzzers/GdUnitFuzzerValueInjectionTest.gd
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,8 @@ func test_multiline_fuzzer_args(
assert_object(fuzzer_a).is_not_null()
assert_object(fuzzer_b).is_not_null()
_current_iterations["test_multiline_fuzzer_args"] += 1


@warning_ignore("untyped_declaration", "unused_parameter")
func test_fuzzing_with_untyped_parameters(float_fuzzer = Fuzzers.rangef(-100.0, 100.0), fuzzer_iterations = 10):
assert_float(float_fuzzer.next_value()).is_between(-100.0, 100.0)

0 comments on commit a94c626

Please sign in to comment.