report

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2023 License: MIT Imports: 12 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
	TotalEffectiveLines        int64
	TotalIgnoredLines          int64
	TotalCoveredLines          int64
	TotalViolationLines        int64
	TotalCoveredButIgnoreLines int64
}

type CoverageProfile

type CoverageProfile struct {
	// FileName indicates which file belongs to this coverage profile.
	FileName string
	// TotalLines indicates total lines of the entire repo/module.
	TotalLines int
	// TotalEffectiveLines indicates effective lines for the coverage profile.
	TotalEffectiveLines int
	// TotalIgnoredLines indicates the lines ignored.
	TotalIgnoredLines int
	// CoveredLines indicates covered lines of this coverage profile.
	CoveredLines int
	// CoveredButIgnoredLines indicates the lines that covered but ignored.
	CoveredButIgnoredLines 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(modulePath string) CoverageTree

type ReportGenerator

type ReportGenerator interface {
	GenerateReport(statistics *Statistics) error
}

ReportGenerator represents the feature that generate coverage report.

func NewReportGenerator

func NewReportGenerator(
	codeStyle string,
	outputPath string,
	reportName string,
	logger logrus.FieldLogger,
) 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
	// TotalEffectiveLines indicates effective lines for the coverage profile.
	TotalEffectiveLines int
	// TotalIgnoredLines indicates the lines ignored.
	TotalIgnoredLines int
	// TotalCoveredLines indicates total covered lines that count for coverage.
	TotalCoveredLines int
	// CoveredButIgnoredLines indicates the lines that covered but ignored.
	TotalCoveredButIgnoredLines int
	// TotalViolationLines represents all the lines that miss test coverage.
	TotalViolationLines int
	// TotalCoveragePercent represents the coverage percent for current diff.
	TotalCoveragePercent float64
	// TotalCoverageWithoutIgnore represents the coverage percent for current diff without ignorance
	TotalCoverageWithoutIgnore float64
	// CoverageProfile represents the coverage profile for a specific file.
	CoverageProfile []*CoverageProfile
	// StatisticsType indicates which type the Statistics is.
	StatisticsType StatisticsType
	// exclude files that won't take participate to coverage calculation.
	ExcludeFiles []string
}

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

type StatisticsType added in v1.0.0

type StatisticsType string
const (
	FullStatisticsType StatisticsType = "full"
	DiffStatisticsType StatisticsType = "diff"
)

type Tree

type Tree *TreeNode

type TreeNode

type TreeNode struct {
	Name                       string // name
	TotalLines                 int64  // total lines of the entire repo/module.
	TotalEffectiveLines        int64  // the lines that for coverage, total lines - ignored lines
	TotalIgnoredLines          int64  // the lines ignored
	TotalCoveredLines          int64  // covered lines account for coverage
	TotalViolationLines        int64  // violation lines that not covered for coverage
	TotalCoveredButIgnoreLines int64  // the lines that covered but ignored
	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