The following program sample.go triggers an unexpected result
// naming is important because of the way the files are sorted when reading the dir
// a.go
package xx
func initializerFunc(x string) string {
return initializerMap[x]
}
// b.go
package xx
var a = initializerFunc("x")
// c.go
package xx
var initializerMap = map[string]string{
"x": "y",
}
// b_test.go
package xx
import "testing"
func TestX(t *testing.T) {
t.Logf(a)
if a != "y" {
panic("invalid")
}
}
Expected result
$ go test -v .
=== RUN TestX
b_test.go:6: y
--- PASS: TestX (0.00s)
PASS
ok yaegi/tst 0.001s
The following program
sample.go
triggers an unexpected resultExpected result
Got
Yaegi Version
0.15.1
Additional Notes
Originally discovered by trying to run
yaegi test
on https://github.com/notnil/chess .A caveat is that this bug's behaviour is dependent on the alphabetic ordering of the file. Doing
mv c.go 0.go
leads to the tests succeeding