lib

package
v0.0.0-...-92b3af4 Latest Latest
Warning

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

Go to latest
Published: May 14, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InvalidFormatCode = iota + 400
	InvalidLevelCode
	InvalidColorCode
	UnresolvableFsPath
)

Variables

This section is empty.

Functions

func FileExists

func FileExists(filePath string) bool

func GetCommonRoot

func GetCommonRoot(rfs []ReportedFile) string

func GetCoveredPct

func GetCoveredPct(blocks []cover.ProfileBlock, multiplied bool) (result float64)

Calculates the covered percentage for a profile, optionally multiplied by 100.

func GetOutPathInfo

func GetOutPathInfo(outPath string, fileName string, ext string, root string) (dispPath, rprtPath string)

func GetRelRootPath

func GetRelRootPath(outFilePath, commonRoot string) string

func GetSourceCode

func GetSourceCode(sourceFile string) (result string, err error)

GetSourceFilePath returns the contents of a file.

func GetSourceFilePath

func GetSourceFilePath(sourceDir string, sourceFile string) (string, error)

func HandleStopError

func HandleStopError(err error)

func InsertStringAt

func InsertStringAt(str string, insert string, index int) string

func MakeFile

func MakeFile(filePath string) (*os.File, error)

func MakeFileDir

func MakeFileDir(filePath string) error

func Offset

func Offset(reader *bytes.Reader) int

func ReverseArray

func ReverseArray[T any](array []T) []T

func SwapFileExt

func SwapFileExt(filePath string, ext string) string

Types

type AppConfig

type AppConfig struct {
	// The output format to use
	Format string `json:"format" yaml:"format" xml:"format"`
	// Whether to build a full report or summary
	Level string `json:"level" yaml:"level" xml:"level"`
	// The file or directory path to write the output to
	Output string `json:"output" yaml:"output" xml:"output"`
	// The input coverage file from `go test -coverprofile`
	Input []string `json:"input" yaml:"input" xml:"input"`
	// The source code folder location on disk
	SourceDir string `json:"source" yaml:"source" xml:"source"`
	// The display name of the package
	ProjectName string `json:"ProjectName" yaml:"ProjectName" xml:"ProjectName"`
}

AppConfig is the application configuration

type AppError

type AppError struct {
	Message string `json:"message" yaml:"message" xml:"message"`
	Code    int    `json:"code" yaml:"code" xml:"code"`
}

func InvalidArgError

func InvalidArgError(name string, value string, options []string, code int) AppError

func UnresolvablePathError

func UnresolvablePathError(fsPath string) AppError

func (AppError) Error

func (ae AppError) Error() string

type PathTuple

type PathTuple struct {
	// The displayable name for this path
	Name string `json:"name"`
	// The navigable path for this path
	Path string `json:"path"`
}

PathTuple is a tuple of a displayable name and a navigable path

func GetRelPathParts

func GetRelPathParts(commonRoot, filePath string) []PathTuple

type ReportContainer

type ReportContainer interface {
	// AddFolder adds a ReportedFolder to the container
	AddFolder(rf *ReportedFolder)
	// ContainsFolder returns true, and a pointer to ReportedFolder if the container contains a ReportedFolder with the given path
	ContainsFolder(folderPath string) (*ReportedFolder, bool)
	// AddFile adds a ReportedFile to the container
	AddFile(rf *ReportedFile)
	// ContainsFile returns true, and a pointer to ReportedFile if the container contains a ReportedFile with the given path
	ContainsFile(filePath string) (*ReportedFile, bool)
	// Updates the roll-up coverage value for the container and all children
	UpdateCoverage()
}

type ReportContext

type ReportContext struct {
	// The application configuration
	Config AppConfig `json:"config" yaml:"config" xml:"config"`
	// The associated metadata for the report
	Meta ReportMeta `json:"meta" yaml:"meta" xml:"meta"`
	// All reported files from the coverage report
	ReportedFiles []*ReportedFile `json:"reportedFiles" yaml:"reportedFiles" xml:"reportedFiles"`
	// ReportedFolders is an array of ReportedFolder entries, each containing at least one reported file
	ReportedFolders []*ReportedFolder `json:"reportedFolders" yaml:"reportedFolders" xml:"reportedFolders"`
	// Whether this is a full report or summary
	IsFullReport bool `json:"isFullReport" yaml:"isFullReport" xml:"isFullReport"`
	// The file or directory path where the output will be written
	Output string `json:"output" yaml:"output" xml:"output"`
	// The coverage percentage for the entire report
	CoveredPct float64 `json:"coveredPct" yaml:"coveredPct" xml:"coveredPct"`
}

