internal

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

This code is adapted from the Go standard library's cover tool: https://github.com/golang/go/blob/master/src/cmd/cover/func.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteHTMLEscapedCode added in v0.2.2

func WriteHTMLEscapedCode(dst *bufio.Writer, line string) error

WriteHTMLEscapedCode writes the given line to the provided bufio.Writer, escaping HTML special characters.

func WriteHTMLEscapedLine added in v0.2.3

func WriteHTMLEscapedLine(dst *bufio.Writer, lineNumber int, count *int, line string) error

WriteHTMLEscapedLine writes an HTML-escaped line to the given bufio.Writer.

Types

type GoDir

type GoDir struct {
	*GoListItem
	SubDirs []*GoDir
	Files   []*GoFile
}

func (*GoDir) AddFile

func (dir *GoDir) AddFile(file *GoFile)

AddFile adds a GoFile to the GoDir's list of files.

func (*GoDir) Aggregate

func (dir *GoDir) Aggregate()

Aggregate recursively aggregates the total and covered statement count of the GoDir and its subdirectories and files.

type GoFile

type GoFile struct {
	*GoListItem
	ABSPath string
	Profile []cover.ProfileBlock
}

type GoListItem added in v0.2.3

type GoListItem struct {
	RelPkgPath string
	ID         string
	Title      string

	StmtCount        int
	StmtCoveredCount int
}

func NewGoListItem added in v0.2.3

func NewGoListItem(relPkgPath string) *GoListItem

func (*GoListItem) Percent added in v0.2.3

func (item *GoListItem) Percent() float64

Percent calculates the percentage of statement coverage for a GoListItem.

type GoProject

type GoProject struct {
	Dirs     map[string]*GoDir
	RootPath string
	Cutlines *config.Cutlines
}

func NewGoProject

func NewGoProject(root string, cutlines *config.Cutlines) *GoProject

func (*GoProject) Parse

func (gp *GoProject) Parse(input string) error

Parse parses the input profiles filename and updates the GoProject's coverage report.

func (*GoProject) Report

func (gp *GoProject) Report(wr io.Writer) error

Report generates an HTML report of the GoProject and writes it to the provided io.Writer. The report includes a directory tree of the project's files and directories, along with coverage information.

func (*GoProject) Root

func (gp *GoProject) Root() *GoDir

Root returns the root directory of the Go project.

func (*GoProject) SafeDir

func (gp *GoProject) SafeDir(relPkgPath string) *GoDir

SafeDir returns a pointer to a GoDir object for the given relative package path.

type Pkg

type Pkg struct {
	ImportPath string
	Dir        string
	Error      *struct {
		Err string
	}
}

Pkg describes a single package, compatible with the JSON output from 'go list'; see 'go help list'.

type TemplateData

type TemplateData struct {
	Views     []*TemplateViewData
	InitialID string
	Cutlines  *config.Cutlines
}

TemplateData is a struct that holds data for generating HTML templates.

func (*TemplateData) AddDir added in v0.2.3

func (td *TemplateData) AddDir(dir *GoDir, links []*TemplateLinkData) error

AddDir adds a directory to the template data.

func (*TemplateData) AddFile added in v0.2.3

func (td *TemplateData) AddFile(file *GoFile, links []*TemplateLinkData) error

AddFile adds a Go file to the template data with the given links and returns an error if any. The method also generates the HTML-escaped lines of code for the file and adds them to the view data.

type TemplateLinkData added in v0.2.3

type TemplateLinkData struct {
	ID    string
	Title string
}

TemplateLinkData represents the data needed for a link in a template.

type TemplateListItemData added in v0.2.3

type TemplateListItemData struct {
	ClassName      string
	ID             string
	Title          string
	Progress       string
	Percent        string
	NumStmtCovered int
	NumStmt        int
}

TemplateListItemData represents the data structure for a single item in the HTML template list.

func NewTemplateListItemData added in v0.2.3

func NewTemplateListItemData(item *GoListItem, cutlines *config.Cutlines) *TemplateListItemData

NewTemplateListItemData returns a new instance of TemplateListItemData based on the given GoListItem and Cutlines.

type TemplateViewData added in v0.2.3

type TemplateViewData struct {
	ID             string
	Percent        string
	NumStmtCovered int
	NumStmt        int
	Links          []*TemplateLinkData
	Items          []*TemplateListItemData
	Lines          string
	IsDir          bool
}

TemplateViewData represents the data needed to render a template view.

Jump to

Keyboard shortcuts

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