MikeSchulze / gdUnit4

A Godot Unit Test Framework. Support for GDScript and C# unit testing
MIT License
490 stars 28 forks source link

GD-512: Add function to append additional failure message text #512

Closed ZodmanPerth closed 2 weeks ago

ZodmanPerth commented 2 weeks ago

Is your feature request related to a problem? Please describe. When doing tests that involve looping over arrays, if an assert fails within the loop the failure message only shows the line number, the current value, and the expected value. I would like to append a line to the failure message that would identify other information such as the index of the loop where the failure happened.

Describe the solution you'd like An optional function such as append_failure_message where I can specify additional info on the failure message without losing the line/expected/current value details would resolve the problem.

Describe alternatives you've considered Currently I can use override_failure_message but I lose the line/expected/current value details. I could recreate that detail myself but it is cumbersome and duplicates what GDUnit already provides.

Additional context none

MikeSchulze commented 2 weeks ago

That sounds like a good idea. Thanks, I will add a new function to extend the failure messages.

I suggest: append_failure_message(<message>: String)

Example:

    assert_array([1, 2, 3, 4, 5])\
        .append_failure_message("Failed at index '%d'" % 10)\
        .not_contains([6, 4, 1])

Shows: image image