Skip to content
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

Allow *_test.gno file to run pkg with _test as suffix #768

Open
albttx opened this issue Apr 21, 2023 · 2 comments
Open

Allow *_test.gno file to run pkg with _test as suffix #768

albttx opened this issue Apr 21, 2023 · 2 comments

Comments

@albttx
Copy link
Member

albttx commented Apr 21, 2023

Package test with suffix _test not working

✅ This work

package airdrop

import (
	"testing"
)

func TestABC(t *testing.T) {
	println("abc")
}

❌ This fail

package airdrop_test

import (
	"testing"
)

func TestABC(t *testing.T) {
	println("abc")
}

with panic output

panic: package ./examples/gno.land/p/demo/airdrop already exists in cache

goroutine 1 [running]:
github.com/gnolang/gno/gnovm/pkg/gnolang.(*defaultStore).SetCachePackage(0xc0000c2000, 0xc009d5f860)
        /home/albttx/go/src/github.com/gnolang/gno/gnovm/pkg/gnolang/store.go:207 +0x16e
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).RunMemPackage(0xc0092a59e0, 0xc0001fe180, 0x1)
        /home/albttx/go/src/github.com/gnolang/gno/gnovm/pkg/gnolang/machine.go:230 +0x1c6
main.gnoTestPkg({0xc00003ae40, 0x22}, {0xc0000d0210?, 0x1, 0x4?}, {0xc0000d0230, 0x1, 0x5066df?}, 0xc000112600, 0xc0000bc000)
        /home/albttx/go/src/github.com/gnolang/gno/gnovm/cmd/gno/test.go:266 +0x46f
main.execTest(0xc000112600, {0xc000112070, 0x1, 0x1}, 0xc000112060?)
        /home/albttx/go/src/github.com/gnolang/gno/gnovm/cmd/gno/test.go:189 +0xca7
main.newTestCmd.func1({0x0?, 0x0?}, {0xc000112070?, 0x0?, 0x0?})
        /home/albttx/go/src/github.com/gnolang/gno/gnovm/cmd/gno/test.go:46 +0x32
github.com/peterbourgon/ff/v3/ffcli.(*Command).Run(0x2?, {0xef9630?, 0xc000128000?})
        /home/albttx/go/pkg/mod/github.com/peterbourgon/ff/[email protected]/ffcli/command.go:153 +0x16c
github.com/peterbourgon/ff/v3/ffcli.(*Command).Run(0xc000016000?, {0xef9630?, 0xc000128000?})
        /home/albttx/go/pkg/mod/github.com/peterbourgon/ff/[email protected]/ffcli/command.go:157 +0x113
github.com/peterbourgon/ff/v3/ffcli.(*Command).ParseAndRun(0x4055fc?, {0xef9630, 0xc000128000}, {0xc000112050?, 0x401230?, 0x0?})
        /home/albttx/go/pkg/mod/github.com/peterbourgon/ff/[email protected]/ffcli/command.go:169 +0x4f
main.main()
        /home/albttx/go/src/github.com/gnolang/gno/gnovm/cmd/gno/main.go:14 +0x77
exit status 2

To fix this, we can do a test with a main function, but testing with TestFunctionXXX(t *testing.T) would be nice:

NOTE

The function TestFunctionXXX should be considered as a Realm

@tbruyelle
Copy link
Contributor

Directives like // PKGPATH: are not read in _test files, only in _filetest files. Can you remove it from your example for better clarity?

@moul moul added this to the 💡Someday/Maybe milestone Sep 6, 2023
@moul
Copy link
Member

moul commented Oct 9, 2023

Related with #1215.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🔵 Not Needed for Launch
Development

No branches or pull requests

3 participants