annotation

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package annotation provides the utils for filtering.

There are two kinds of ignore.

  1. Ignore the whole go file. `//+gocover:ignore:file`

  2. Ignore a go code block. `//+gocover:ignore:block`

    Code block concept comes from the go coverage profile, the detail can be found at https://cs.opensource.google/go/x/tools/+/master:cover/profile.go;drc=81efdbcac4736176ac97c60577b0069f76414c44;l=28 https://go.dev/ref/spec#Blocks gives more details about it. For example: pf, err := os.Open(fileName) if err != nil { -| return nil, err | -> code block } -|

    { fmt.Println() -| profile, err := parseIgnoreProfilesFromReader(pf) | -> code block profile.Filename = fileName -| }

Index

Constants

This section is empty.

Variables

View Source
var (
	// IgnoreRegexp the regexp for the gocover ignore pattern.
	// Two kinds of ignore pattern are supported:
	// - block
	// - file
	//
	// This regexp matches the lines that
	// starts with any characters, then follows `//+gocover:ignore:` and following either `file` or `block`,
	// then comments about the intention.
	IgnoreRegexp = regexp.MustCompile(`.*//\s*\+gocover:ignore:(file|block)(\s*)(.*)`)

	ErrCommentsRequired      = errors.New("comments required")
	ErrWrongAnnotationFormat = errors.New("wrong ignore annotation format")
)

Functions

This section is empty.

Types

type IgnoreBlock

type IgnoreBlock struct {
	Annotation           string   // concrete ignore pattern
	AnnotationLineNumber int      // line number the ignore pattern locates at
	Contents             []string // ignore contents
	Lines                []int    // corresponding code line number of the ignore contents
	Comments             string   // comments about block ignore
}

IgnoreBlock represents a single block of ignore profiling data.

type IgnoreProfile

type IgnoreProfile struct {
	// type of the ignore profile.
	// when it's BLOCK_IGNORE, IgnoreBlocks contains the concrete ignore data.
	Type         IgnoreType
	Filename     string
	IgnoreBlocks map[cover.ProfileBlock]*IgnoreBlock
	Comments     string // comments about file ignore
	Annotation   string // concrete ignore pattern
}

IgnoreProfile represents the ignore profiling data for a specific file.

func ParseIgnoreProfiles

func ParseIgnoreProfiles(fileName string, coverProfile *cover.Profile) (*IgnoreProfile, error)

ParseIgnoreProfiles parses ignore profile data in the specified file with the help of go unit test cover profile, and returns a ignore profile. The ProfileBlock in the cover profile is already sorted.

type IgnoreType

type IgnoreType string

IgnoreType indicates the type of the ignore profile. - FILE_IGNORE means the profile ignore the whole input file. - BLOCK_IGNORE means the profile ignore several code block of the input file.

const (
	FILE_IGNORE  IgnoreType = "file"
	BLOCK_IGNORE IgnoreType = "block"
)

Jump to

Keyboard shortcuts

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