Skip to content

Instantly share code, notes, and snippets.

@dperny
Last active May 3, 2017 19:02
Show Gist options
  • Save dperny/dacdcd9f43c24c480eb0c76e7cf97bae to your computer and use it in GitHub Desktop.
Save dperny/dacdcd9f43c24c480eb0c76e7cf97bae to your computer and use it in GitHub Desktop.
Defer if passing example
func DeferIfPassing(t *testing.T, f func()) {
if t.Failed() {
return
}
f()
}
TestDeferIfPassing(t *testing.T) {
// skip a bit, fill in the blanks
defer DeferIfPassing(t, func() { someCleanUp(with, some, args) })
require.Fail(t, "Fail this test")
}
.--------------.
| ~MAGIC~ |
| ____ |
| |.--.| |
| || || |
| ||__|| |
| ||\ \| |
| |\ \_\ |
| |_\[_] |
| |
| ~MORE MAGIC~ |
'--------------'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment