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

feat(gno test): implement failfast flag #3866

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ build:
test:
go run ../gnovm/cmd/gno test -v ./...

.PHONY: test.fast
test:
go run ../gnovm/cmd/gno test -failfast -v ./...

.PHONY: lint
lint:
go run ../gnovm/cmd/gno tool lint -v $(OFFICIAL_PACKAGES)
Expand Down
12 changes: 12 additions & 0 deletions gnovm/cmd/gno/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

type testCfg struct {
verbose bool
failfast bool
rootDir string
run string
timeout time.Duration
Expand Down Expand Up @@ -104,6 +105,13 @@ func (c *testCfg) RegisterFlags(fs *flag.FlagSet) {
"verbose output when running",
)

fs.BoolVar(
&c.failfast,
"failfast",
false,
"disables running additional tests after any test fails",
)

fs.BoolVar(
&c.updateGoldenTests,
"update-golden-tests",
Expand Down Expand Up @@ -246,6 +254,10 @@ func execTest(cfg *testCfg, args []string, io commands.IO) error {
io.ErrPrintfln("FAIL %s \t%s", pkg.Dir, dstr)
io.ErrPrintfln("FAIL")
testErrCount++
if cfg.failfast {
io.ErrPrintfln("FAIL")
return fmt.Errorf("FAIL: %d build errors, %d test errors", buildErrCount, testErrCount)
}
Comment on lines +258 to +261
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-failfast does not fail just on the first failing package, but on the first failing test, so this implementation is incomplete

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough, good catch :)
fixed here I think 2be439e

} else {
io.ErrPrintfln("ok %s \t%s", pkg.Dir, dstr)
}
Expand Down
38 changes: 38 additions & 0 deletions gnovm/cmd/gno/testdata/test/flag_fail-fast.txtar
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this should be named flag_failfast

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Test -failfast flag

! gno test -failfast ./...

! stdout .+
stderr '--- FAIL: TestFail'
stderr 'someError'
! stderr 'secondError'


-- one/failfast.gno --
package one

-- one/failfast_test.gno --
package one

import (
"testing"
)

func TestFail(t *testing.T) {
t.Error("someError")
}

-- two/failfast.gno --
package two

-- two/failfast_test.gno --
package two

import (
"testing"
)

func TestFail2(t *testing.T) {
t.Error("secondError")
}

Loading