gobertura

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2026 License: MIT Imports: 9 Imported by: 0

README

status PkgGoDev

gobertura

gobertura converts go test -coverprofile output into Cobertura XML format, making Go coverage reports compatible with CI tools that consume Cobertura (e.g. GitLab, Jenkins, Codecov).

Installation

go get -tool github.com/aereal/gobertura/cmd/gobertura
go tool gobertura

Synopsis

Read from stdin, write to stdout:

go test -coverprofile=/dev/stdout ./... | go tool gobertura > coverage.xml

Use explicit file paths with -input / -output flags:

go test -coverprofile=coverage.out ./...
go tool gobertura -input coverage.out -output coverage.xml
Flags
Flag Default Description
-input stdin Input coverage profile file path
-output stdout Output Cobertura XML file path

License

See LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Write

func Write(w io.Writer, cov *Coverage) error

Write encodes cov as Cobertura XML to w. The output includes the XML declaration and the Cobertura DOCTYPE declaration.

Types

type Class

type Class struct {
	Methods    Methods `xml:"methods"`
	Name       string  `xml:"name,attr"`
	Filename   string  `xml:"filename,attr"`
	Lines      []Line  `xml:"lines>line"`
	LineRate   float64 `xml:"line-rate,attr"`
	BranchRate float64 `xml:"branch-rate,attr"`
	Complexity float64 `xml:"complexity,attr"`
}

Class represents a <class> element, corresponding to a single Go source file.

type Coverage

type Coverage struct {
	XMLName         xml.Name  `xml:"coverage"`
	Version         string    `xml:"version,attr"`
	Sources         Sources   `xml:"sources"`
	Packages        []Package `xml:"packages>package"`
	LineRate        float64   `xml:"line-rate,attr"`
	BranchRate      float64   `xml:"branch-rate,attr"`
	LinesValid      int       `xml:"lines-valid,attr"`
	LinesCovered    int       `xml:"lines-covered,attr"`
	BranchesValid   int       `xml:"branches-valid,attr"`
	BranchesCovered int       `xml:"branches-covered,attr"`
	Complexity      float64   `xml:"complexity,attr"`
	Timestamp       int64     `xml:"timestamp,attr"`
}

Coverage represents the root <coverage> element of a Cobertura XML document.

func Parse

func Parse(r io.Reader, timestamp time.Time) (*Coverage, error)

Parse parses go test coverage output into a Coverage value for Cobertura XML output. timestamp is used for the <coverage timestamp="..."> attribute.

type Line

type Line struct {
	Number int  `xml:"number,attr"`
	Hits   int  `xml:"hits,attr"`
	Branch bool `xml:"branch,attr"`
}

Line represents a <line> element.

type Methods

type Methods struct{}

Methods represents the <methods/> element. Always empty because Go coverage profiles do not include method-level information.

type Package

type Package struct {
	Name       string  `xml:"name,attr"`
	Classes    []Class `xml:"classes>class"`
	LineRate   float64 `xml:"line-rate,attr"`
	BranchRate float64 `xml:"branch-rate,attr"`
	Complexity float64 `xml:"complexity,attr"`
}

Package represents a <package> element.

type Sources

type Sources struct {
	Sources []string `xml:"source"`
}

Sources represents the <sources> element.

Directories

Path Synopsis
cmd
gobertura command
internal
cli
Package cli implements the core logic of the gobertura command.
Package cli implements the core logic of the gobertura command.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL