domain

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2022 License: Unlicense Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ParseFile = func(file io.Reader) coverage.CoverageLines {
	lineMatcher := coverage.NewLineMatcher()
	parsedLines := coverage.CoverageLines{}

	scanner := bufio.NewScanner(file)
	scanner.Split(bufio.ScanLines)
	for scanner.Scan() {
		line := scanner.Text()

		if strings.HasPrefix(line, "mode:") {
			continue
		}

		parsedLine, err := lineMatcher.Apply(line)
		if err == nil {
			parsedLines = append(parsedLines, parsedLine)
		}
	}

	return parsedLines
}
View Source
var ParseGoMod = func(f io.Reader) (module.GoMod, error) {
	goModContent, err := io.ReadAll(f)
	if err != nil {
		return module.GoMod{}, errors.New(fmt.Errorf("failed reading go.mod: %w", err))
	}

	regex := regexp.MustCompile(goModRegex)
	matches := regex.FindStringSubmatch(string(goModContent))
	if len(matches) != 3 {
		return module.GoMod{}, errors.New("couldn't detect go.mod components")
	}

	return module.GoMod{
		ModuleName: matches[1],
		GoVersion:  matches[2],
	}, nil
}
View Source
var ParseModule = func(rootDir string, srcAnalyzer ModuleAnalyzer) (module.Module, error) {
	gomodFile, err := os.Open(filepath.Clean(path.Join(rootDir, "go.mod")))
	if err != nil {
		return module.Module{}, errors.New(fmt.Errorf("failed opening go.mod: %w", err))
	}

	defer gomodFile.Close()

	gomod, err := ParseGoMod(gomodFile)
	if err != nil {
		return module.Module{}, err
	}

	analyzedFiles, err := srcAnalyzer(rootDir)
	if err != nil {
		return module.Module{}, err
	}

	return module.Module{
		GoMod: gomod,
		Files: analyzedFiles,
	}, nil
}

Functions

func BuildStatementStatistic

func BuildStatementStatistic(module module.Module, parsedCoverage coverage.CoverageLines) *statistic.ModuleStatistic

func Evaluate

func Evaluate(moduleStatistic statistic.ModuleStatistic, cfg dto.CoverageConfig) (errs []evaluation.CoverageError, err error)

func ExploreFunctions

func ExploreFunctions(filePath string) (functions []gosrc.Function, err error)

func GroupCoverageByDirectory

func GroupCoverageByDirectory(moduleName string, coverageLines coverage.CoverageLines) (group coverage.GroupedCoverage)

func NewPrinter

func NewPrinter(w io.Writer, fmt dto.Formatter) printer

Types

type GoModParser

type GoModParser func(io.Reader) (module.GoMod, error)

type GoSrcFile

type GoSrcFile struct {
	Name string
	Path string
}

type ModuleAnalyzer

type ModuleAnalyzer func(string) ([]gosrc.AnalyzedFile, error)

func NewModuleAnalyzer

func NewModuleAnalyzer(excludes []string) ModuleAnalyzer

type ModuleParser

type ModuleParser func(string, ModuleAnalyzer) (module.Module, error)

type Parser

type Parser func(io.Reader) coverage.CoverageLines

Jump to

Keyboard shortcuts

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