Documentation
¶
Overview ¶
Package coverage integrates Go test coverage analysis.
The coverage package runs `go test -cover` on packages and parses the output to extract coverage percentages. It supports: - Configurable timeouts per package - Automatic exclusion of testdata and vendor packages - Coverage threshold detection
Usage ¶
Create a coverage runner with timeout:
runner := coverage.NewRunner(30) // 30 second timeout
Run coverage analysis:
results, err := runner.RunCoverage("/path/to/project", excludePatterns)
if err != nil {
log.Fatal(err)
}
for _, result := range results {
if result.Skipped {
fmt.Printf("Skipped: %s (no tests)\n", result.PackagePath)
} else if result.Error != "" {
fmt.Printf("Error: %s - %s\n", result.PackagePath, result.Error)
} else {
fmt.Printf("%s: %.1f%%\n", result.PackagePath, result.Coverage)
}
}
The runner automatically skips packages without tests and handles compilation errors gracefully.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PackageCoverage ¶
type PackageCoverage struct {
PackagePath string `json:"package_path"`
Coverage float64 `json:"coverage"` // Percentage (0-100)
Error string `json:"error"` // Empty if successful
Skipped bool `json:"skipped"` // True if no tests found
}
PackageCoverage represents coverage data for a single package
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner executes go test -cover for packages
func (*Runner) RunCoverage ¶
func (r *Runner) RunCoverage(projectPath string, excludePatterns []string) ([]*PackageCoverage, error)
RunCoverage executes tests and extracts coverage for all packages in projectPath