Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mechanism for assertions to signal immediate/fatal termination of failed test cases #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mdwhatcott
Copy link
Contributor

@mdwhatcott mdwhatcott commented Oct 6, 2023

...via *testing.T.Fatalf.

This change is meant to be released in concert with smarty/assertions#55, which introduces a new must package.

This new feature addresses cases where an assertion failure early in a test should kill a test immediately. Here are a few examples of how we've approached this up until this PR:

Length checks before assertions:

Old way:

if !this.So(collection, should.HaveLength, 2) {
    return // we don't have enough items in the collection for upcoming assertions
}
this.So(collection[1].Whatever, should.Equal, "something")
... // more assertions may follow

New way:

this.So(collection, must.HaveLength, 2) // <- new 'must' package ends failed test immediately
this.So(collection[1].Whatever, should.Equal, "Something")

Error checking before subsequent assertions:

Old way:

value, err := SomeOperationThatCouldFail()
if !this.So(err, should.BeNil) {
    return
}
this.So(value, should.Equal, 42)

New way:

value, err := SomeOperationThatCouldFail()
this.So(err, must.BeNil) // <- new 'must' package ends failed test immediately
this.So(value, should.Equal, 42)

@mdwhatcott mdwhatcott changed the title Assertions whose output begins with "<<FATAL>>" end tests immediately. Mechanism for assertions to end tests immediately Oct 6, 2023
@mdwhatcott mdwhatcott changed the title Mechanism for assertions to end tests immediately Mechanism for assertions to signal immediate/fatal termination of failed test cases Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant