github.com/switchupcb/yaegi@v0.10.2/example/fs/fs_test.go (about) 1 package fs1 2 3 import ( 4 "testing" 5 6 // only available from 1.16. 7 "testing/fstest" 8 9 "github.com/switchupcb/yaegi/interp" 10 "github.com/switchupcb/yaegi/stdlib" 11 ) 12 13 var testFilesystem = fstest.MapFS{ 14 "main.go": &fstest.MapFile{ 15 Data: []byte(`package main 16 17 import ( 18 "foo/bar" 19 "./localfoo" 20 ) 21 22 func main() { 23 bar.PrintSomething() 24 localfoo.PrintSomethingElse() 25 } 26 `), 27 }, 28 "_pkg/src/foo/bar/bar.go": &fstest.MapFile{ 29 Data: []byte(`package bar 30 31 import ( 32 "fmt" 33 ) 34 35 func PrintSomething() { 36 fmt.Println("I am a virtual filesystem printing something from _pkg/src/foo/bar/bar.go!") 37 } 38 `), 39 }, 40 "localfoo/foo.go": &fstest.MapFile{ 41 Data: []byte(`package localfoo 42 43 import ( 44 "fmt" 45 ) 46 47 func PrintSomethingElse() { 48 fmt.Println("I am virtual filesystem printing else from localfoo/foo.go!") 49 } 50 `), 51 }, 52 } 53 54 func TestFilesystemMapFS(t *testing.T) { 55 i := interp.New(interp.Options{ 56 GoPath: "./_pkg", 57 SourcecodeFilesystem: testFilesystem, 58 }) 59 if err := i.Use(stdlib.Symbols); err != nil { 60 t.Fatal(err) 61 } 62 63 _, err := i.EvalPath(`main.go`) 64 if err != nil { 65 t.Fatal(err) 66 } 67 }