gnolang / gno

Gno: An interpreted, stack-based Go virtual machine to build succinct and composable apps + Gno.land: a blockchain for timeless code and fair open-source
https://gno.land/
Other
844 stars 344 forks source link

Panics not shown (when _testfile); tests that panic this way are shown as passed #615

Closed grepsuzette closed 1 year ago

grepsuzette commented 1 year ago

(posting this as a separate issue, but related to #481. Edit: only related because it makes #481 important to fix)

If I use _filetest, gnodev test pass, even when it's supposed to fail (t.Fail()).

Apparent cause: It in fact panics internally, but regardless of whether tests are supposed to fail, it will always pass (it likely recovers too optimistically, bug 2, where the cause of the panic is bug 1).

One example could be this:

package mail
import "testing"
func TestIt(t *testing.T) {}

Or that:

package mail
import "testing"
func TestIt(t *testing.T) { t.Fail() }

Whatever, it will always pass.

Without -verbose, e.g. gnodev test -root-dir ./gno .:

ok ./. 0.00s

With -verbose:

OUTPUT:

goroutine 1 [running]:
runtime/debug.Stack()
        /usr/lib/go/src/runtime/debug/stack.go:24 +0x65
runtime/debug.PrintStack()
        /usr/lib/go/src/runtime/debug/stack.go:16 +0x19
github.com/gnolang/gno/tests.RunFileTest.func1.1()
        /home/gus/code/gno_realms/gno/tests/file.go:133 +0x16e
panic({0xbaf840, 0xc004654c10})
        /usr/lib/go/src/runtime/panic.go:884 +0x213
github.com/gnolang/gno/pkgs/gnolang.(*Machine).runFiles(0xc00c2fd9e0, {0xc00049d3c8, 0x1, 0x1})
        /home/gus/code/gno_realms/gno/pkgs/gnolang/machine.go:340 +0xb65
github.com/gnolang/gno/pkgs/gnolang.(*Machine).RunFiles(...)
        /home/gus/code/gno_realms/gno/pkgs/gnolang/machine.go:332
github.com/gnolang/gno/tests.RunFileTest.func1(0x1?, 0xc00ae7d720?, {0x0?, 0xc000036180?}, 0xc005915bd8, {0xcb087d, 0x4}, {0xcb087d, 0x4}, {0xdec6f8, ...}, ...)
        /home/gus/code/gno_realms/gno/tests/file.go:156 +0x8a5
github.com/gnolang/gno/tests.RunFileTest({0x7ffcd6498ca3, 0x7}, {0xc006a928a0, 0x14}, {0xc00ae7da08, 0x1, 0x0?})
        /home/gus/code/gno_realms/gno/tests/file.go:230 +0x388
main.gnoTestPkg({0xc00028f06a, 0x3}, {0xc0002950c0?, 0x1, 0x4?}, {0xc0002950e0, 0x1, 0xc000295040?}, 0xc000298600, 0xc000201c70)
        /home/gus/code/gno_realms/gno/cmd/gnodev/test.go:294 +0x6e7
main.execTest(0xc000298600, {0xc000036230, 0x1, 0x1}, 0xc000036200?)
        /home/gus/code/gno_realms/gno/cmd/gnodev/test.go:189 +0xb67
main.newTestCmd.func1({0x0?, 0x0?}, {0xc000036230?, 0x0?, 0x0?})
        /home/gus/code/gno_realms/gno/cmd/gnodev/test.go:46 +0x32
github.com/peterbourgon/ff/v3/ffcli.(*Command).Run(0x4?, {0xddda88?, 0xc00003a140?})
        /home/gus/code/go/pkg/mod/github.com/peterbourgon/ff/v3@v3.3.0/ffcli/command.go:153 +0x16c
github.com/peterbourgon/ff/v3/ffcli.(*Command).Run(0xc0000003c0?, {0xddda88?, 0xc00003a140?})
        /home/gus/code/go/pkg/mod/github.com/peterbourgon/ff/v3@v3.3.0/ffcli/command.go:157 +0x113
github.com/peterbourgon/ff/v3/ffcli.(*Command).ParseAndRun(0x4059dc?, {0xddda88, 0xc00003a140}, {0xc0000361f0?, 0x401240?, 0x0?})
        /home/gus/code/go/pkg/mod/github.com/peterbourgon/ff/v3@v3.3.0/ffcli/command.go:169 +0x4f
main.main()
        /home/gus/code/gno_realms/gno/cmd/gnodev/main.go:14 +0x77
--- PASS: file/install_filetest.gno (0.00s)
ok      ./.     1.70s
grepsuzette commented 1 year ago

The panic advertised at gno/pkgs/gnolang/machine.go:340 is this one

func (m *Machine) runFiles(fns ...*FileNode) {
    // Files' package names must match the machine's active one.
    // if there is one.
    for _, fn := range fns {
        if fn.PkgName != "" && fn.PkgName != m.Package.PkgName {
            panic(fmt.Sprintf("expected package name [%s] but got [%s]",
                m.Package.PkgName, fn.PkgName))
        }
    }

The message never shows through.

--

Addendum: Looks like one does not use a _filetest like I did but with a main instead:

// PKGPATH: gno.land/r/boards_test
package boards_test

func main() {}                                       

Still same outout with -verbose. I'll go on investigating.

grepsuzette commented 1 year ago

It was me who didn't understandj what a filetest was and how to use it. Closing this, sorry.