Skip to content

feat(cmd/gno): allow gno test to default to the current directory #3453

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

Merged
merged 5 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions gnovm/cmd/gno/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,9 @@ func (c *testCfg) RegisterFlags(fs *flag.FlagSet) {
}

func execTest(cfg *testCfg, args []string, io commands.IO) error {
if len(args) < 1 {
return flag.ErrHelp
// Default to current directory if no args provided
if len(args) == 0 {
args = []string{"."}
}

// guess opts.RootDir
Expand All @@ -159,6 +160,7 @@ func execTest(cfg *testCfg, args []string, io commands.IO) error {
if err != nil {
return fmt.Errorf("list targets from patterns: %w", err)
}

if len(paths) == 0 {
io.ErrPrintln("no packages to test")
return nil
Expand Down
6 changes: 0 additions & 6 deletions gnovm/cmd/gno/testdata/test/no_args.txtar

This file was deleted.

6 changes: 6 additions & 0 deletions gnovm/cmd/gno/testdata/test/no_path_empty_dir.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Run gno test without path argument on an empty dir

gno test

! stdout .+
stderr '[no test files]'
8 changes: 8 additions & 0 deletions gnovm/cmd/gno/testdata/test/no_path_empty_gno.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Test empty gno without path argument

gno test

! stdout .+
stderr '\? \. \[no test files\]'

-- empty.gno --
99 changes: 99 additions & 0 deletions gnovm/cmd/gno/testdata/test/no_path_flag_run.txtar
Original file line number Diff line number Diff line change
@@ -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) {})
}
}
Loading