From 4cb597b6fa9d40e8becd3ab8beb02d44b3447de8 Mon Sep 17 00:00:00 2001 From: Nemanya8 Date: Mon, 30 Dec 2024 12:08:26 -0500 Subject: [PATCH 1/6] fix(test): handle empty args by assuming current directory for gno test --- gnovm/cmd/gno/test.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/gnovm/cmd/gno/test.go b/gnovm/cmd/gno/test.go index fec0de7c221..59ecb6550a2 100644 --- a/gnovm/cmd/gno/test.go +++ b/gnovm/cmd/gno/test.go @@ -146,9 +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 == "" { @@ -159,9 +156,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 { From 0cc40e50e203204dea3a5e0a1fb0986957c7c094 Mon Sep 17 00:00:00 2001 From: Nemanya8 Date: Mon, 30 Dec 2024 12:33:58 -0500 Subject: [PATCH 2/6] fix(test): remove unnecessary blank line in execTest function --- gnovm/cmd/gno/test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/gnovm/cmd/gno/test.go b/gnovm/cmd/gno/test.go index 59ecb6550a2..369e7588b08 100644 --- a/gnovm/cmd/gno/test.go +++ b/gnovm/cmd/gno/test.go @@ -146,7 +146,6 @@ func (c *testCfg) RegisterFlags(fs *flag.FlagSet) { } func execTest(cfg *testCfg, args []string, io commands.IO) error { - // guess opts.RootDir if cfg.rootDir == "" { cfg.rootDir = gnoenv.RootDir() From 68ea721442df74bc8855a9a52c55ecc57ab6693b Mon Sep 17 00:00:00 2001 From: Nemanya8 Date: Mon, 30 Dec 2024 13:25:15 -0500 Subject: [PATCH 3/6] fix(test): handle case where args contain "/..." --- gnovm/cmd/gno/test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gnovm/cmd/gno/test.go b/gnovm/cmd/gno/test.go index 369e7588b08..c5190632dbb 100644 --- a/gnovm/cmd/gno/test.go +++ b/gnovm/cmd/gno/test.go @@ -157,6 +157,12 @@ func execTest(cfg *testCfg, args []string, io commands.IO) error { } // Assume current directory if no paths are provided if len(paths) == 0 { + for _, arg := range args { + if strings.Contains(arg, "/...") { + io.ErrPrintln("no packages to test") + return nil + } + } paths = []string{"."} } From 58695867b5f9f9d24a7fc148c0c70c30917231ce Mon Sep 17 00:00:00 2001 From: Nemanya21 Date: Fri, 3 Jan 2025 23:51:07 +0100 Subject: [PATCH 4/6] Add new tests for gno test without path arg --- gnovm/cmd/gno/testdata/test/no_args.txtar | 6 -- .../gno/testdata/test/no_args_flag_run.txtar | 99 +++++++++++++++++++ .../test/no_args_output_correct.txtar | 21 ++++ .../test/no_args_output_incorrect.txtar | 24 +++++ .../test/no_args_unknown_package.txtar | 24 +++++ .../cmd/gno/testdata/test/no_args_valid.txtar | 18 ++++ 6 files changed, 186 insertions(+), 6 deletions(-) delete mode 100644 gnovm/cmd/gno/testdata/test/no_args.txtar create mode 100644 gnovm/cmd/gno/testdata/test/no_args_flag_run.txtar create mode 100644 gnovm/cmd/gno/testdata/test/no_args_output_correct.txtar create mode 100644 gnovm/cmd/gno/testdata/test/no_args_output_incorrect.txtar create mode 100644 gnovm/cmd/gno/testdata/test/no_args_unknown_package.txtar create mode 100644 gnovm/cmd/gno/testdata/test/no_args_valid.txtar 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..a3838927c15 --- /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 +} From da8d9cb4433f3e2ceffd3d9647d96c1b80c95f69 Mon Sep 17 00:00:00 2001 From: Nemanya21 Date: Sat, 4 Jan 2025 00:44:36 +0100 Subject: [PATCH 5/6] Revert "fix(test): handle case where args contain "/..."" This reverts commit 68ea721442df74bc8855a9a52c55ecc57ab6693b. --- gnovm/cmd/gno/test.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/gnovm/cmd/gno/test.go b/gnovm/cmd/gno/test.go index c5190632dbb..369e7588b08 100644 --- a/gnovm/cmd/gno/test.go +++ b/gnovm/cmd/gno/test.go @@ -157,12 +157,6 @@ func execTest(cfg *testCfg, args []string, io commands.IO) error { } // Assume current directory if no paths are provided if len(paths) == 0 { - for _, arg := range args { - if strings.Contains(arg, "/...") { - io.ErrPrintln("no packages to test") - return nil - } - } paths = []string{"."} } From 54094717ce90752c6a85bfb6a0ecad056221b2b9 Mon Sep 17 00:00:00 2001 From: Nemanya21 Date: Sun, 5 Jan 2025 02:48:08 +0100 Subject: [PATCH 6/6] testing CI --- gnovm/cmd/gno/testdata/test/no_args_valid.txtar | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnovm/cmd/gno/testdata/test/no_args_valid.txtar b/gnovm/cmd/gno/testdata/test/no_args_valid.txtar index a3838927c15..df295aab7d8 100644 --- a/gnovm/cmd/gno/testdata/test/no_args_valid.txtar +++ b/gnovm/cmd/gno/testdata/test/no_args_valid.txtar @@ -14,5 +14,5 @@ package valid import "testing" func TestAlwaysValid(t *testing.T) { - // noop + // noop test }