| 1 | package interpscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/ |
| 2 | |
| 3 | import ( |
| 4 | "osscip-go gomod github.com/golang/go/src go1.21 os/" |
| 5 | "pathscip-go gomod github.com/golang/go/src go1.21 path/" |
| 6 | "path/filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/" |
| 7 | "testingscip-go gomod github.com/golang/go/src go1.21 testing/" |
| 8 | ) |
| 9 | |
| 10 | func Test_effectivePkgscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Test_effectivePkg().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 11 | testCases := []struct { |
| 12 | desc string |
| 13 | root string |
| 14 | path string |
| 15 | expected string |
| 16 | }{ |
| 17 | { |
| 18 | desc: "path is a subpackage", |
| 19 | root: "github.com/foo/plugin/vendor/guthib.com/traefik/fromage", |
| 20 | path: "guthib.com/traefik/fromage/couteau/lol", |
| 21 | expected: "github.com/foo/plugin/vendor/guthib.com/traefik/fromage/couteau/lol", |
| 22 | }, |
| 23 | { |
| 24 | desc: "path is a vendored package", |
| 25 | root: "github.com/foo/plugin/vendor/guthib.com/traefik/fromage", |
| 26 | path: "vendor/guthib.com/traefik/vin", |
| 27 | expected: "github.com/foo/plugin/vendor/guthib.com/traefik/fromage/vendor/guthib.com/traefik/vin", |
| 28 | }, |
| 29 | { |
| 30 | desc: "path is non-existent", |
| 31 | root: "foo", |
| 32 | path: "githib.com/foo/app", |
| 33 | expected: "foo/githib.com/foo/app", |
| 34 | }, |
| 35 | } |
| 36 | |
| 37 | for _, test := range testCases { |
| 38 | test := test |
| 39 | t.Runscip-go gomod github.com/golang/go/src go1.21 testing/T#Run().(test.desc, func(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 40 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 41 | |
| 42 | pkg := effectivePkgscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/effectivePkg().(test.root, test.path) |
| 43 | |
| 44 | if pkg != test.expected { |
| 45 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("Got %s, want %s", pkg, test.expected) |
| 46 | } |
| 47 | }) |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | func Test_pkgDirscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Test_pkgDir().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 52 | // create GOPATH |
| 53 | goPath := t.TempDirscip-go gomod github.com/golang/go/src go1.21 testing/common#TempDir().() |
| 54 | |
| 55 | // Create project |
| 56 | project := filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(goPath, "src", "guthib.com", "foo", "root") |
| 57 | if err := osscip-go gomod github.com/golang/go/src go1.21 os/.MkdirAllscip-go gomod github.com/golang/go/src go1.21 os/MkdirAll().(project, 0o700); err != nil { |
| 58 | t.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err) |
| 59 | } |
| 60 | |
| 61 | type expected struct { |
| 62 | dir string |
| 63 | rpath string |
| 64 | } |
| 65 | |
| 66 | testCases := []struct { |
| 67 | desc string |
| 68 | path string |
| 69 | root string |
| 70 | setup func() error |
| 71 | expected expected |
| 72 | }{ |
| 73 | { |
| 74 | desc: "GOPATH only", |
| 75 | path: "guthib.com/foo/bar", |
| 76 | root: "", |
| 77 | setup: func() error { |
| 78 | return osscip-go gomod github.com/golang/go/src go1.21 os/.MkdirAllscip-go gomod github.com/golang/go/src go1.21 os/MkdirAll().(filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(goPath, "src", "guthib.com", "foo", "bar"), 0o700) |
| 79 | }, |
| 80 | expected: expected{ |
| 81 | dir: filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(goPath, "src", "guthib.com", "foo", "bar"), |
| 82 | rpath: "", |
| 83 | }, |
| 84 | }, |
| 85 | { |
| 86 | desc: "vendor", |
| 87 | path: "guthib.com/foo/bar", |
| 88 | root: pathscip-go gomod github.com/golang/go/src go1.21 path/.Joinscip-go gomod github.com/golang/go/src go1.21 path/Join().("guthib.com", "foo", "root"), |
| 89 | setup: func() error { |
| 90 | return osscip-go gomod github.com/golang/go/src go1.21 os/.MkdirAllscip-go gomod github.com/golang/go/src go1.21 os/MkdirAll().(filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(project, "vendor", "guthib.com", "foo", "bar"), 0o700) |
| 91 | }, |
| 92 | expected: expected{ |
| 93 | dir: filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(goPath, "src", "guthib.com", "foo", "root", "vendor", "guthib.com", "foo", "bar"), |
| 94 | rpath: filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().("guthib.com", "foo", "root", "vendor"), |
| 95 | }, |
| 96 | }, |
| 97 | { |
| 98 | desc: "GOPATH flat", |
| 99 | path: "guthib.com/foo/bar", |
| 100 | root: pathscip-go gomod github.com/golang/go/src go1.21 path/.Joinscip-go gomod github.com/golang/go/src go1.21 path/Join().("guthib.com", "foo", "root"), |
| 101 | setup: func() error { |
| 102 | return osscip-go gomod github.com/golang/go/src go1.21 os/.MkdirAllscip-go gomod github.com/golang/go/src go1.21 os/MkdirAll().(filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(goPath, "src", "guthib.com", "foo", "bar"), 0o700) |
| 103 | }, |
| 104 | expected: expected{ |
| 105 | dir: filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(goPath, "src", "guthib.com", "foo", "bar"), |
| 106 | rpath: "", |
| 107 | }, |
| 108 | }, |
| 109 | { |
| 110 | desc: "vendor flat", |
| 111 | path: "guthib.com/foo/bar", |
| 112 | root: pathscip-go gomod github.com/golang/go/src go1.21 path/.Joinscip-go gomod github.com/golang/go/src go1.21 path/Join().("guthib.com", "foo", "root", "vendor", "guthib.com", "foo", "bir"), |
| 113 | setup: func() error { |
| 114 | if err := osscip-go gomod github.com/golang/go/src go1.21 os/.MkdirAllscip-go gomod github.com/golang/go/src go1.21 os/MkdirAll().(filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(project, "vendor", "guthib.com", "foo", "bar"), 0o700); err != nil { |
| 115 | return err |
| 116 | } |
| 117 | return osscip-go gomod github.com/golang/go/src go1.21 os/.MkdirAllscip-go gomod github.com/golang/go/src go1.21 os/MkdirAll().(filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(project, "vendor", "guthib.com", "foo", "bir"), 0o700) |
| 118 | }, |
| 119 | expected: expected{ |
| 120 | dir: filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(goPath, "src", "guthib.com", "foo", "root", "vendor", "guthib.com", "foo", "bar"), |
| 121 | rpath: filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().("guthib.com", "foo", "root", "vendor"), |
| 122 | }, |
| 123 | }, |
| 124 | { |
| 125 | desc: "fallback to GOPATH", |
| 126 | path: "guthib.com/foo/bar", |
| 127 | root: pathscip-go gomod github.com/golang/go/src go1.21 path/.Joinscip-go gomod github.com/golang/go/src go1.21 path/Join().("guthib.com", "foo", "root", "vendor", "guthib.com", "foo", "bir"), |
| 128 | setup: func() error { |
| 129 | if err := osscip-go gomod github.com/golang/go/src go1.21 os/.MkdirAllscip-go gomod github.com/golang/go/src go1.21 os/MkdirAll().(filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(goPath, "src", "guthib.com", "foo", "bar"), 0o700); err != nil { |
| 130 | return err |
| 131 | } |
| 132 | return osscip-go gomod github.com/golang/go/src go1.21 os/.MkdirAllscip-go gomod github.com/golang/go/src go1.21 os/MkdirAll().(filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(project, "vendor", "guthib.com", "foo", "bir"), 0o700) |
| 133 | }, |
| 134 | expected: expected{ |
| 135 | dir: filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(goPath, "src", "guthib.com", "foo", "bar"), |
| 136 | rpath: "", |
| 137 | }, |
| 138 | }, |
| 139 | { |
| 140 | desc: "vendor recursive", |
| 141 | path: "guthib.com/foo/bar", |
| 142 | root: pathscip-go gomod github.com/golang/go/src go1.21 path/.Joinscip-go gomod github.com/golang/go/src go1.21 path/Join().("guthib.com", "foo", "root", "vendor", "guthib.com", "foo", "bir", "vendor", "guthib.com", "foo", "bur"), |
| 143 | setup: func() error { |
| 144 | if err := osscip-go gomod github.com/golang/go/src go1.21 os/.MkdirAllscip-go gomod github.com/golang/go/src go1.21 os/MkdirAll().( |
| 145 | filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(goPath, "src", "guthib.com", "foo", "root", "vendor", "guthib.com", "foo", "bir", "vendor", "guthib.com", "foo", "bur"), |
| 146 | 0o700); err != nil { |
| 147 | return err |
| 148 | } |
| 149 | return osscip-go gomod github.com/golang/go/src go1.21 os/.MkdirAllscip-go gomod github.com/golang/go/src go1.21 os/MkdirAll().(filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(project, "vendor", "guthib.com", "foo", "bar"), 0o700) |
| 150 | }, |
| 151 | expected: expected{ |
| 152 | dir: filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(project, "vendor", "guthib.com", "foo", "bar"), |
| 153 | rpath: filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().("guthib.com", "foo", "root", "vendor"), |
| 154 | }, |
| 155 | }, |
| 156 | } |
| 157 | |
| 158 | interp := &Interpreterscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#{ |
| 159 | optscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#opt.: optscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/opt#{ |
| 160 | filesystemscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/opt#filesystem.: &realFSscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/realFS#{}, |
| 161 | }, |
| 162 | } |
| 163 | |
| 164 | for _, test := range testCases { |
| 165 | test := test |
| 166 | t.Runscip-go gomod github.com/golang/go/src go1.21 testing/T#Run().(test.desc, func(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 167 | if err := osscip-go gomod github.com/golang/go/src go1.21 os/.RemoveAllscip-go gomod github.com/golang/go/src go1.21 os/RemoveAll().(goPath); err != nil { |
| 168 | t.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err) |
| 169 | } |
| 170 | if err := osscip-go gomod github.com/golang/go/src go1.21 os/.MkdirAllscip-go gomod github.com/golang/go/src go1.21 os/MkdirAll().(goPath, 0o700); err != nil { |
| 171 | t.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err) |
| 172 | } |
| 173 | |
| 174 | if test.setup != nil { |
| 175 | err := test.setup() |
| 176 | if err != nil { |
| 177 | t.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err) |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | goPath := filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.ToSlashscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/ToSlash().(goPath) |
| 182 | dir, rPath, err := interp.pkgDirscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Interpreter#pkgDir().(goPath, test.root, test.path) |
| 183 | if err != nil { |
| 184 | t.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err) |
| 185 | } |
| 186 | |
| 187 | expectedDir := filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.ToSlashscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/ToSlash().(test.expected.dir) |
| 188 | if dir != expectedDir { |
| 189 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("[dir] got: %s, want: %s", dir, expectedDir) |
| 190 | } |
| 191 | |
| 192 | expectedRpath := filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.ToSlashscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/ToSlash().(test.expected.rpath) |
| 193 | if rPath != expectedRpath { |
| 194 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().(" [rpath] got: %s, want: %s", rPath, expectedRpath) |
| 195 | } |
| 196 | }) |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | func Test_previousRootscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/Test_previousRoot().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 201 | testCases := []struct { |
| 202 | desc string |
| 203 | root string |
| 204 | rootPathSuffix string |
| 205 | expected string |
| 206 | }{ |
| 207 | { |
| 208 | desc: "GOPATH", |
| 209 | root: "github.com/foo/pkg/", |
| 210 | expected: "", |
| 211 | }, |
| 212 | { |
| 213 | desc: "vendor level 1", |
| 214 | root: "github.com/foo/pkg/vendor/guthib.com/traefik/fromage", |
| 215 | expected: "github.com/foo/pkg", |
| 216 | }, |
| 217 | { |
| 218 | desc: "vendor level 2", |
| 219 | root: "github.com/foo/pkg/vendor/guthib.com/traefik/fromage/vendor/guthib.com/traefik/fuu", |
| 220 | expected: "github.com/foo/pkg/vendor/guthib.com/traefik/fromage", |
| 221 | }, |
| 222 | { |
| 223 | desc: "vendor is sibling", |
| 224 | root: "github.com/foo/bar", |
| 225 | rootPathSuffix: "testdata/src/github.com/foo/bar", |
| 226 | expected: "github.com/foo", |
| 227 | }, |
| 228 | { |
| 229 | desc: "vendor is uncle", |
| 230 | root: "github.com/foo/bar/baz", |
| 231 | rootPathSuffix: "testdata/src/github.com/foo/bar/baz", |
| 232 | expected: "github.com/foo", |
| 233 | }, |
| 234 | } |
| 235 | |
| 236 | for _, test := range testCases { |
| 237 | test := test |
| 238 | t.Runscip-go gomod github.com/golang/go/src go1.21 testing/T#Run().(test.desc, func(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 239 | t.Parallelscip-go gomod github.com/golang/go/src go1.21 testing/T#Parallel().() |
| 240 | |
| 241 | var rootPath string |
| 242 | if test.rootPathSuffix != "" { |
| 243 | wd, err := osscip-go gomod github.com/golang/go/src go1.21 os/.Getwdscip-go gomod github.com/golang/go/src go1.21 os/Getwd().() |
| 244 | if err != nil { |
| 245 | t.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err) |
| 246 | } |
| 247 | rootPath = filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.ToSlashscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/ToSlash().(filepathscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/.Joinscip-go gomod github.com/golang/go/src go1.21 `path/filepath`/Join().(wd, test.rootPathSuffix)) |
| 248 | } else { |
| 249 | rootPath = vendorscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/vendor. |
| 250 | } |
| 251 | p, err := previousRootscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/previousRoot().(&realFSscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/realFS#{}, rootPath, test.root) |
| 252 | if err != nil { |
| 253 | t.Errorscip-go gomod github.com/golang/go/src go1.21 testing/common#Error().(err) |
| 254 | } |
| 255 | |
| 256 | if p != test.expected { |
| 257 | previousRootscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/previousRoot().(&realFSscip-go gomod github.com/traefik/yaegi . `github.com/traefik/yaegi/interp`/realFS#{}, rootPath, test.root) |
| 258 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("got: %s, want: %s", p, test.expected) |
| 259 | } |
| 260 | }) |
| 261 | } |
| 262 | } |