neotest: sort coverage blocks within a test scope

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 <shaleva.ann@nspcc.ru>
This commit is contained in:
Anna Shaleva 2024-10-15 15:22:54 +03:00
parent c747bb8ff7
commit d8e945978a

View file

@ -1,10 +1,12 @@
package neotest package neotest
import ( import (
"cmp"
"flag" "flag"
"fmt" "fmt"
"io" "io"
"os" "os"
"slices"
"strconv" "strconv"
"sync" "sync"
"testing" "testing"
@ -201,6 +203,15 @@ func processCover() map[documentName][]*coverBlock {
for _, b := range mappedBlocks { for _, b := range mappedBlocks {
blocks = append(blocks, b) 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 cover[documentName] = blocks
} }