Skip to content

Test.expectFailure does not output the error message #4475

@holyfuchs

Description

@holyfuchs

Issue to be solved

Test.expectFailure(fun () { willfail() }, errorMessageSubstring: "no funds")

will output:

- FAIL: test_has_no_pass_by_default
                Execution failed:
                        error: Expected error message to include: "pass"
                          --> cadence/tests/x.cdc

                        Was this error unhelpful?
                        Consider suggesting an improvement here: https://github.com/onflow/cadence/issues.

it would help to have in the test output the error message that was actually returned.

Suggested Solution

defer invocationContext.RecoverErrors(func(internalErr error) {
	if !failedAsExpected {
		panic(internalErr)
	} else if !strings.Contains(internalErr.Error(), errorMessage.Str) {
		panic(errors.NewDefaultUserError(
			"Expected error message to include: %s",
			errorMessage,
		))
	}
})

add

errors.NewDefaultUserError(
	"Expected error message to include: %s, got: %s",
	errorMessage,
	internalErr.Error()
)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions