-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cmd/gno): move test output within gno code (#1594)
Once again, welcome to "I was annoyed by a small thing that I wanted to do a 10 minute fix for and ended up on a refactoring detour". This PR moves the output of the `gno test` function to happen within the gno code. This solves a number of issues: - filtered tests are no longer printed to the console with `--- FILT` (my original 10-minute fix) - test output is no longer buffered - success of subtests is reported correctly - run/success report of subtests goes to stderr instead of stdout - `--- FAIL` is not printed for every time a Fail function is called (ie. only once) - as a bonus, `SkipNow` and `FailNow` actually work, so now you can Skip and Fatal your way out of test functions. Fixes #665
- Loading branch information
Showing
12 changed files
with
299 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Test panic output in a test | ||
|
||
! gno test . | ||
|
||
! stdout .+ | ||
stderr '--- FAIL: TestPanic' | ||
stderr 'panic: hello world' | ||
stderr 'FAIL' | ||
|
||
-- panic.gno -- | ||
package valid | ||
|
||
-- panic_test.gno -- | ||
package valid | ||
|
||
import "testing" | ||
|
||
func TestPanic(t *testing.T) { | ||
panic("hello world") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Test recovering | ||
|
||
gno test -verbose -run 'TestRecover$' . | ||
|
||
! stdout .+ | ||
stderr 'recovered bad panic!' | ||
stderr '--- PASS' | ||
stderr 'ok ' | ||
|
||
gno test -verbose -run 'TestRecoverSkip$' . | ||
|
||
! stdout .+ | ||
stderr 'skipped' | ||
! stderr 'recovered.*testing.Recover' | ||
stderr '--- SKIP' | ||
stderr 'ok ' | ||
|
||
gno test -verbose -run 'TestBadRecoverSkip$' . | ||
|
||
! stdout .+ | ||
# should contain warning about using testing.Recover | ||
stderr 'recovered.*testing.Recover' | ||
# the test will still be marked as skipped | ||
stderr '--- SKIP' | ||
stderr 'ok ' | ||
|
||
-- recov.gno -- | ||
package recov | ||
|
||
-- recov_test.gno -- | ||
package recov | ||
|
||
import "testing" | ||
|
||
func TestRecover(t *testing.T) { | ||
defer func() { | ||
err := testing.Recover() | ||
t.Log("recovered", err) | ||
}() | ||
|
||
panic("bad panic!") | ||
} | ||
|
||
func TestRecoverSkip(t *testing.T) { | ||
defer func() { | ||
err := testing.Recover() | ||
t.Log("recovered", err) | ||
}() | ||
|
||
t.Skip("skipped") | ||
panic("bad panic!") | ||
} | ||
|
||
func TestBadRecoverSkip(t *testing.T) { | ||
defer func() { | ||
err := recover() | ||
t.Log("recovered", err) | ||
}() | ||
|
||
t.Skip("skipped") | ||
panic("bad panic!") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Test skipping a test | ||
|
||
gno test -verbose . | ||
|
||
! stdout .+ | ||
stderr 'Hey' | ||
stderr 'I.m on strike!' | ||
! stderr 'this shouldn.t print' | ||
stderr '--- SKIP: TestSkip' | ||
stderr 'ok ' | ||
|
||
-- skip.gno -- | ||
package skip | ||
|
||
-- skip_test.gno -- | ||
package skip | ||
|
||
import "testing" | ||
|
||
func TestSkip(t *testing.T) { | ||
t.Log("Hey") | ||
t.Skip("I'm on strike!") | ||
t.Log("so this shouldn't print") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.