| 1 | package fs1 |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | "testing/fstest" // only available from 1.16. |
| 6 | |
| 7 | "github.com/traefik/yaegi/interp" |
| 8 | "github.com/traefik/yaegi/stdlib" |
| 9 | ) |
| 10 | |
| 11 | var testFilesystem = fstest.MapFS{ |
| 12 | "main.go": &fstest.MapFile{ |
| 13 | 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": &fstest.MapFile{ |
| 27 | 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": &fstest.MapFile{ |
| 39 | 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 TestFilesystemMapFS(t *testing.T) { |
| 53 | i := interp.New(interp.Options{ |
| 54 | GoPath: "./_pkg", |
| 55 | SourcecodeFilesystem: testFilesystem, |
| 56 | }) |
| 57 | if err := i.Use(stdlib.Symbols); err != nil { |
| 58 | t.Fatal(err) |
| 59 | } |
| 60 | |
| 61 | _, err := i.EvalPath(`main.go`) |
| 62 | if err != nil { |
| 63 | t.Fatal(err) |
| 64 | } |
| 65 | } |