Skip to content

Returning true/false for all assert_* methods #850

Description

@guildem

Maybe I'm not using Gut the right way, but I didn't found any alternative in the docs no duplicate in the opened or closed issues. Sorry if I misunderstood the concept.

I have sometimes tests like that :

func test_example() -> void:
    var object = MyClass.make_object() # can return either an object instanciated from MyClass or null
    
    assert_is(object, MyClass, "should be MyClass")
    if object is MyClass:
        assert_true(object.my_class_function(), "should be true)

If I don't check that object is from MyClass before I do my second test, and object is null, then the Engine crash, because it doesn't find the function.

It would be better to check only one time, by returning the test result from the test, to write something like that :

func test_example() -> void:
    var object = MyClass.make_object() # can return either an object instanciated from MyClass or null
    
    if assert_is(object, MyClass, "should be MyClass"):
        assert_true(object.my_class_function(), "should be true)

Each assert_* method would return a bool, with by default a return false at the end, and return true after each pass() call. I even may be able to make the PR myself. And it should be retrocompatible, because no assert* returns anything.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions