-
Notifications
You must be signed in to change notification settings - Fork 386
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): allow gno test to default to the current directory #3453
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
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]' |
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 -- |
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) {}) | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say this and the following test ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed those two tests. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you make it work by simply putting
args
as[]string{"."}
when it's empty? The current approach, verifyingpaths
, looks a bit hacky.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Putting
args
as[]string{"."}
when it's empty works for simple cases likegno test
, but it falls apart once you add flags, becauseargs
won't be empty anymore.I also have to check if
./...
is inargs
, since when you run a command with./...
and no matching packages are found, the paths end up with a length of 0. That would incorrectly make it look like there are no path args, which is a false positive.So while verifying paths might seem a bit clunky, it’s necessary to handle all these edge cases properly.