| 1 | package fs1scip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/example/fs`/ |
| 2 | |
| 3 | import ( |
| 4 | "testingscip-go gomod github.com/golang/go/src go1.21 testing/" |
| 5 | "testing/fstestscip-go gomod github.com/golang/go/src go1.21 `testing/fstest`/" // only available from 1.16. |
| 6 | |
| 7 | "github.com/traefik/yaegi/interpscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/" |
| 8 | "github.com/traefik/yaegi/stdlibscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/stdlib`/" |
| 9 | ) |
| 10 | |
| 11 | var testFilesystemscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/example/fs`/testFilesystem. = fstestscip-go gomod github.com/golang/go/src go1.21 `testing/fstest`/.MapFSscip-go gomod github.com/golang/go/src go1.21 `testing/fstest`/MapFS#{ |
| 12 | "main.go": &fstestscip-go gomod github.com/golang/go/src go1.21 `testing/fstest`/.MapFilescip-go gomod github.com/golang/go/src go1.21 `testing/fstest`/MapFile#{ |
| 13 | Datascip-go gomod github.com/golang/go/src go1.21 `testing/fstest`/MapFile#Data.: []byte(`package main |
| 14 | |
| 15 | import ( |
| 16 | "foo/bar" |
| 17 | "./localfoo" |
| 18 | ) |
| 19 | |
| 20 | func main() { |
| 21 | bar.PrintSomething() |
| 22 | localfoo.PrintSomethingElse() |
| 23 | } |
| 24 | `), |
| 25 | }, |
| 26 | "_pkg/src/foo/bar/bar.go": &fstestscip-go gomod github.com/golang/go/src go1.21 `testing/fstest`/.MapFilescip-go gomod github.com/golang/go/src go1.21 `testing/fstest`/MapFile#{ |
| 27 | Datascip-go gomod github.com/golang/go/src go1.21 `testing/fstest`/MapFile#Data.: []byte(`package bar |
| 28 | |
| 29 | import ( |
| 30 | "fmt" |
| 31 | ) |
| 32 | |
| 33 | func PrintSomething() { |
| 34 | fmt.Println("I am a virtual filesystem printing something from _pkg/src/foo/bar/bar.go!") |
| 35 | } |
| 36 | `), |
| 37 | }, |
| 38 | "localfoo/foo.go": &fstestscip-go gomod github.com/golang/go/src go1.21 `testing/fstest`/.MapFilescip-go gomod github.com/golang/go/src go1.21 `testing/fstest`/MapFile#{ |
| 39 | Datascip-go gomod github.com/golang/go/src go1.21 `testing/fstest`/MapFile#Data.: []byte(`package localfoo |
| 40 | |
| 41 | import ( |
| 42 | "fmt" |
| 43 | ) |
| 44 | |
| 45 | func PrintSomethingElse() { |
| 46 | fmt.Println("I am virtual filesystem printing else from localfoo/foo.go!") |
| 47 | } |
| 48 | `), |
| 49 | }, |
| 50 | } |
| 51 | |
| 52 | func TestFilesystemMapFSscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/example/fs`/TestFilesystemMapFS().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 53 | i := interpscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/.Newscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/New().(interpscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/.Optionsscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Options#{ |
| 54 | GoPathscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Options#GoPath.: "./_pkg", |
| 55 | SourcecodeFilesystemscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Options#SourcecodeFilesystem.: testFilesystemscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/example/fs`/testFilesystem., |
| 56 | }) |
| 57 | if err := i.Usescip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#Use().(stdlibscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/stdlib`/.Symbolsscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/stdlib`/Symbols.); err != nil { |
| 58 | t.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err) |
| 59 | } |
| 60 | |
| 61 | _, err := i.EvalPathscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#EvalPath().(`main.go`) |
| 62 | if err != nil { |
| 63 | t.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err) |
| 64 | } |
| 65 | } |