Debian Codegraph @

goconvey_1_8.go

raw symbols SCIP
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, users of Go 1.8 or below can't be
7 // using modules, so they can continue to use go/build.
8
9 package main
10
11 import (
12 "go/build"
13 "strings"
14 )
15
16 // This method exists because of a bug in the go cover tool that
17 // causes an infinite loop when you try to run `go test -cover`
18 // on a package that has an import cycle defined in one of it's
19 // test files. Yuck.
20 func testFilesImportTheirOwnPackage(packagePath string) bool {
21 meta, err := build.ImportDir(packagePath, build.AllowBinary)
22 if err != nil {
23 return false
24 }
25
26 for _, dependency := range meta.TestImports {
27 if dependency == meta.ImportPath {
28 return true
29 }
30 }
31 return false
32 }
33
34 func resolvePackageName(path string) string {
35 pkg, err := build.ImportDir(path, build.FindOnly)
36 if err == nil {
37 return pkg.ImportPath
38 }
39
40 nameArr := strings.Split(path, endGoPath)
41 return nameArr[len(nameArr)-1]
42 }