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 16, 2024
1 parent c747bb8 commit d8e9459
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/neotest/coverage.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package neotest

import (
"cmp"
"flag"
"fmt"
"io"
"os"
"slices"
"strconv"
"sync"
"testing"
Expand Down Expand Up @@ -201,6 +203,15 @@ func processCover() map[documentName][]*coverBlock {
for _, b := range mappedBlocks {
blocks = append(blocks, b)
}
slices.SortFunc(blocks, func(a, b *coverBlock) int {
return cmp.Or(
cmp.Compare(a.startLine, b.startLine),
cmp.Compare(a.endLine, b.endLine),
cmp.Compare(a.startCol, b.startCol),
cmp.Compare(a.endCol, b.endCol),
cmp.Compare(a.stmts, b.stmts),
cmp.Compare(a.counts, b.counts))
})
cover[documentName] = blocks
}

Expand Down

0 comments on commit d8e9459

Please sign in to comment.