The top-level context for coverage reporting

func NewReportContext

func NewReportContext(config AppConfig, meta ReportMeta, isFullRpt bool) ReportContext

Creates a new ReportContext

func (*ReportContext) AddFile

func (rc *ReportContext) AddFile(file *ReportedFile)

AddFile adds a ReportedFile to the context.ReportedFiles, creating the folder if it doesn't already exist.

func (*ReportContext) AddFolder

func (rc *ReportContext) AddFolder(folder *ReportedFolder)

AddFolder adds a ReportedFolder to the context.ReportedFolders, creating the folder if it doesn't already exist.

func (*ReportContext) AddFolderFile

func (rc *ReportContext) AddFolderFile(folderPath string, file *ReportedFile)

AddFolderFile adds a ReportedFile to the context.ReportedFolders, creating the folder if it doesn't already exist.

func (*ReportContext) AddProfile

func (rc *ReportContext) AddProfile(profile *cover.Profile)

AddProfile add a cover.Profile to the context.ReportedFiles as a ReportedFile

func (*ReportContext) ContainsFile

func (rc *ReportContext) ContainsFile(filePath string) (*ReportedFile, bool)

ContainsFile returns true if the context.ReportedFiles contains a file with the given path

func (*ReportContext) ContainsFolder

func (rc *ReportContext) ContainsFolder(folderPath string) (*ReportedFolder, bool)

ContainsFolder returns true if the context.ReportedFolders contains a folder with the given path

func (*ReportContext) GetAllFolders

func (rc *ReportContext) GetAllFolders() []*ReportedFolder

func (*ReportContext) GetPseudoFolder

func (rc *ReportContext) GetPseudoFolder() *ReportedFolder

GetPseudoFolder returns a ReportedFolder that represents the root folder of the source code

func (*ReportContext) UpdateCoverage

func (rc *ReportContext) UpdateCoverage()

UpdateCoverage updates the coverage percentage for each folder in the context.ReportedFolders based on the covered files.

type ReportMeta

type ReportMeta struct {
	// The display name of the package
	ProjectName string `json:"ProjectName" yaml:"ProjectName" xml:"ProjectName"`
	// The common root directory path for all reported files
	CommonRoot string `json:"commonRoot" yaml:"commonRoot" xml:"commonRoot"`
	// The parent of the CommonRoot directory path
	ParentRoot string `json:"parentRoot" yaml:"parentRoot" xml:"parentRoot"`
}

The basic meta data for the report

type ReportedBlock

type ReportedBlock struct {
	// The start line number for this block
	StartLine int `json:"start"`
	// The start column number for this block
	StartCol int `json:"startCol"`
	// The stop line number for this block
	StopLine int `json:"stop"`
	// The stop column number for this block
	StopCol int `json:"stopCol"`
	// Whether or not this block is covered
	Covered bool `json:"covered"`
}

func GetProfiledLines

func GetProfiledLines(cp *cover.Profile) (reportedLines, coveredLines []ReportedBlock)

GetLines returns the reported and covered lines for this file.

type ReportedFile

type ReportedFile struct {
	// The associated metadata for the report
	Meta ReportMeta `json:"meta" yaml:"meta" xml:"meta"`
	// The resolved source file for this coverage profile
	SourceFile string `json:"sourceFile" yaml:"sourceFile" xml:"sourceFile"`
	// The reported lines, covered an uncovered for this file
	ReportedLines []ReportedBlock `json:"reportedLines" yaml:"reportedLines" xml:"reportedLines"`
	// The reported lines that are covered for this file
	CoveredLines []ReportedBlock `json:"coveredLines" yaml:"coveredLines" xml:"coveredLines"`
	// A map of the path parts for this file, the key is displayable and the value is navigable
	PathParts []PathTuple `json:"pathParts" yaml:"pathParts" xml:"pathParts"`
	// The display path for this file
	DisplayPath string `json:"displayPath" yaml:"displayPath" xml:"displayPath"`
	// The output file path for this file with a '.out' extension
	OutFilePath string `json:"outFilePath" yaml:"outFilePath" xml:"outFilePath"`
	// The file name for this file
	FileName string `json:"fileName" yaml:"fileName" xml:"fileName"`
	// The source code for this file
	SourceCode string `json:"sourceCode" yaml:"sourceCode" xml:"sourceCode"`

	// The relative path to the assets folder from this file
	AssetsPath string `json:"assetsPath" yaml:"assetsPath" xml:"assetsPath"`
	// The percentage of coverage for this file
	CoveredPct float64 `json:"coveredPct" yaml:"coveredPct" xml:"coveredPct"`
	// The coverage profile for this file
	Profile *cover.Profile `json:"-" yaml:"-" xml:"-"`
	// contains filtered or unexported fields
}

