mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-25 03:47:18 +00:00
neotest: exclude RET statements from coverage
The sequence point bounds of all RET statements include the whole method
body, for example:
86ed214e8a/pkg/compiler/codegen.go (L542-L543)
Such behaviour breaks the resulting coverage report. A part of #3559.
Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
This commit is contained in:
parent
86ed214e8a
commit
de4b133406
1 changed files with 29 additions and 3 deletions
|
@ -51,6 +51,12 @@ var (
|
|||
|
||||
type scriptRawCoverage struct {
|
||||
debugInfo *compiler.DebugInfo
|
||||
// methodStartOffsets holds the set of script offsets that correspond to method
|
||||
// declaration start.
|
||||
methodStartOffsets map[uint16]struct{}
|
||||
// methodStartOffsets holds the set of script offsets that correspond to method
|
||||
// declaration end.
|
||||
methodEndOffsets map[uint16]struct{}
|
||||
offsetsVisited []int
|
||||
}
|
||||
|
||||
|
@ -174,6 +180,12 @@ func processCover() map[documentName][]*coverBlock {
|
|||
documentSeqPoints := documentSeqPoints(di, documentName)
|
||||
|
||||
for _, point := range documentSeqPoints {
|
||||
// Don't track RET statements since their bounds overlap the whole function
|
||||
// which break the resulting coverage report.
|
||||
_, isRET := scriptRawCoverage.methodEndOffsets[uint16(point.Opcode)]
|
||||
if isRET {
|
||||
continue
|
||||
}
|
||||
b := coverBlock{
|
||||
startLine: uint(point.StartLine),
|
||||
startCol: uint(point.StartCol),
|
||||
|
@ -193,6 +205,10 @@ func processCover() map[documentName][]*coverBlock {
|
|||
for _, offset := range scriptRawCoverage.offsetsVisited {
|
||||
for _, point := range documentSeqPoints {
|
||||
if point.Opcode == offset {
|
||||
_, ok := mappedBlocks[point.Opcode]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
mappedBlocks[point.Opcode].counts++
|
||||
}
|
||||
}
|
||||
|
@ -239,6 +255,16 @@ func addScriptToCoverage(c *Contract) {
|
|||
coverageLock.Lock()
|
||||
defer coverageLock.Unlock()
|
||||
if _, ok := rawCoverage[c.Hash]; !ok {
|
||||
rawCoverage[c.Hash] = &scriptRawCoverage{debugInfo: c.DebugInfo}
|
||||
startOffsets := make(map[uint16]struct{})
|
||||
endOffsets := make(map[uint16]struct{})
|
||||
for _, m := range c.DebugInfo.Methods {
|
||||
startOffsets[m.Range.Start] = struct{}{}
|
||||
endOffsets[m.Range.End] = struct{}{}
|
||||
}
|
||||
rawCoverage[c.Hash] = &scriptRawCoverage{
|
||||
debugInfo: c.DebugInfo,
|
||||
methodStartOffsets: startOffsets,
|
||||
methodEndOffsets: endOffsets,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue