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(test): handle empty args by assuming current directory for gno test #3429

Closed
wants to merge 6 commits into from
Closed
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
8 changes: 2 additions & 6 deletions gnovm/cmd/gno/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 {
Expand Down
6 changes: 0 additions & 6 deletions gnovm/cmd/gno/testdata/test/no_args.txtar

This file was deleted.

99 changes: 99 additions & 0 deletions gnovm/cmd/gno/testdata/test/no_args_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

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) {})
}
}
21 changes: 21 additions & 0 deletions gnovm/cmd/gno/testdata/test/no_args_output_correct.txtar
Original file line number Diff line number Diff line change
@@ -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?
24 changes: 24 additions & 0 deletions gnovm/cmd/gno/testdata/test/no_args_output_incorrect.txtar
Original file line number Diff line number Diff line change
@@ -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?
24 changes: 24 additions & 0 deletions gnovm/cmd/gno/testdata/test/no_args_unknown_package.txtar
Original file line number Diff line number Diff line change
@@ -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()
}
18 changes: 18 additions & 0 deletions gnovm/cmd/gno/testdata/test/no_args_valid.txtar
Original file line number Diff line number Diff line change
@@ -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
}
Loading