From d8e945978af6fe7ee32ee62d249700d0758458cf 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 | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/neotest/coverage.go b/pkg/neotest/coverage.go index 7e502d9dc3..f22580ab30 100644 --- a/pkg/neotest/coverage.go +++ b/pkg/neotest/coverage.go @@ -1,10 +1,12 @@ package neotest import ( + "cmp" "flag" "fmt" "io" "os" + "slices" "strconv" "sync" "testing" @@ -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 }