From 8e650c752a58561d02e7c79dad5429d86c9992d5 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Tue, 15 Oct 2024 15:22:54 +0300 Subject: [PATCH] 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 --- pkg/neotest/coverage.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pkg/neotest/coverage.go b/pkg/neotest/coverage.go index 7e502d9dc3..0f9e2a5912 100644 --- a/pkg/neotest/coverage.go +++ b/pkg/neotest/coverage.go @@ -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 }