| 1 | // +build go1.9 |
| 2 | |
| 3 | // To work correctly with out of GOPATH modules, some functions needed to |
| 4 | // switch from using go/build to golang.org/x/tools/go/packages. But that |
| 5 | // package depends on changes to go/types that were introduced in Go 1.9. Since |
| 6 | // modules weren't introduced until Go 1.11, using |
| 7 | // golang.org/x/tools/go/packages can safely be restricted to users of Go 1.9 |
| 8 | // or above. |
| 9 | package mainscip-go gomod github.com/smartystreets/goconvey . `github.com/smartystreets/goconvey`/ |
| 10 | |
| 11 | import ( |
| 12 | "fmtscip-go gomod github.com/golang/go/src go1.16 fmt/" |
| 13 | "stringsscip-go gomod github.com/golang/go/src go1.16 strings/" |
| 14 | |
| 15 | "golang.org/x/tools/go/packagesscip-go gomod golang.org/x/tools ab21143f2384 `golang.org/x/tools/go/packages`/" |
| 16 | ) |
| 17 | |
| 18 | // This method exists because of a bug in the go cover tool that |
| 19 | // causes an infinite loop when you try to run `go test -cover` |
| 20 | // on a package that has an import cycle defined in one of it's |
| 21 | // test files. Yuck. |
| 22 | func testFilesImportTheirOwnPackagescip-go gomod github.com/smartystreets/goconvey . `github.com/smartystreets/goconvey`/testFilesImportTheirOwnPackage().(packagePath string) bool { |
| 23 | meta, err := packagesscip-go gomod golang.org/x/tools ab21143f2384 `golang.org/x/tools/go/packages`/.Loadscip-go gomod golang.org/x/tools ab21143f2384 `golang.org/x/tools/go/packages`/Load().( |
| 24 | &packagesscip-go gomod golang.org/x/tools ab21143f2384 `golang.org/x/tools/go/packages`/.Configscip-go gomod golang.org/x/tools ab21143f2384 `golang.org/x/tools/go/packages`/Config#{ |
| 25 | Modescip-go gomod golang.org/x/tools ab21143f2384 `golang.org/x/tools/go/packages`/Config#Mode.: packagesscip-go gomod golang.org/x/tools ab21143f2384 `golang.org/x/tools/go/packages`/.NeedNamescip-go gomod golang.org/x/tools ab21143f2384 `golang.org/x/tools/go/packages`/NeedName. | packagesscip-go gomod golang.org/x/tools ab21143f2384 `golang.org/x/tools/go/packages`/.NeedImportsscip-go gomod golang.org/x/tools ab21143f2384 `golang.org/x/tools/go/packages`/NeedImports., |
| 26 | Testsscip-go gomod golang.org/x/tools ab21143f2384 `golang.org/x/tools/go/packages`/Config#Tests.: true, |
| 27 | }, |
| 28 | packagePath, |
| 29 | ) |
| 30 | if err != nil { |
| 31 | return false |
| 32 | } |
| 33 | |
| 34 | testPackageID := fmtscip-go gomod github.com/golang/go/src go1.16 fmt/.Sprintfscip-go gomod github.com/golang/go/src go1.16 fmt/Sprintf().("%s [%s.test]", meta[0], meta[0]) |
| 35 | |
| 36 | for _, testPackage := range meta[1:] { |
| 37 | if testPackage.IDscip-go gomod golang.org/x/tools ab21143f2384 `golang.org/x/tools/go/packages`/Package#ID. != testPackageID { |
| 38 | continue |
| 39 | } |
| 40 | |
| 41 | for dependency := range testPackage.Importsscip-go gomod golang.org/x/tools ab21143f2384 `golang.org/x/tools/go/packages`/Package#Imports. { |
| 42 | if dependency == meta[0].PkgPathscip-go gomod golang.org/x/tools ab21143f2384 `golang.org/x/tools/go/packages`/Package#PkgPath. { |
| 43 | return true |
| 44 | } |
| 45 | } |
| 46 | break |
| 47 | } |
| 48 | return false |
| 49 | } |
| 50 | |
| 51 | func resolvePackageNamescip-go gomod github.com/smartystreets/goconvey . `github.com/smartystreets/goconvey`/resolvePackageName().(path string) string { |
| 52 | pkg, err := packagesscip-go gomod golang.org/x/tools ab21143f2384 `golang.org/x/tools/go/packages`/.Loadscip-go gomod golang.org/x/tools ab21143f2384 `golang.org/x/tools/go/packages`/Load().( |
| 53 | &packagesscip-go gomod golang.org/x/tools ab21143f2384 `golang.org/x/tools/go/packages`/.Configscip-go gomod golang.org/x/tools ab21143f2384 `golang.org/x/tools/go/packages`/Config#{ |
| 54 | Modescip-go gomod golang.org/x/tools ab21143f2384 `golang.org/x/tools/go/packages`/Config#Mode.: packagesscip-go gomod golang.org/x/tools ab21143f2384 `golang.org/x/tools/go/packages`/.NeedNamescip-go gomod golang.org/x/tools ab21143f2384 `golang.org/x/tools/go/packages`/NeedName., |
| 55 | }, |
| 56 | path, |
| 57 | ) |
| 58 | if err == nil { |
| 59 | return pkg[0].PkgPathscip-go gomod golang.org/x/tools ab21143f2384 `golang.org/x/tools/go/packages`/Package#PkgPath. |
| 60 | } |
| 61 | |
| 62 | nameArr := stringsscip-go gomod github.com/golang/go/src go1.16 strings/.Splitscip-go gomod github.com/golang/go/src go1.16 strings/Split().(path, endGoPathscip-go gomod github.com/smartystreets/goconvey . `github.com/smartystreets/goconvey`/endGoPath.) |
| 63 | return nameArr[len(nameArr)-1] |
| 64 | } |