ReportedFile is a wrapper around cover.Profile that includes additional metadata

func NewReportedFile

func NewReportedFile(context *ReportContext, profile *cover.Profile) ReportedFile

func (*ReportedFile) GetCoveredPct

func (rf *ReportedFile) GetCoveredPct(multiplied bool) (result float64)

GetCoveredPct returns the percentage of statements covered for all blocks in this file.

func (*ReportedFile) GetSourceCode

func (rf *ReportedFile) GetSourceCode() (result string, err error)

GetSourceCode returns the source code for this file.

func (*ReportedFile) WithExtension

func (rf *ReportedFile) WithExtension(ext string) string

WithExtension gets the output file path for the file with the specified extension.

type ReportedFolder

type ReportedFolder struct {
	// The associated metadata for the report
	Meta ReportMeta `json:"meta" yaml:"meta" xml:"meta"`
	// The reported files for this folder
	ReportedFiles []*ReportedFile `json:"sourceFiles" yaml:"sourceFiles" xml:"sourceFiles"`
	// The reported subfolder for this folder
	ReportedFolders []*ReportedFolder `json:"reportedFolders" yaml:"reportedFolders" xml:"reportedFolders"`
	// The resolved folder path for this folder
	FolderPath string `json:"folderPath" yaml:"folderPath" xml:"folderPath"`
	// The name for this folder
	FolderName string `json:"folderName" yaml:"folderName" xml:"folderName"`
	// The path parts for this folder
	PathParts []PathTuple `json:"pathParts" yaml:"pathParts" xml:"pathParts"`
	// The display path for this folder
	DisplayPath string `json:"displayPath" yaml:"displayPath" xml:"displayPath"`
	// The output file path for this folder
	OutFilePath string `json:"outFilePath" yaml:"outFilePath" xml:"outFilePath"`
	// The relative path to the assets folder from this folder
	AssetsPath string `json:"assetsPath" yaml:"assetsPath" xml:"assetsPath"`
	// The roll-up percentage of coverage for the files in this folder
	CoveredPct float64 `json:"coveredPct" yaml:"coveredPct" xml:"coveredPct"`
}

A ReportedFolder is a meta-level representation of a folder of ReportedFile entries

func NewReportedFolder

func NewReportedFolder(context *ReportContext, folderPath string, files ...*ReportedFile) ReportedFolder

func (*ReportedFolder) AddFile

func (rf *ReportedFolder) AddFile(file *ReportedFile)

AddFile adds a ReportedFile to the folder, if it doesn't already exist.

func (*ReportedFolder) AddFolder

func (rf *ReportedFolder) AddFolder(folder *ReportedFolder)

AddFolder adds a ReportedFolder to the folder, if it doesn't already exist.

func (*ReportedFolder) ContainsFile

func (rf *ReportedFolder) ContainsFile(filePath string) (*ReportedFile, bool)

ContainsFile returns true if the folder contains a file with the given path

func (*ReportedFolder) ContainsFolder

func (rf *ReportedFolder) ContainsFolder(folderPath string) (*ReportedFolder, bool)

ContainsFolder returns true, and a pointer to the ReportedFolder if the folder contains a folder with the given path

func (*ReportedFolder) GetAllFolders

func (rc *ReportedFolder) GetAllFolders() []*ReportedFolder

func (*ReportedFolder) GetProfileBlocks

func (rf *ReportedFolder) GetProfileBlocks() []cover.ProfileBlock

GetProfileBlocks gets the covered blocks for the folder, and all sub-folders.

func (*ReportedFolder) UpdateCoverage

func (rf *ReportedFolder) UpdateCoverage()

UpdateCoverage updates the coverage percentage for the folder based on the covered files.

func (*ReportedFolder) WithExtension

func (rf *ReportedFolder) WithExtension(ext string) string

WithExtension gets the output file path for the folder with the specified extension.

Jump to

Keyboard shortcuts

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