Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thehowl committed Nov 14, 2024
1 parent 3bf22fb commit 6f90e23
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 89 deletions.
16 changes: 11 additions & 5 deletions gnovm/cmd/gno/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"flag"
"fmt"
goio "io"
"log"
"math"
"os"
Expand Down Expand Up @@ -334,7 +335,13 @@ func gnoTestPkg(
// testing with *_filetest.gno
{
var opts test.FileTestOptions
opts.BaseStore, opts.Store = test.TestStore(rootDir, false, os.Stdin, &opts.Stdout, &opts.Stdout)
gnoOut, gnoErr := opts.Stdout(), goio.Discard
if verbose {
gnoOut = goio.MultiWriter(gnoOut, stdout)
gnoErr = stderr
opts.Output = gnoOut
}
opts.BaseStore, opts.Store = test.TestStore(rootDir, false, os.Stdin, gnoOut, gnoErr)

filter := splitRegexp(runFlag)
for _, testFile := range filetestFiles {
Expand Down Expand Up @@ -369,15 +376,14 @@ func gnoTestPkg(
}
duration := time.Since(startedAt)
dstr := fmtDuration(duration)
if verbose {
io.Out().Write(opts.Stdout.Bytes())
}
if err != nil {
io.ErrPrintln(err.Error())
io.ErrPrintfln("--- FAIL: %s (%s)", testName, dstr)
io.ErrPrintln(err.Error())
errs = multierr.Append(errs, fmt.Errorf("%s failed", testName))
} else if verbose {
io.ErrPrintfln("--- PASS: %s (%s)", testName, dstr)
}

// XXX: add per-test metrics
}
}
Expand Down
1 change: 0 additions & 1 deletion gnovm/cmd/gno/testdata/gno_test/error_correct.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

gno test -v .

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'
Expand Down
5 changes: 3 additions & 2 deletions gnovm/cmd/gno/testdata/gno_test/error_incorrect.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

! gno test -v .

stdout 'Machine\.RunMain\(\) panic: oups'
stderr '=== RUN file/x_filetest.gno'
stderr 'panic: fail on x_filetest.gno: got "oups", want: "xxx"'
stderr 'Error diff:'
stderr '-xxx'
stderr '\+oups'

-- x_filetest.gno --
package main
Expand Down
7 changes: 2 additions & 5 deletions gnovm/cmd/gno/testdata/gno_test/error_sync.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
# by the '-update-golden-tests' flag. The Error is only updated when it is
# empty.

! gno test -v .
gno test -update-golden-tests -v .

stdout 'Machine\.RunMain\(\) panic: oups'
! stdout .+
stderr '=== RUN file/x_filetest.gno'

cmp x_filetest.gno x_filetest.gno.golden
Expand All @@ -18,7 +18,6 @@ func main() {
}

// Error:

-- x_filetest.gno.golden --
package main

Expand All @@ -28,5 +27,3 @@ func main() {

// Error:
// oups
// *** CHECK THE ERR MESSAGES ABOVE, MAKE SURE IT'S WHAT YOU EXPECTED, DELETE THIS LINE AND RUN TEST AGAIN ***

3 changes: 1 addition & 2 deletions gnovm/cmd/gno/testdata/gno_test/failing_filetest.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

! gno test -v .

stdout 'Machine.RunMain\(\) panic: beep boop'
stderr '=== RUN file/failing_filetest.gno'
stderr 'panic: fail on failing_filetest.gno: got unexpected error: beep boop'
stderr 'unexpected panic: beep boop'

-- failing.gno --
package failing
Expand Down
2 changes: 1 addition & 1 deletion gnovm/cmd/gno/testdata/gno_test/filetest_events.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ stderr 'ok \. \d\.\d\ds'

gno test -print-events -v .

! stdout .+
stdout 'test'
stderr '=== RUN file/valid_filetest.gno'
stderr '--- PASS: file/valid_filetest.gno \(\d\.\d\ds\)'
stderr 'ok \. \d\.\d\ds'
Expand Down
3 changes: 2 additions & 1 deletion gnovm/cmd/gno/testdata/gno_test/output_correct.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

gno test -v .

! stdout .+ # stdout should be empty
stdout 'hey'
stdout 'hru?'
stderr '=== RUN file/x_filetest.gno'
stderr '--- PASS: file/x_filetest.gno \(\d\.\d\ds\)'
stderr 'ok \. \d\.\d\ds'
Expand Down
7 changes: 4 additions & 3 deletions gnovm/cmd/gno/testdata/gno_test/output_incorrect.txtar
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# Test Output instruction incorrect

# with -v, stdout should contain output (unmodified).
! gno test -v .

! stdout .+ # stdout should be empty
stdout 'hey'

stderr '=== RUN file/x_filetest.gno'
stderr 'panic: fail on x_filetest.gno: diff:'
stderr '--- Expected'
stderr '\+\+\+ Actual'
stderr '@@ -1,2 \+1 @@'
stderr '@@ -1,3 \+1,2 @@'
stderr 'hey'
stderr '-hru?'

Expand Down
6 changes: 3 additions & 3 deletions gnovm/cmd/gno/testdata/gno_test/output_sync.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

gno test -v . -update-golden-tests

! stdout .+ # stdout should be empty
stdout 'hey'
stdout '^hru\?'

stderr '=== RUN file/x_filetest.gno'
stderr '--- PASS: file/x_filetest.gno \(\d\.\d\ds\)'
stderr 'ok \. \d\.\d\ds'
Expand All @@ -19,7 +21,6 @@ func main() {

// Output:
// hey

-- x_filetest.gno.golden --
package main

Expand All @@ -31,4 +32,3 @@ func main() {
// Output:
// hey
// hru?

3 changes: 2 additions & 1 deletion gnovm/cmd/gno/testdata/gno_test/pkg_underscore_test.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ func main() {
println("filetest " + hello.Name)
}

// Output: filetest foo
// Output:
// filetest foo
5 changes: 2 additions & 3 deletions gnovm/cmd/gno/testdata/gno_test/realm_correct.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func main() {
// "Escaped": true,
// "ObjectID": "58cde29876a8d185e30c727361981efb068f4726:3"
// },
// "FileName": "main.gno",
// "FileName": "x.gno",
// "IsMethod": false,
// "Name": "main",
// "NativeName": "",
Expand All @@ -70,7 +70,7 @@ func main() {
// "BlockNode": null,
// "Location": {
// "Column": "1",
// "File": "main.gno",
// "File": "x.gno",
// "Line": "6",
// "PkgPath": "gno.land/r/x"
// }
Expand All @@ -84,4 +84,3 @@ func main() {
// }
// ]
// }

6 changes: 3 additions & 3 deletions gnovm/cmd/gno/testdata/gno_test/realm_incorrect.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

! stdout .+ # stdout should be empty
stderr '=== RUN file/x_filetest.gno'
stderr 'panic: fail on x_filetest.gno: diff:'
stderr 'Realm diff:'
stderr '--- Expected'
stderr '\+\+\+ Actual'
stderr '@@ -1 \+1,66 @@'
stderr '@@ -1,2 \+1,67 @@'
stderr '-xxx'
stderr '\+switchrealm\["gno.land/r/x"\]'
stderr 'x_filetest.gno failed'

-- x_filetest.gno --
// PKGPATH: gno.land/r/x
Expand All @@ -23,4 +24,3 @@ func main() {

// Realm:
// xxxx

6 changes: 2 additions & 4 deletions gnovm/cmd/gno/testdata/gno_test/realm_sync.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func main() {

// Realm:
// xxx

-- x_filetest.gno.golden --
// PKGPATH: gno.land/r/x
package x
Expand Down Expand Up @@ -74,7 +73,7 @@ func main() {
// "Escaped": true,
// "ObjectID": "58cde29876a8d185e30c727361981efb068f4726:3"
// },
// "FileName": "main.gno",
// "FileName": "x.gno",
// "IsMethod": false,
// "Name": "main",
// "NativeName": "",
Expand All @@ -85,7 +84,7 @@ func main() {
// "BlockNode": null,
// "Location": {
// "Column": "1",
// "File": "main.gno",
// "File": "x.gno",
// "Line": "6",
// "PkgPath": "gno.land/r/x"
// }
Expand All @@ -99,4 +98,3 @@ func main() {
// }
// ]
// }

32 changes: 0 additions & 32 deletions gnovm/cmd/gno/testdata/gno_test/test_with-native-fallback.txtar

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
stderr 'panic: unknown import path foobarbaz \[recovered\]'
stderr ' panic: gno.land/r/\w{8}/contract.gno:3:8: unknown import path foobarbaz'

! gno test -v --with-native-fallback .

! stdout .+
stderr 'panic: unknown import path foobarbaz \[recovered\]'
stderr ' panic: gno.land/r/\w{8}/contract.gno:3:8: unknown import path foobarbaz'

-- contract.gno --
package contract

Expand All @@ -29,4 +23,3 @@ import "testing"
func TestFoo(t *testing.T) {
Foo()
}

2 changes: 1 addition & 1 deletion gnovm/cmd/gno/testdata/gno_test/valid_filetest.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ stderr 'ok \. \d\.\d\ds'

gno test -v .

! stdout .+
stdout 'test'
stderr '=== RUN file/valid_filetest.gno'
stderr '--- PASS: file/valid_filetest.gno \(\d\.\d\ds\)'
stderr 'ok \. \d\.\d\ds'
Expand Down
9 changes: 6 additions & 3 deletions gnovm/pkg/gnolang/files_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package gnolang_test

import (
"bytes"
"flag"
"fmt"
"io"
"io/fs"
"os"
"path/filepath"
Expand All @@ -16,6 +16,10 @@ import (

var withSync = flag.Bool("update-golden-tests", false, "rewrite tests updating Realm: and Output: with new values where changed")

type nopReader struct{}

func (nopReader) Read(p []byte) (int, error) { return 0, io.EOF }

// TestFiles tests all the files in "gnovm/tests/files".
//
// Cheatsheet:
Expand All @@ -30,8 +34,7 @@ func TestFiles(t *testing.T) {
rootDir, err := filepath.Abs("../../../")
require.NoError(t, err)
var opts test.FileTestOptions
var stdin, stderr bytes.Buffer
opts.BaseStore, opts.Store = test.TestStore(rootDir, true, &stdin, &opts.Stdout, &stderr)
opts.BaseStore, opts.Store = test.TestStore(rootDir, true, nopReader{}, opts.Stdout(), io.Discard)
// XXX: Using opts like this is a bit funky, replacing the state each time; maybe we can re-create each time
// if we don't require usage of opts.Stdout.

Expand Down
Loading

0 comments on commit 6f90e23

Please sign in to comment.