cobertura

package module
v0.0.0-...-b1fba29 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2022 License: MIT Imports: 17 Imported by: 0

README

Build Status Coverage Status

go tool cover XML (Cobertura) export

This is a simple helper tool for generating XML output in Cobertura format for CIs like Jenkins and others from go tool cover output.

Installation

Just type the following to install the program and its dependencies:

$ go get code.google.com/p/go.tools/cmd/cover
$ go get github.com/t-yuki/gocover-cobertura

Usage

gocover-cobertura reads from the standard input:

$ go test -coverprofile=coverage.txt -covermode count github.com/gorilla/mux
$ gocover-cobertura < coverage.txt > coverage.xml

Authors

Thanks

This tool is originated from gocov-xml by Alexey Palazhchenko (AlekSi)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Boundary

type Boundary struct {
	Offset int     // Location as a byte offset in the source file.
	Start  bool    // Is this the start of a block?
	Count  int     // Event count from the cover profile.
	Norm   float64 // Count normalized to [0..1].
}

Boundary represents the position in a source file of the beginning or end of a block as reported by the coverage profile. In HTML mode, it will correspond to the opening or closing of a <span> tag and will be used to colorize the source

type Class

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

func (Class) HitRate

func (class Class) HitRate() float32

HitRate returns a float32 from 0.0 to 1.0 representing what fraction of lines have hits

func (Class) NumLines

func (class Class) NumLines() (numLines int64)

NumLines returns the number of lines

func (Class) NumLinesWithHits

func (class Class) NumLinesWithHits() (numLinesWithHits int64)

NumLinesWithHits returns the number of lines with a hit count > 0

type Coverage

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

func (Coverage) HitRate

func (cov Coverage) HitRate() float32

HitRate returns a float32 from 0.0 to 1.0 representing what fraction of lines have hits

func (Coverage) NumLines

func (cov Coverage) NumLines() (numLines int64)

NumLines returns the number of lines

func (Coverage) NumLinesWithHits

func (cov Coverage) NumLinesWithHits() (numLinesWithHits int64)

NumLinesWithHits returns the number of lines with a hit count > 0

type Line

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

type Lines

type Lines []*Line

Lines is a slice of Line pointers, with some convenience methods

func (*Lines) AddOrUpdateLine

func (lines *Lines) AddOrUpdateLine(lineNumber int, hits int64)

AddOrUpdateLine adds a line if it is a different line than the last line recorded. If it's the same line as the last line recorded then we update the hits down if the new hits is less; otherwise just leave it as-is

func (Lines) HitRate

func (lines Lines) HitRate() (hitRate float32)

HitRate returns a float32 from 0.0 to 1.0 representing what fraction of lines have hits

func (Lines) NumLines

func (lines Lines) NumLines() int64

NumLines returns the number of lines

func (Lines) NumLinesWithHits

func (lines Lines) NumLinesWithHits() (numLinesWithHits int64)

NumLinesWithHits returns the number of lines with a hit count > 0

type Method

type Method struct {
	Name       string  `xml:"name,attr"`
	Signature  string  `xml:"signature,attr"`
	LineRate   float32 `xml:"line-rate,attr"`
	BranchRate float32 `xml:"branch-rate,attr"`
	Complexity float32 `xml:"complexity,attr"`
	Lines      Lines   `xml:"lines>line"`
}

func (Method) HitRate

func (method Method) HitRate() float32

HitRate returns a float32 from 0.0 to 1.0 representing what fraction of lines have hits

func (Method) NumLines

func (method Method) NumLines() int64

NumLines returns the number of lines

func (Method) NumLinesWithHits

func (method Method) NumLinesWithHits() int64

NumLinesWithHits returns the number of lines with a hit count > 0

type Package

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

func (Package) HitRate

func (pkg Package) HitRate() float32

HitRate returns a float32 from 0.0 to 1.0 representing what fraction of lines have hits

func (Package) NumLines

func (pkg Package) NumLines() (numLines int64)

NumLines returns the number of lines

func (Package) NumLinesWithHits

func (pkg Package) NumLinesWithHits() (numLinesWithHits int64)

NumLinesWithHits returns the number of lines with a hit count > 0

type Profile

type Profile struct {
	FileName string
	Mode     string
	Blocks   []ProfileBlock
}

Profile represents the profiling data for a specific file.

func ParseProfiles

func ParseProfiles(in io.Reader) ([]*Profile, error)

ParseProfiles parses profile data from the given Reader and returns a Profile for each file.

func (*Profile) Boundaries

func (p *Profile) Boundaries(src []byte) (boundaries []Boundary)

Boundaries returns a Profile as a set of Boundary objects within the provided src.

type ProfileBlock

type ProfileBlock struct {
	StartLine, StartCol int
	EndLine, EndCol     int
	NumStmt, Count      int
}

ProfileBlock represents a single block of profiling data.

type Source

type Source struct {
	Path string `xml:",chardata"`
}

Jump to

Keyboard shortcuts

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