Skip to content

xhd2015/go-coverage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

0b44ffd · Nov 2, 2024

History

45 Commits
Dec 8, 2022
Jan 5, 2024
Mar 20, 2023
Oct 25, 2022
Jan 5, 2024
Jan 5, 2024
Aug 14, 2022
Nov 2, 2024
May 16, 2023
Mar 21, 2023
Feb 10, 2023
Aug 14, 2022
Dec 7, 2022
Dec 20, 2022
Jan 10, 2023
Jan 10, 2023
Jan 10, 2023

Repository files navigation

Introduction

This library handles go-coverage files. It provides semantic coverage profile merging function. Check merge/merge.go for more details.

Example:

go test -run TestMergeProfile -v ./merge

Old Coverage: old

New Coverage: new

Merged Coverage: merged

Algorithm

The algorithm implementation is at merge/merge.go.

First, traverse the old and new AST tree to get each basic block's cleaned code. Simply put, cleaned code is code that gets compiled into assembly, excluding any space and comments.

Then, use myers diff to find unchanged blocks, see ComputeBlockMapping.In this step we map all blocks in new AST to their unchanged counterpart in old AST.

Finally, use the new-to-old mapping to merge counters, for unchanged blocks, counters are added together.

The algorithm effectively provides incrimental testing coverage across muiltpe changes(e.g. multiple git commits).

Diff

go generate ./...

Required go version: 1.16

When build with go1.14:

$ with-go1.14 go build ./...
# github.com/dop251/goja/parser
../../gopath/pkg/mod/github.com/dop251/goja@v0.0.0-20221229151140-b95230a9dbad/parser/parser.go:150:9: undefined: os.ReadFile
../../gopath/pkg/mod/github.com/dop251/goja@v0.0.0-20221229151140-b95230a9dbad/parser/statement.go:901:19: undefined: os.ReadFile
note: module requires Go 1.16

About

merge go test coverage profiles

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages