Documentation ¶
Overview ¶
Package cove is a thin wrapper around the go toolchain
Index ¶
- func CoverageProfile(short bool, mode string, outdir string, pack Package) (string, error)
- func CoverageReport(profile string, outdir string) (string, error)
- func Get(pack Package) error
- func GetFirstGoPath() string
- func GoCmd(sub string, args ...string) *exec.Cmd
- func PackageExists(pack Package) bool
- func PackageJSON(pack Package, v interface{}) error
- func PackagePatternsAsStrings(paths []PackagePattern) []string
- func PackagesAsStrings(packs []Package) []string
- type Package
- type PackagePattern
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CoverageProfile ¶
CoverageProfile creates a cover profile file for the provided package The file is created in outdir. The parameter short sets whether to run all tests or only the short ones. The mode specifies which style of cover mode is used. If a profile is able to be created its file name is returned.
Example ¶
testdir, temperr := ioutil.TempDir("", "coverage-profile") if temperr != nil { fmt.Printf("%v", temperr) } defer os.RemoveAll(testdir) profile, profileErr := CoverageProfile(false, "count", testdir, "text/scanner") if profileErr != nil { fmt.Printf("%v", profileErr) } fmt.Println(filepath.Base(profile))
Output: text.scanner.out
Example (Short) ¶
testdir, _ := ioutil.TempDir("", "coverage-profile") defer os.RemoveAll(testdir) profile, _ := CoverageProfile(true, "set", testdir, "text/scanner") fmt.Println(filepath.Base(profile))
Output: text.scanner.out
func CoverageReport ¶
CoverageReport turns the profile into a report using 'go tool cover'
func Get ¶
Get runs 'go get pack'
Example ¶
if err := Get("text/scanner"); err != nil { fmt.Println(err) } if err := Get("not/a/package"); err != nil { fmt.Println("Got error") }
Output: Got error
func GetFirstGoPath ¶
func GetFirstGoPath() string
The Go PATH variable can be a ":" separated list. The default behavior for "most" go tools when needing a canonical go path location is to just use the first one in the list. this function returns that.
func PackageExists ¶
PackageExists checks to see if a given package name exists
Example ¶
if PackageExists("os/exec") { fmt.Println("os/exec exists") } if !PackageExists("boogey/woogey/bugleboy") { fmt.Println("boogey/woogey/bugleboy does not exist") }
Output: os/exec exists boogey/woogey/bugleboy does not exist
func PackageJSON ¶
PackageJSON takes a SINGLE fully qualified package import path and decodes the 'go list -json' response. See $GOROOT/src/cmd/go/list.go for documentation on the json output.
Example ¶
var info struct { ImportPath string Name string Incomplete bool } PackageJSON("os/exec", &info) fmt.Printf("%s %s %v", info.ImportPath, info.Name, info.Incomplete)
Output: os/exec exec false
Example (Unknown) ¶
var info struct { ImportPath string Name string Incomplete bool } if err := PackageJSON("moo/boo", &info); err != nil { fmt.Printf("%v", err) }
Output: Cannot get json for 'moo/boo' as it is not a go package. Original error: EOF
Example (Wildcard) ¶
type JSONresponse struct { ImportPath string Name string Incomplete bool } var resp []JSONresponse if err := PackageJSON("os/...", &resp); err != nil { fmt.Printf("'go list -json os/...' returns an invalid json in the multiple return case.") }
Output: 'go list -json os/...' returns an invalid json in the multiple return case.
func PackagePatternsAsStrings ¶
func PackagePatternsAsStrings(paths []PackagePattern) []string
PackagePatternsAsStrings takes a slice of paths and returns a slice of strings
func PackagesAsStrings ¶
PackagesAsStrings takes a slice of packages and returns a slice of strings
Types ¶
type Package ¶
type Package string
Package is a specific and unique go package
func MissingDependencies ¶
MissingDependencies returns any go packages that are missing for a given package.
Example (Unknown) ¶
_, err := MissingDependencies("moo/boo") if err != nil { fmt.Printf("%v", err) }
Output: Could not determine missing dependencies for moo/boo: Cannot get json for 'moo/boo' as it is not a go package. Original error: EOF
func Packages ¶
func Packages(paths ...PackagePattern) ([]Package, error)
Packages gets all packages that match any of the paths. The package list will only contain 1 entry per package in sorted order. Invalid paths will generate an error, but will not stop the evaluation of the other paths.
Example (Multiples) ¶
packs, _ := Packages("text/...", "os/exec") for _, pack := range packs { fmt.Println(pack) }
Output: os/exec text/scanner text/tabwriter text/template text/template/parse
Example (Relative) ¶
//duplicates are filtered packs, _ := Packages(".") for _, pack := range packs { fmt.Println(pack) }
Output: github.com/MediaMath/cove
Example (Single) ¶
packs, _ := Packages("text/template") for _, pack := range packs { fmt.Println(pack) }
Output: text/template
Example (Unknown) ¶
packs, err := Packages("foo/manchu", "text/...", "moo/...") for _, pack := range packs { fmt.Println(pack) } if err != nil { fmt.Println("Had errors.") }
Output: text/scanner text/tabwriter text/template text/template/parse Had errors.
Example (Unknown2) ¶
packs, err := Packages("foo/manchu") for _, pack := range packs { fmt.Println(pack) } if err != nil { fmt.Println("Had errors.") }
Output: Had errors.
Example (Wildcard) ¶
packs, _ := Packages("text/...") for _, pack := range packs { fmt.Println(pack) }
Output: text/scanner text/tabwriter text/template text/template/parse
func PackagesFromStrings ¶
PackagesFromStrings creates a slice of packages from a slice of strings
type PackagePattern ¶
type PackagePattern string
PackagePattern is a pattern, potentially with wildcards, to search for packages in. It can correlate to 0 to many Packages
func PackagePatternsFromStrings ¶
func PackagePatternsFromStrings(str []string) []PackagePattern
PackagePatternsFromStrings creates a slice of paths from a slice of strings