forked from gnolang/gno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(gnovm): "*_filetest.gno" instructions (gnolang#1023)
- Loading branch information
Showing
46 changed files
with
816 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,196 +1,11 @@ | ||
package main | ||
|
||
import "testing" | ||
import ( | ||
"testing" | ||
|
||
func TestTest(t *testing.T) { | ||
tc := []testMainCase{ | ||
{ | ||
args: []string{"test"}, | ||
errShouldBe: "flag: help requested", | ||
}, | ||
{ | ||
args: []string{"test", "../../../examples/gno.land/p/demo/rand"}, | ||
stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/rand \t", | ||
}, | ||
{ | ||
args: []string{"test", "../../tests/integ/no-such-dir"}, | ||
errShouldContain: "no such file or directory", | ||
}, | ||
{ | ||
args: []string{"test", "../../tests/integ/empty-dir"}, | ||
stderrShouldContain: "no packages to test", | ||
}, | ||
{ | ||
// FIXME: should have an output | ||
args: []string{"test", "../../tests/integ/minimalist-gno1"}, | ||
stderrShouldBe: "? ./../../tests/integ/minimalist-gno1 \t[no test files]\n", | ||
}, | ||
{ | ||
args: []string{"test", "../../tests/integ/minimalist-gno2"}, | ||
stderrShouldContain: "ok ", | ||
}, | ||
{ | ||
args: []string{"test", "../../tests/integ/minimalist-gno3"}, | ||
stderrShouldContain: "ok ", | ||
}, | ||
{ | ||
args: []string{"test", "--verbose", "../../tests/integ/valid1"}, | ||
stderrShouldContain: "ok ", | ||
}, | ||
{ | ||
args: []string{"test", "../../tests/integ/valid2"}, | ||
stderrShouldContain: "ok ", | ||
}, | ||
{ | ||
args: []string{"test", "--verbose", "../../tests/integ/valid2"}, | ||
stderrShouldContain: "ok ", | ||
}, | ||
{ | ||
args: []string{"test", "../../tests/integ/empty-gno1"}, | ||
stderrShouldBe: "? ./../../tests/integ/empty-gno1 \t[no test files]\n", | ||
}, | ||
{ | ||
args: []string{"test", "--precompile", "../../tests/integ/empty-gno1"}, | ||
errShouldBe: "FAIL: 1 build errors, 0 test errors", | ||
stderrShouldContain: "../../tests/integ/empty-gno1/empty.gno: parse: tmp.gno:1:1: expected 'package', found 'EOF'", | ||
}, | ||
{ | ||
args: []string{"test", "../../tests/integ/empty-gno2"}, | ||
recoverShouldBe: "empty.gno:1:1: expected 'package', found 'EOF'", | ||
}, | ||
{ | ||
// FIXME: better error handling + rename dontcare.gno with actual test file | ||
args: []string{"test", "--precompile", "../../tests/integ/empty-gno2"}, | ||
errShouldContain: "FAIL: 1 build errors, 0 test errors", | ||
stderrShouldContain: "../../tests/integ/empty-gno2/empty.gno: parse: tmp.gno:1:1: expected 'package', found 'EOF'", | ||
}, | ||
{ | ||
args: []string{"test", "../../tests/integ/empty-gno3"}, | ||
recoverShouldBe: "../../tests/integ/empty-gno3/empty_filetest.gno:1:1: expected 'package', found 'EOF'", | ||
}, | ||
{ | ||
// FIXME: better error handling | ||
args: []string{"test", "--precompile", "../../tests/integ/empty-gno3"}, | ||
errShouldContain: "FAIL: 1 build errors, 0 test errors", | ||
stderrShouldContain: "../../tests/integ/empty-gno3/empty.gno: parse: tmp.gno:1:1: expected 'package', found 'EOF'", | ||
}, | ||
{ | ||
args: []string{"test", "--verbose", "../../tests/integ/failing1"}, | ||
errShouldBe: "FAIL: 0 build errors, 1 test errors", | ||
stderrShouldContain: "FAIL: TestAlwaysFailing", | ||
}, | ||
{ | ||
args: []string{"test", "--verbose", "--precompile", "../../tests/integ/failing1"}, | ||
errShouldBe: "FAIL: 0 build errors, 1 test errors", | ||
stderrShouldContain: "FAIL: TestAlwaysFailing", | ||
}, | ||
{ | ||
args: []string{"test", "--verbose", "../../tests/integ/failing2"}, | ||
recoverShouldBe: "fail on ../../tests/integ/failing2/failing_filetest.gno: got unexpected error: beep boop", | ||
stderrShouldContain: "== RUN file/failing_filetest.gno", | ||
}, | ||
{ | ||
args: []string{"test", "--verbose", "--precompile", "../../tests/integ/failing2"}, | ||
stderrShouldBe: "=== PREC ./../../tests/integ/failing2\n=== BUILD ./../../tests/integ/failing2\n=== RUN file/failing_filetest.gno\n", | ||
recoverShouldBe: "fail on ../../tests/integ/failing2/failing_filetest.gno: got unexpected error: beep boop", | ||
}, | ||
{ | ||
args: []string{"test", "../../../examples/gno.land/p/demo/ufmt"}, | ||
stdoutShouldContain: "RUN TestSprintf", | ||
stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", | ||
}, | ||
{ | ||
args: []string{"test", "../../../examples/gno.land/p/demo/ufmt/ufmt_test.gno"}, | ||
stdoutShouldContain: "RUN TestSprintf", | ||
stderrShouldContain: "ok ../../../examples/gno.land/p/demo/ufmt", | ||
}, | ||
{ | ||
args: []string{"test", "--verbose", "../../../examples/gno.land/p/demo/ufmt"}, | ||
stdoutShouldContain: "RUN TestSprintf", | ||
stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", | ||
}, | ||
{ | ||
args: []string{"test", "--verbose", "--run", ".*", "../../../examples/gno.land/p/demo/ufmt"}, | ||
stdoutShouldContain: "RUN TestSprintf", | ||
stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", | ||
}, | ||
{ | ||
args: []string{"test", "--verbose", "--run", "NoExists", "../../../examples/gno.land/p/demo/ufmt"}, | ||
stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", | ||
}, | ||
{ | ||
args: []string{"test", "--verbose", "--run", ".*/hello", "../../../examples/gno.land/p/demo/ufmt"}, | ||
stdoutShouldContain: "RUN TestSprintf", | ||
stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", | ||
}, | ||
{ | ||
args: []string{"test", "--verbose", "--run", ".*/hi", "../../../examples/gno.land/p/demo/ufmt"}, | ||
stdoutShouldContain: "RUN TestSprintf", | ||
stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", | ||
}, | ||
{ | ||
args: []string{"test", "--verbose", "--run", ".*/NoExists", "../../../examples/gno.land/p/demo/ufmt"}, | ||
stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", | ||
}, | ||
{ | ||
args: []string{"test", "--verbose", "--run", ".*/hello/NoExists", "../../../examples/gno.land/p/demo/ufmt"}, | ||
stdoutShouldContain: "RUN TestSprintf", | ||
stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", | ||
}, | ||
{ | ||
args: []string{"test", "--verbose", "--run", "Sprintf/", "../../../examples/gno.land/p/demo/ufmt"}, | ||
stdoutShouldContain: "RUN TestSprintf", | ||
stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", | ||
}, | ||
{ | ||
args: []string{"test", "--verbose", "--run", "Sprintf/.*", "../../../examples/gno.land/p/demo/ufmt"}, | ||
stdoutShouldContain: "RUN TestSprintf", | ||
stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", | ||
}, | ||
{ | ||
args: []string{"test", "--verbose", "--run", "Sprintf/hello", "../../../examples/gno.land/p/demo/ufmt"}, | ||
stdoutShouldContain: "RUN TestSprintf", | ||
stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", | ||
}, | ||
{ | ||
args: []string{"test", "--verbose", "--timeout", "1000000s", "../../../examples/gno.land/p/demo/ufmt"}, | ||
stdoutShouldContain: "RUN TestSprintf", | ||
stderrShouldContain: "ok ./../../../examples/gno.land/p/demo/ufmt", | ||
}, | ||
{ | ||
args: []string{"test", "--verbose", "../../tests/integ/native-lib"}, | ||
recoverShouldContain: "gno.land/r/\\w{8}/contract.gno:1: unknown import path net", | ||
}, | ||
{ | ||
args: []string{"test", "--verbose", "--with-native-fallback", "../../tests/integ/native-lib"}, | ||
stderrShouldContain: "ok ./../../tests/integ/native-lib", | ||
}, | ||
{ | ||
args: []string{"test", "--verbose", "../../tests/integ/unknown-lib"}, | ||
recoverShouldContain: "gno.land/r/\\w{8}/contract.gno:1: unknown import path foobarbaz", | ||
}, | ||
{ | ||
args: []string{"test", "--verbose", "--with-native-fallback", "../../tests/integ/unknown-lib"}, | ||
recoverShouldContain: "gno.land/r/\\w{8}/contract.gno:1: unknown import path foobarbaz", | ||
}, | ||
{ | ||
args: []string{"test", "--verbose", "--print-runtime-metrics", "../../../examples/gno.land/p/demo/ufmt"}, | ||
stdoutShouldContain: "RUN TestSprintf", | ||
stderrShouldContain: "cycle=", | ||
}, | ||
"github.com/rogpeppe/go-internal/testscript" | ||
) | ||
|
||
// TODO: when 'gnodev test' will by default imply running precompile, we should use the following tests. | ||
// {args: []string{"test", "../../tests/integ/empty-gno1", "--no-precompile"}, stderrShouldBe: "? ./../../tests/integ/empty-gno1 \t[no test files]\n"}, | ||
// {args: []string{"test", "../../tests/integ/empty-gno1"}, errShouldBe: "FAIL: 1 build errors, 0 test errors", stderrShouldContain: "../../tests/integ/empty-gno1/empty.gno: parse: tmp.gno:1:1: expected 'package', found 'EOF'"}, | ||
// {args: []string{"test", "../../tests/integ/empty-gno2", "--no-precompile"}, recoverShouldBe: "empty.gno:1:1: expected 'package', found 'EOF'"}, // FIXME: better error handling + rename dontcare.gno with actual test file | ||
// {args: []string{"test", "../../tests/integ/empty-gno2"}, errShouldContain: "FAIL: 1 build errors, 0 test errors", stderrShouldContain: "../../tests/integ/empty-gno2/empty.gno: parse: tmp.gno:1:1: expected 'package', found 'EOF'"}, | ||
// {args: []string{"test", "../../tests/integ/empty-gno3", "--no-precompile"}, recoverShouldBe: "../../tests/integ/empty-gno3/empty_filetest.gno:1:1: expected 'package', found 'EOF'"}, // FIXME: better error handling | ||
// {args: []string{"test", "../../tests/integ/empty-gno3"}, errShouldContain: "FAIL: 1 build errors, 0 test errors", stderrShouldContain: "../../tests/integ/empty-gno3/empty.gno: parse: tmp.gno:1:1: expected 'package', found 'EOF'"}, | ||
// {args: []string{"test", "../../tests/integ/failing1", "--verbose", "--no-precompile"}, errShouldBe: "FAIL: 0 build errors, 1 test errors", stderrShouldContain: "FAIL: TestAlwaysFailing"}, | ||
// {args: []string{"test", "../../tests/integ/failing1", "--verbose"}, errShouldBe: "FAIL: 0 build errors, 1 test errors", stderrShouldContain: "FAIL: TestAlwaysFailing"}, | ||
// {args: []string{"test", "../../tests/integ/failing2", "--verbose", "--no-precompile"}, recoverShouldBe: "fail on ../../tests/integ/failing2/failing_filetest.gno: got unexpected error: beep boop", stderrShouldContain: "== RUN file/failing_filetest.gno"}, | ||
// {args: []string{"test", "../../tests/integ/failing2", "--verbose"}, stderrShouldBe: "=== PREC ./../../tests/integ/failing2\n=== BUILD ./../../tests/integ/failing2\n=== RUN file/failing_filetest.gno\n", recoverShouldBe: "fail on ../../tests/integ/failing2/failing_filetest.gno: got unexpected error: beep boop"}, | ||
// {args: []string{"test", "../../../examples/gno.land/p/demo/ufmt", "--verbose", "--timeout", "10000" /* 10µs */}, recoverShouldContain: "test timed out after"}, // FIXME: should be testable | ||
} | ||
testMainCaseRun(t, tc) | ||
func TestTest(t *testing.T) { | ||
testscript.Run(t, setupTestScript(t, "testdata/gno_test")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Run gno test with a dir that doesn't exists | ||
|
||
! gno test no-such-dir | ||
|
||
! stdout .+ | ||
stderr 'no such file or directory' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Run gno test on an empty dir | ||
|
||
gno test . | ||
|
||
! stdout .+ | ||
stderr 'no packages to test' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Test empty gno1 | ||
|
||
gno test . | ||
|
||
! stdout .+ | ||
stderr '\? \./\. \[no test files\]' | ||
|
||
! gno test --precompile . | ||
|
||
! stdout .+ | ||
stderr 'expected ''package'', found ''EOF''' | ||
|
||
-- empty.gno -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Test empty gno2 | ||
|
||
! gno test . | ||
|
||
! stdout .+ | ||
stderr 'expected ''package'', found ''EOF''' | ||
|
||
! gno test --precompile . | ||
|
||
! stdout .+ | ||
stderr 'expected ''package'', found ''EOF''' | ||
|
||
-- empty.gno -- | ||
-- empty_test.gno -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Test empty gno3 | ||
|
||
! gno test . | ||
|
||
! stdout .+ | ||
stderr 'expected ''package'', found ''EOF''' | ||
|
||
! gno test --precompile . | ||
|
||
! stdout .+ | ||
stderr 'expected ''package'', found ''EOF''' | ||
|
||
-- empty.gno -- | ||
-- empty_filetest.gno -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Test Error instruction correct | ||
|
||
gno test -verbose . | ||
|
||
stdout 'Machine\.RunMain\(\) panic: oups' | ||
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() { | ||
panic("oups") | ||
} | ||
|
||
// Error: | ||
// oups |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Test Error instruction incorrect | ||
|
||
! gno test -verbose . | ||
|
||
stdout 'Machine\.RunMain\(\) panic: oups' | ||
stderr '=== RUN file/x_filetest.gno' | ||
stderr 'panic: fail on x_filetest.gno: got "oups", want: "xxx"' | ||
|
||
-- x_filetest.gno -- | ||
package main | ||
|
||
func main() { | ||
panic("oups") | ||
} | ||
|
||
// Error: | ||
// xxx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Test Error instruction updated | ||
# NOTE: unlike Output and Realm instruction updates, Error update is not driven | ||
# by the '-update-golden-tests' flag. The Error is only updated when it is | ||
# empty. | ||
|
||
! gno test -verbose . | ||
|
||
stdout 'Machine\.RunMain\(\) panic: oups' | ||
stderr '=== RUN file/x_filetest.gno' | ||
|
||
cmp x_filetest.gno x_filetest.gno.golden | ||
|
||
-- x_filetest.gno -- | ||
package main | ||
|
||
func main() { | ||
panic("oups") | ||
} | ||
|
||
// Error: | ||
|
||
-- x_filetest.gno.golden -- | ||
package main | ||
|
||
func main() { | ||
panic("oups") | ||
} | ||
|
||
// Error: | ||
// oups | ||
// *** CHECK THE ERR MESSAGES ABOVE, MAKE SURE IT'S WHAT YOU EXPECTED, DELETE THIS LINE AND RUN TEST AGAIN *** | ||
|
Oops, something went wrong.