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

defer not working in tests #778

Closed
albttx opened this issue Apr 25, 2023 · 0 comments · Fixed by #779
Closed

defer not working in tests #778

albttx opened this issue Apr 25, 2023 · 0 comments · Fixed by #779
Assignees
Labels
🐞 bug Something isn't working

Comments

@albttx
Copy link
Member

albttx commented Apr 25, 2023

Defer not working in tests

Description

see this simple example to reproduce

// bug.gno
package bug

var number int = 0

func SetNumber(n int) {
	number = n
}

func GetNumber() int {
	return number
}

func reset() {
	number = 0
}
// bug_test.gno
package bug

import (
	"testing"
)

func TestSetNumber(t *testing.T) {
	defer reset()
	println(GetNumber())
	SetNumber(42)
	println(GetNumber())
}

Output:

=== RUN   TestSetNumber
0
42
panic: runtime error: index out of range [3] with length 1

goroutine 1 [running]:
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Block).GetPointerToInt(...)
        /home/albttx/go/src/github.com/gnolang/gno/gnovm/pkg/gnolang/values.go:2285
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Block).GetPointerTo(0x0?, {0xf06958, 0xc000196120}, {0xc0?, 0xa5?, 0x4d3?, {0xc000042226?, 0xc004d3a5c0?}})
        /home/albttx/go/src/github.com/gnolang/gno/gnovm/pkg/gnolang/values.go:2319 +0x1aa
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).PopAsPointer(0xc0000d0fc0, {0xefebe8?, 0xc0001c0be0?})
        /home/albttx/go/src/github.com/gnolang/gno/gnovm/pkg/gnolang/machine.go:1788 +0xcf
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).doOpAssign(0xc0000d0fc0)
        /home/albttx/go/src/github.com/gnolang/gno/gnovm/pkg/gnolang/op_assign.go:35 +0x197
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).Run(0xc0000d0fc0)
        /home/albttx/go/src/github.com/gnolang/gno/gnovm/pkg/gnolang/machine.go:1251 +0x14ae
github.com/gnolang/gno/gnovm/pkg/gnolang.(*Machine).Eval(0xc0000d0fc0, {0xefe408, 0xc0092fea20})
        /home/albttx/go/src/github.com/gnolang/gno/gnovm/pkg/gnolang/machine.go:615 +0x572
main.runTestFiles(0xc0000d0fc0?, 0xc0001203c0, {0xc000119db7, 0x3}, 0x1, {0x0, 0x0}, 0xef2cc0?)
        /home/albttx/go/src/github.com/gnolang/gno/gnovm/cmd/gno/test.go:355 +0x41c
main.gnoTestPkg({0xc000124360, 0x1e}, {0xc0001102b0?, 0x1, 0x4?}, {0x0, 0x0, 0x5066df?}, 0xc000112400, 0xc00028c2d0)
        /home/albttx/go/src/github.com/gnolang/gno/gnovm/cmd/gno/test.go:255 +0x394
main.execTest(0xc000112400, {0xc000036070, 0x1, 0x1}, 0xc000036060?)
        /home/albttx/go/src/github.com/gnolang/gno/gnovm/cmd/gno/test.go:189 +0xca7
main.newTestCmd.func1({0x0?, 0x0?}, {0xc000036070?, 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?, {0xef81f0?, 0xc0000420f8?})
        /home/albttx/go/pkg/mod/github.com/peterbourgon/ff/v3@v3.3.0/ffcli/command.go:153 +0x16c
github.com/peterbourgon/ff/v3/ffcli.(*Command).Run(0xc0003d8000?, {0xef81f0?, 0xc0000420f8?})
        /home/albttx/go/pkg/mod/github.com/peterbourgon/ff/v3@v3.3.0/ffcli/command.go:157 +0x113
github.com/peterbourgon/ff/v3/ffcli.(*Command).ParseAndRun(0x4055fc?, {0xef81f0, 0xc0000420f8}, {0xc000036050?, 0x401230?, 0x0?})
        /home/albttx/go/pkg/mod/github.com/peterbourgon/ff/v3@v3.3.0/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
@albttx albttx added the bug label Apr 25, 2023
@albttx albttx self-assigned this Apr 25, 2023
albttx added a commit to albttx/gno that referenced this issue Apr 25, 2023
albttx added a commit to albttx/gno that referenced this issue Apr 26, 2023
@moul moul closed this as completed in #779 Apr 28, 2023
@ajnavarro ajnavarro added 🐞 bug Something isn't working and removed bug labels May 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

2 participants