From e5650b2dfe812660a019774d82b3237e3e54434b Mon Sep 17 00:00:00 2001 From: Nemanya21 Date: Sun, 5 Jan 2025 21:22:29 +0100 Subject: [PATCH 1/4] feat(test): allow `gno test` to default to the current directory --- gnovm/cmd/gno/test.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/gnovm/cmd/gno/test.go b/gnovm/cmd/gno/test.go index fec0de7c221..6ac6b44da5d 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,16 @@ 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 + for _, arg := range args { + if strings.Contains(arg, "/...") { + io.ErrPrintln("no packages to test") + return nil + } + } + paths = []string{"."} } if cfg.timeout > 0 { From 22803a260a9620613a04f2e7d12315128548aa58 Mon Sep 17 00:00:00 2001 From: Nemanya21 Date: Sun, 5 Jan 2025 21:26:54 +0100 Subject: [PATCH 2/4] ci(test): update CI tests to cover `gno test` default directory behavior --- gnovm/cmd/gno/testdata/test/no_args.txtar | 6 -- .../gno/testdata/test/no_path_empty_dir.txtar | 6 ++ .../gno/testdata/test/no_path_empty_gno.txtar | 8 ++ .../gno/testdata/test/no_path_flag_run.txtar | 99 +++++++++++++++++++ .../test/no_path_valid_filetest.txtar | 26 +++++ .../testdata/test/no_path_valid_test.txtar | 18 ++++ 6 files changed, 157 insertions(+), 6 deletions(-) delete mode 100644 gnovm/cmd/gno/testdata/test/no_args.txtar create mode 100644 gnovm/cmd/gno/testdata/test/no_path_empty_dir.txtar create mode 100644 gnovm/cmd/gno/testdata/test/no_path_empty_gno.txtar create mode 100644 gnovm/cmd/gno/testdata/test/no_path_flag_run.txtar create mode 100644 gnovm/cmd/gno/testdata/test/no_path_valid_filetest.txtar create mode 100644 gnovm/cmd/gno/testdata/test/no_path_valid_test.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_path_empty_dir.txtar b/gnovm/cmd/gno/testdata/test/no_path_empty_dir.txtar new file mode 100644 index 00000000000..6f8b54d7ea4 --- /dev/null +++ b/gnovm/cmd/gno/testdata/test/no_path_empty_dir.txtar @@ -0,0 +1,6 @@ +# Run gno test without path argument on an empty dir + +gno test + +! stdout .+ +stderr '[no test files]' \ No newline at end of file diff --git a/gnovm/cmd/gno/testdata/test/no_path_empty_gno.txtar b/gnovm/cmd/gno/testdata/test/no_path_empty_gno.txtar new file mode 100644 index 00000000000..846ce5bbd88 --- /dev/null +++ b/gnovm/cmd/gno/testdata/test/no_path_empty_gno.txtar @@ -0,0 +1,8 @@ +# Test empty gno without path argument + +gno test + +! stdout .+ +stderr '\? \. \[no test files\]' + +-- empty.gno -- \ No newline at end of file diff --git a/gnovm/cmd/gno/testdata/test/no_path_flag_run.txtar b/gnovm/cmd/gno/testdata/test/no_path_flag_run.txtar new file mode 100644 index 00000000000..542460331bd --- /dev/null +++ b/gnovm/cmd/gno/testdata/test/no_path_flag_run.txtar @@ -0,0 +1,99 @@ +# Run test on gno.land/p/demo/ufmt without path argument + +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) {}) + } +} \ No newline at end of file diff --git a/gnovm/cmd/gno/testdata/test/no_path_valid_filetest.txtar b/gnovm/cmd/gno/testdata/test/no_path_valid_filetest.txtar new file mode 100644 index 00000000000..8ffb8c0a14a --- /dev/null +++ b/gnovm/cmd/gno/testdata/test/no_path_valid_filetest.txtar @@ -0,0 +1,26 @@ +# Test with a valid _filetest.gno file + +gno test + +! stdout .+ +stderr 'ok \. \d\.\d\ds' + +gno test -v + +stdout 'test' +stderr '=== RUN file/valid_filetest.gno' +stderr '--- PASS: file/valid_filetest.gno \(\d\.\d\ds\)' +stderr 'ok \. \d\.\d\ds' + +-- valid.gno -- +package valid + +-- valid_filetest.gno -- +package main + +func main() { + println("test") +} + +// Output: +// test diff --git a/gnovm/cmd/gno/testdata/test/no_path_valid_test.txtar b/gnovm/cmd/gno/testdata/test/no_path_valid_test.txtar new file mode 100644 index 00000000000..9ccf278c92e --- /dev/null +++ b/gnovm/cmd/gno/testdata/test/no_path_valid_test.txtar @@ -0,0 +1,18 @@ +# Test with a valid _test.gno file without path argument + +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 +} \ No newline at end of file From fe529ad96e6c364722d24ce66369af3616e85f21 Mon Sep 17 00:00:00 2001 From: Nemanya8 Date: Thu, 9 Jan 2025 18:16:12 -0500 Subject: [PATCH 3/4] refactor(test): remove redundant tests --- .../gno/testdata/test/no_path_flag_run.txtar | 2 +- .../test/no_path_valid_filetest.txtar | 26 ------------------- .../testdata/test/no_path_valid_test.txtar | 18 ------------- 3 files changed, 1 insertion(+), 45 deletions(-) delete mode 100644 gnovm/cmd/gno/testdata/test/no_path_valid_filetest.txtar delete mode 100644 gnovm/cmd/gno/testdata/test/no_path_valid_test.txtar diff --git a/gnovm/cmd/gno/testdata/test/no_path_flag_run.txtar b/gnovm/cmd/gno/testdata/test/no_path_flag_run.txtar index 542460331bd..3db2a4c9295 100644 --- a/gnovm/cmd/gno/testdata/test/no_path_flag_run.txtar +++ b/gnovm/cmd/gno/testdata/test/no_path_flag_run.txtar @@ -2,7 +2,7 @@ gno test -gno test -v +gno test -v ! stdout .+ stderr '=== RUN TestRun/hello' diff --git a/gnovm/cmd/gno/testdata/test/no_path_valid_filetest.txtar b/gnovm/cmd/gno/testdata/test/no_path_valid_filetest.txtar deleted file mode 100644 index 8ffb8c0a14a..00000000000 --- a/gnovm/cmd/gno/testdata/test/no_path_valid_filetest.txtar +++ /dev/null @@ -1,26 +0,0 @@ -# Test with a valid _filetest.gno file - -gno test - -! stdout .+ -stderr 'ok \. \d\.\d\ds' - -gno test -v - -stdout 'test' -stderr '=== RUN file/valid_filetest.gno' -stderr '--- PASS: file/valid_filetest.gno \(\d\.\d\ds\)' -stderr 'ok \. \d\.\d\ds' - --- valid.gno -- -package valid - --- valid_filetest.gno -- -package main - -func main() { - println("test") -} - -// Output: -// test diff --git a/gnovm/cmd/gno/testdata/test/no_path_valid_test.txtar b/gnovm/cmd/gno/testdata/test/no_path_valid_test.txtar deleted file mode 100644 index 9ccf278c92e..00000000000 --- a/gnovm/cmd/gno/testdata/test/no_path_valid_test.txtar +++ /dev/null @@ -1,18 +0,0 @@ -# Test with a valid _test.gno file without path argument - -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 -} \ No newline at end of file From 606423909fe823e3e6da0f570358af5f0715da61 Mon Sep 17 00:00:00 2001 From: Nemanya21 Date: Tue, 14 Jan 2025 23:42:24 +0100 Subject: [PATCH 4/4] feat(test): remove redundant checks for improved performance --- gnovm/cmd/gno/test.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/gnovm/cmd/gno/test.go b/gnovm/cmd/gno/test.go index 6ac6b44da5d..ea06b25d8e2 100644 --- a/gnovm/cmd/gno/test.go +++ b/gnovm/cmd/gno/test.go @@ -146,6 +146,11 @@ func (c *testCfg) RegisterFlags(fs *flag.FlagSet) { } func execTest(cfg *testCfg, args []string, io commands.IO) error { + // Default to current directory if no args provided + if len(args) == 0 { + args = []string{"."} + } + // guess opts.RootDir if cfg.rootDir == "" { cfg.rootDir = gnoenv.RootDir() @@ -156,15 +161,9 @@ func execTest(cfg *testCfg, args []string, io commands.IO) error { return fmt.Errorf("list targets from patterns: %w", err) } - // 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{"."} + io.ErrPrintln("no packages to test") + return nil } if cfg.timeout > 0 {