-
Notifications
You must be signed in to change notification settings - Fork 7
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
Defer 'after' block before any hook execution #14
Conversation
Currently if anything in the before block calls t.FailNow (like t.Fatal), the after block never executes because it never gets to defer
Good catch! |
@cbron Looks like this change introduced an interesting bug: func TestObject(t *testing.T) {
spec.Run(t, "object", func(t *testing.T, when spec.G, it spec.S) {
it.Before(func() {
fmt.Println("Before")
t.Skip()
})
it.After(func() {
fmt.Println("After")
})
it("should have some default", func() {
fmt.Println("Test")
})
when("group", func() {
it.Before(func() {
fmt.Println("Skipped before")
})
it.After(func() {
fmt.Println("This after should be skipped too")
})
it("should have some other default", func() {
fmt.Println("blah")
})
})
})
} One might expect Here's a real-world example of where v1.3.0 introduced a test failure: https://github.com/buildpacks/pack/blob/master/internal/paths/paths_test.go#L24 I'd prefer to fix this for the next release rather than revert it. Let me know if you disagree about the correct behavior / have suggestions. |
@sclevine interesting, I would also assume that only "Before" and "After" would print but not the others. I'd still want "After" to print because you might setup some objects in the before block and then skip/fail on a conditional halfway through, and after should clean that situation up. Can't think of a simple solution off top of my head. Probably needs something more complex like grouping execution in blocks or adding in a separator. Really what we want is
|
Working on a fix now -- just wanted to make sure that we agree on the behavior. 😄 |
Signed-off-by: Stephen Levine <[email protected]>
Signed-off-by: Stephen Levine <[email protected]>
@cbron Fixed (v1.3.0...v1.4.0) and released: |
@sclevine nice solution, a good ol linked list. I bumped our version and its working well. Thanks! |
Currently if anything in the before block calls t.FailNow (like t.Fatal), the after block never executes because it never gets to defer. This is a problem if your
before
block sets up multiple objects and you need to clean all of them up if any fail.Example:
Output, notice that
After
isn't printed:Thanks for the library @sclevine , really enjoying working with it so far.