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 8e650c752a

View file

@ -5,6 +5,7 @@ import (
"fmt"
"io"
"os"
"slices"
"strconv"
"sync"
"testing"
@ -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
}