diff --git a/gnovm/cmd/gno/test.go b/gnovm/cmd/gno/test.go index fec0de7c221..369e7588b08 100644 --- a/gnovm/cmd/gno/test.go +++ b/gnovm/cmd/gno/test.go @@ -146,10 +146,6 @@ func (c *testCfg) RegisterFlags(fs *flag.FlagSet) { } func execTest(cfg *testCfg, args []string, io commands.IO) error { - if len(args) < 1 { - return flag.ErrHelp - } - // guess opts.RootDir if cfg.rootDir == "" { cfg.rootDir = gnoenv.RootDir() @@ -159,9 +155,9 @@ func execTest(cfg *testCfg, args []string, io commands.IO) error { if err != nil { return fmt.Errorf("list targets from patterns: %w", err) } + // Assume current directory if no paths are provided if len(paths) == 0 { - io.ErrPrintln("no packages to test") - return nil + paths = []string{"."} } if cfg.timeout > 0 { diff --git a/gnovm/cmd/gno/testdata/test/no_args.txtar b/gnovm/cmd/gno/testdata/test/no_args.txtar deleted file mode 100644 index bd9cd4fc965..00000000000 --- a/gnovm/cmd/gno/testdata/test/no_args.txtar +++ /dev/null @@ -1,6 +0,0 @@ -# Run gno test without args - -! gno test - -! stdout .+ -stderr 'USAGE' diff --git a/gnovm/cmd/gno/testdata/test/no_args_flag_run.txtar b/gnovm/cmd/gno/testdata/test/no_args_flag_run.txtar new file mode 100644 index 00000000000..243791ec9f7 --- /dev/null +++ b/gnovm/cmd/gno/testdata/test/no_args_flag_run.txtar @@ -0,0 +1,99 @@ +# Run test on gno.land/p/demo/ufmt + +gno test + +gno test -v + +! stdout .+ +stderr '=== RUN TestRun/hello' +stderr '=== RUN TestRun/hi_you' +stderr '=== RUN TestRun/hi_me' +stderr '=== RUN TestRun' +stderr '--- PASS: TestRun' + +gno test -v -run .* + +! stdout .+ +stderr '=== RUN TestRun/hello' +stderr '=== RUN TestRun/hi_you' +stderr '=== RUN TestRun/hi_me' +stderr '=== RUN TestRun' +stderr '--- PASS: TestRun' + +gno test -v -run NotExists + +! stdout .+ +! stderr '=== RUN TestRun' + +gno test -v -run .*/hello + +! stdout .+ +stderr '=== RUN TestRun/hello' +! stderr '=== RUN TestRun/hi_you' +! stderr '=== RUN TestRun/hi_me' +stderr '=== RUN TestRun' +stderr '--- PASS: TestRun' + +gno test -v -run .*/hi + +! stdout .+ +! stderr '=== RUN TestRun/hello' +stderr '=== RUN TestRun/hi_you' +stderr '=== RUN TestRun/hi_me' +stderr '=== RUN TestRun' +stderr '--- PASS: TestRun' + +gno test -v -run .*/NotExists + +! stdout .+ +stderr '=== RUN TestRun' +stderr '--- PASS: TestRun' + +gno test -v -run Run/.* + +! stdout .+ +stderr '=== RUN TestRun/hello' +stderr '=== RUN TestRun/hi_you' +stderr '=== RUN TestRun/hi_me' +stderr '=== RUN TestRun' +stderr '--- PASS: TestRun' + +gno test -v -run Run/ + +! stdout .+ +stderr '=== RUN TestRun/hello' +stderr '=== RUN TestRun/hi_you' +stderr '=== RUN TestRun/hi_me' +stderr '=== RUN TestRun' +stderr '--- PASS: TestRun' + +gno test -v -run Run/hello + +! stdout .+ +stderr '=== RUN TestRun/hello' +! stderr '=== RUN TestRun/hi_you' +! stderr '=== RUN TestRun/hi_me' +stderr '=== RUN TestRun' +stderr '--- PASS: TestRun' + +-- run.gno -- +package run + +-- run_test.gno -- +package run + +import ( + "fmt" + "testing" +) + +func TestRun(t *testing.T) { + cases := []string { + "hello", + "hi you", + "hi me", + } + for _, tc := range cases { + t.Run(tc, func(t *testing.T) {}) + } +} diff --git a/gnovm/cmd/gno/testdata/test/no_args_output_correct.txtar b/gnovm/cmd/gno/testdata/test/no_args_output_correct.txtar new file mode 100644 index 00000000000..b6377cff571 --- /dev/null +++ b/gnovm/cmd/gno/testdata/test/no_args_output_correct.txtar @@ -0,0 +1,21 @@ +# Test Output instruction correct without path arguments + +gno test -v + +stdout 'hey' +stdout 'hru?' +stderr '=== RUN file/x_filetest.gno' +stderr '--- PASS: file/x_filetest.gno \(\d\.\d\ds\)' +stderr 'ok \. \d\.\d\ds' + +-- x_filetest.gno -- +package main + +func main() { + println("hey") + println("hru?") +} + +// Output: +// hey +// hru? diff --git a/gnovm/cmd/gno/testdata/test/no_args_output_incorrect.txtar b/gnovm/cmd/gno/testdata/test/no_args_output_incorrect.txtar new file mode 100644 index 00000000000..ff8e0fa42c5 --- /dev/null +++ b/gnovm/cmd/gno/testdata/test/no_args_output_incorrect.txtar @@ -0,0 +1,24 @@ +# Test Output instruction incorrect without path arguments + +# with -v, stdout should contain output (unmodified). +! gno test -v + +stdout 'hey' + +stderr '=== RUN file/x_filetest.gno' +stderr '--- Expected' +stderr '\+\+\+ Actual' +stderr '@@ -1,3 \+1,2 @@' +stderr 'hey' +stderr '-hru?' + +-- x_filetest.gno -- +package main + +func main() { + println("hey") +} + +// Output: +// hey +// hru? diff --git a/gnovm/cmd/gno/testdata/test/no_args_unknown_package.txtar b/gnovm/cmd/gno/testdata/test/no_args_unknown_package.txtar new file mode 100644 index 00000000000..e9334b40d30 --- /dev/null +++ b/gnovm/cmd/gno/testdata/test/no_args_unknown_package.txtar @@ -0,0 +1,24 @@ +# Test for loading an unknown package without path arguments + +! gno test -v + +! stdout .+ +stderr 'contract.gno:3:8: unknown import path foobarbaz' + +-- contract.gno -- +package contract + +import "foobarbaz" + +func Foo() { + _ = foobarbaz.Gnognogno +} + +-- contract_test.gno -- +package contract + +import "testing" + +func TestFoo(t *testing.T) { + Foo() +} diff --git a/gnovm/cmd/gno/testdata/test/no_args_valid.txtar b/gnovm/cmd/gno/testdata/test/no_args_valid.txtar new file mode 100644 index 00000000000..df295aab7d8 --- /dev/null +++ b/gnovm/cmd/gno/testdata/test/no_args_valid.txtar @@ -0,0 +1,18 @@ +# Run valid gno test without args + +! gno test + +! stdout .+ +stderr 'ok \. \d\.\d\ds' + +-- valid.gno -- +package valid + +-- valid_test.gno -- +package valid + +import "testing" + +func TestAlwaysValid(t *testing.T) { + // noop test +}