Skip to content

Commit

Permalink
neotest: sort coverage blocks within a test scope
Browse files Browse the repository at this point in the history
Make the behaviour similar to the `go test` output. It's not a problem
for the `go cover` tool, but the sorted file is easier to debug and analize.

Signed-off-by: Anna Shaleva <[email protected]>
  • Loading branch information
AnnaShaleva committed Oct 15, 2024
1 parent c747bb8 commit 8e650c7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/neotest/coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"os"
"slices"
"strconv"
"sync"
"testing"
Expand Down Expand Up @@ -201,6 +202,27 @@ func processCover() map[documentName][]*coverBlock {
for _, b := range mappedBlocks {
blocks = append(blocks, b)
}
slices.SortFunc(blocks, func(a, b *coverBlock) int {
if a.startLine != b.startLine {
return int(a.startLine - b.startLine)
}
if a.endLine != b.endLine {
return int(a.endLine - b.endLine)
}
if a.startCol != b.startCol {
return int(a.startCol - b.startCol)
}
if a.endCol != b.endCol {
return int(a.endCol - b.endCol)
}
if a.stmts != b.stmts {
return int(a.stmts - b.stmts)
}
if a.counts != b.counts {
return int(a.counts - b.counts)
}
return 0
})
cover[documentName] = blocks
}

Expand Down

0 comments on commit 8e650c7

Please sign in to comment.