From 23ad70fc2f2fc4f257ba460c7c12c9e5c304edb5 Mon Sep 17 00:00:00 2001 From: Ce Gao Date: Thu, 6 Aug 2020 14:14:17 +0800 Subject: [PATCH] fix: Fix order problem Signed-off-by: Ce Gao --- gocover.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/gocover.go b/gocover.go index 532efd9..133ccc4 100644 --- a/gocover.go +++ b/gocover.go @@ -46,17 +46,20 @@ func mergeProfs(pfss [][]*cover.Profile) []*cover.Profile { } head, rest := pfss[0], pfss[1:] ret := make([]*cover.Profile, 0, len(head)) - for i, profile := range head { + for _, profile := range head { for _, ps := range rest { // find profiles if len(ps) == 0 { continue - } else if len(ps) < i+1 { - continue - } else if ps[i].FileName != profile.FileName { + } else { + for _, p := range ps { + if p.FileName == profile.FileName { + profile.Blocks = mergeProfBlocks(profile.Blocks, p.Blocks) + break + } + } continue } - profile.Blocks = mergeProfBlocks(profile.Blocks, ps[i].Blocks) } ret = append(ret, profile) }