The following program sample.go triggers an unexpected result
package main
import (
"testing/fstest"
"github.com/traefik/yaegi/interp"
"github.com/traefik/yaegi/stdlib"
)
var testFilesystem = fstest.MapFS{
"main.go": &fstest.MapFile{
Data: []byte(`package main
import (
"foo/bar"
"./localfoo"
)
func main() {
bar.PrintSomething()
localfoo.PrintSomethingElse()
}
`),
},
`_pkg/src/foo/bar/bar.go`: &fstest.MapFile{
Data: []byte(`package bar
import (
"fmt"
)
func PrintSomething() {
fmt.Println("I am a virtual filesystem printing something from _pkg/src/foo/bar/bar.go!")
}
`),
},
`localfoo/foo.go`: &fstest.MapFile{
Data: []byte(`package localfoo
import (
"fmt"
)
func PrintSomethingElse() {
fmt.Println("I am virtual filesystem printing else from localfoo/foo.go!")
}
`),
},
}
func main() {
i := interp.New(interp.Options{
GoPath: "./_pkg",
SourcecodeFilesystem: testFilesystem,
})
if err := i.Use(stdlib.Symbols); err != nil {
panic(err)
}
_, err := i.EvalPath(`main.go`)
if err != nil {
panic(err)
}
}
Expected result
I am a virtual filesystem printing something from _pkg/src/foo/bar/bar.go!
I am virtual filesystem printing else from localfoo/foo.go!
Got
panic: main.go:4:2: import "foo/bar" error: package location C:\gosrc\src\test not in GOPATH
Yaegi Version
v0.15.1
Additional Notes
fstest uses the character / as the separator, while the internal Interpreter.pkgDir function combines paths with filepath.Join, but on windows, the path separator uses the character \, causing this error.
The following program
sample.go
triggers an unexpected resultExpected result
Got
Yaegi Version
v0.15.1
Additional Notes
fstest
uses the character/
as the separator, while the internalInterpreter.pkgDir
function combines paths withfilepath.Join
, but on windows, the path separator uses the character\
, causing this error.