report

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

package report generates the diff coverage report for current commit and compared branch.

Index

Constants

View Source
const (
	// CodeLanguage represents the language style for report.
	CodeLanguage = "go"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AllInformation

type AllInformation struct {
	Path                string
	TotalLines          int64
	TotalCoveredLines   int64
	TotalViolationLines int64
}

type CoverageProfile

type CoverageProfile struct {
	// FileName indicates which file belongs to this coverage profile.
	FileName string
	// TotalLines indicates total lines of this coverage profile.
	TotalLines int
	// CoveredLines indicates covered lines of this coverage profile.
	CoveredLines int
	// CoveragePercent indicates the diff coverage percent for this file.
	TotalViolationLines []int
	// ViolationSections indicates the violation sections that miss full coverage.
	ViolationSections []*ViolationSection
	// CodeSnippet represents the output of the ViolationSections, it's calculated from ViolationSections.
	CodeSnippet []template.HTML
}

CoverageProfile represents the test coverage information for a file.

type CoverageTree

type CoverageTree interface {
	// FindOrCreate returns the leaf node that represents the source file (go) if found,
	// otherwise, it will creates the all the nodes along the path to the leaf, and finally return it.
	FindOrCreate(file string) *TreeNode
	Find(pkgPath string) *TreeNode
	CollectCoverageData()
	All() []*AllInformation
	Statistics() *AllInformation
}

func NewCoverageTree

func NewCoverageTree(hostpath string) CoverageTree

type DiffCoverage

type DiffCoverage interface {
	GenerateDiffCoverage() (*Statistics, error)
}

DiffCoverage expose the diff coverage statistics

func NewDiffCoverage

func NewDiffCoverage(
	profiles []*cover.Profile,
	changes []*gittool.Change,
	excludes []string,
	comparedBranch string,
) (DiffCoverage, error)

type FullCoverage

type FullCoverage interface {
	BuildFullCoverageTree() []*AllInformation
}

func NewFullCoverage

func NewFullCoverage(
	profiles []*cover.Profile,
	moduleHostPath string,
	excludes []string,
) (FullCoverage, error)

type ReportGenerator

type ReportGenerator interface {
	GenerateReport() error
}

ReportGenerator represents the feature that generate coverage report.

func NewReportGenerator

func NewReportGenerator(
	statistics *Statistics,
	codeStyle string,
	outputPath string,
	reportName string,
) ReportGenerator

NewReportGenerator creates a html report generator to generate html coverage report. We will use https://pygments.org/docs/styles to style the output, and use // https://github.com/alecthomas/chroma to help to generate code snippets.

type Statistics

type Statistics struct {
	// ComparedBranch the branch that diff compared with.
	ComparedBranch string
	// TotalLines represents the total lines that count for coverage.
	TotalLines int
	// TotalCoveredLines indicates total covered lines that count for coverage.
	TotalCoveredLines int
	// TotalViolationLines represents all the lines that miss test coverage.
	TotalViolationLines int
	// TotalCoveragePercent represents the coverage percent for current diff.
	TotalCoveragePercent float64
	// CoverageProfile represents the coverage profile for a specific file.
	CoverageProfile []*CoverageProfile
}

Statistics represents the total diff coverage for the HEAD commit. It contains the total coverage and possible coverage profile.

type Tree

type Tree *TreeNode

type TreeNode

type TreeNode struct {
	Name                string // name
	TotalLines          int64  // total lines account for coverage
	TotalCoveredLines   int64  // covered lines account for coverage
	TotalViolationLines int64  // violation lines that not covered for coverage
	CoverageProfile     *CoverageProfile
	Nodes               map[string]*TreeNode // sub nodes that store in map
	// contains filtered or unexported fields
}

TreeNode represents the node of multi branches tree. Each node contains the basic coverage information, includes covered lines count, totol lines count and vioaltion lines count. Each internal node has one or many sub node, which is stored in a map, and can be retrieved by node name. For the leaf node, it does not have sub node.

func NewTreeNode

func NewTreeNode(name string, isLeaf bool) *TreeNode

type ViolationSection

type ViolationSection struct {
	// ViolationLines indicates which line miss the coverage.
	ViolationLines []int
	// StartLine indicates the start line of the section.
	StartLine int
	// EndLine indicates the end line of the section.
	EndLine int
	// Contents contains [StartLine..EndLine] lines from the source file.
	Contents []string
}

ViolationSection represents a portion of the change that miss unit test coverage.

Jump to

Keyboard shortcuts

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