Skip to content

Commit

Permalink
Merge pull request #74 from k1LoW/fix-out-of-sync
Browse files Browse the repository at this point in the history
Fix: panic: assignment to entry in nil map
  • Loading branch information
k1LoW authored Sep 27, 2021
2 parents dfe1bcb + e959722 commit f89fa72
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/coverage/coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,13 @@ func (fc *FileCoverage) FindBlocksByLine(n int) BlockCoverages {
return BlockCoverages{}
}
if len(fc.cache) == 0 {
fc.cache = map[int]BlockCoverages{}
for _, b := range fc.Blocks {
for i := *b.StartLine; i <= *b.EndLine; i++ {
_, ok := fc.cache[i]
if !ok {
fc.cache[i] = BlockCoverages{}
}
fc.cache[i] = append(fc.cache[i], b)
}
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/coverage/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ func paintLine(n, w int, in string, blocks BlockCoverages) (string, string) {
if *b.EndLine == n && b.EndCol != nil {
e = *b.EndCol - 1
}
if e > lc {
// coverage report and source code are out of sync.
e = lc
}
for i := s; i < e; i++ {
l[i] = cl
}
Expand Down

0 comments on commit f89fa72

Please sign in to comment.