Skip to content

Commit

Permalink
fix(gnovm): correct filetest directive behavior (#3697)
Browse files Browse the repository at this point in the history
The test result is misleading. Without an output directive set, the
current logic does not provide a prompt even when actual output occurs.

```go
package main

func main() {
	println("ok")
}

// Error:
// panic xxx
```

## before fix:

=== RUN   TestFiles
=== PAUSE TestFiles
=== CONT  TestFiles
=== RUN   TestFiles/a111.gno
--- PASS: TestFiles (0.14s)
    --- PASS: TestFiles/a111.gno (0.01s)
PASS
ok  	command-line-arguments	1.619s


## after fix:

=== RUN   TestFiles
=== PAUSE TestFiles
=== CONT  TestFiles
=== RUN   TestFiles/a111.gno
    files_test.go:92: unexpected output:
        ok

--- FAIL: TestFiles (0.13s)
    --- FAIL: TestFiles/a111.gno (0.01s)
FAIL
FAIL	command-line-arguments	1.479s
FAIL

---------

Co-authored-by: Morgan <[email protected]>
  • Loading branch information
ltzmaxwell and thehowl authored Feb 6, 2025
1 parent 29c3ee6 commit ce6a4aa
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions gnovm/pkg/test/filetest.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ func (opts *TestOptions) runFiletest(filename string, source []byte) (string, er
// The Error directive (and many others) will have one trailing newline,
// which is not in the output - so add it there.
match(errDirective, result.Error+"\n")
} else if result.Output != "" {
outputDirective := dirs.First(DirectiveOutput)
if outputDirective == nil {
return "", fmt.Errorf("unexpected output:\n%s", result.Output)
}
} else {
err = m.CheckEmpty()
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions gnovm/tests/files/addressable_5.gno
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ func main() {
le := &binary.LittleEndian
println(&le.AppendUint16(b, 0)[0])
}

// Output:
// &(0 <databyte> uint8)
5 changes: 3 additions & 2 deletions gnovm/tests/files/type_alias.gno
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import "gno.land/p/demo/uassert"
type TestingT = uassert.TestingT

func main() {
println(TestingT)
println("ok")
}

// No need for output; not panicking is passing.
// Output:
// ok
2 changes: 2 additions & 0 deletions gnovm/tests/files/types/eql_0f49.gno
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ func main() {

}

// Output:
// true
// true
// true
// true
Expand Down

0 comments on commit ce6a4aa

Please sign in to comment.