1
16
17 package cov_test
18
19 import (
20 "reflect"
21 "testing"
22
23 "golang.org/x/tools/cover"
24
25 "edge-infra.dev/third_party/gopherage/pkg/cov"
26 )
27
28 func TestAggregateProfilesSingleProfile(t *testing.T) {
29 p := [][]*cover.Profile{
30 {
31 {
32 FileName: "a.go",
33 Mode: "count",
34 Blocks: []cover.ProfileBlock{
35 {StartLine: 1, StartCol: 14, EndLine: 5, EndCol: 13, NumStmt: 4, Count: 3},
36 {StartLine: 7, StartCol: 4, EndLine: 12, EndCol: 4, NumStmt: 3, Count: 0},
37 },
38 },
39 {
40 FileName: "b.go",
41 Mode: "count",
42 Blocks: []cover.ProfileBlock{
43 {StartLine: 3, StartCol: 2, EndLine: 7, EndCol: 2, NumStmt: 3, Count: 1},
44 },
45 },
46 },
47 }
48
49 aggregate, err := cov.AggregateProfiles(p)
50 if err != nil {
51 t.Fatalf("AggregateProfiles failed: %v", err)
52 }
53
54 expected := []*cover.Profile{
55 {
56 FileName: "a.go",
57 Mode: "count",
58 Blocks: []cover.ProfileBlock{
59 {StartLine: 1, StartCol: 14, EndLine: 5, EndCol: 13, NumStmt: 4, Count: 1},
60 {StartLine: 7, StartCol: 4, EndLine: 12, EndCol: 4, NumStmt: 3, Count: 0},
61 },
62 },
63 {
64 FileName: "b.go",
65 Mode: "count",
66 Blocks: []cover.ProfileBlock{
67 {StartLine: 3, StartCol: 2, EndLine: 7, EndCol: 2, NumStmt: 3, Count: 1},
68 },
69 },
70 }
71
72 if !reflect.DeepEqual(aggregate, expected) {
73 t.Fatal("aggregate profile incorrect")
74 }
75 }
76
77 func TestAggregateProfilesOverlapping(t *testing.T) {
78 p := [][]*cover.Profile{
79 {
80 {
81 FileName: "a.go",
82 Mode: "count",
83 Blocks: []cover.ProfileBlock{
84 {StartLine: 1, StartCol: 14, EndLine: 5, EndCol: 13, NumStmt: 4, Count: 3},
85 {StartLine: 7, StartCol: 4, EndLine: 12, EndCol: 4, NumStmt: 3, Count: 0},
86 {StartLine: 14, StartCol: 3, EndLine: 19, EndCol: 4, NumStmt: 6, Count: 0},
87 },
88 },
89 },
90 {
91 {
92 FileName: "a.go",
93 Mode: "count",
94 Blocks: []cover.ProfileBlock{
95 {StartLine: 1, StartCol: 14, EndLine: 5, EndCol: 13, NumStmt: 4, Count: 0},
96 {StartLine: 7, StartCol: 4, EndLine: 12, EndCol: 4, NumStmt: 3, Count: 4},
97 {StartLine: 14, StartCol: 3, EndLine: 19, EndCol: 4, NumStmt: 6, Count: 0},
98 },
99 },
100 },
101 }
102
103 aggregate, err := cov.AggregateProfiles(p)
104 if err != nil {
105 t.Fatalf("AggregateProfiles failed: %v", err)
106 }
107
108 expected := []*cover.Profile{
109 {
110 FileName: "a.go",
111 Mode: "count",
112 Blocks: []cover.ProfileBlock{
113 {StartLine: 1, StartCol: 14, EndLine: 5, EndCol: 13, NumStmt: 4, Count: 1},
114 {StartLine: 7, StartCol: 4, EndLine: 12, EndCol: 4, NumStmt: 3, Count: 1},
115 {StartLine: 14, StartCol: 3, EndLine: 19, EndCol: 4, NumStmt: 6, Count: 0},
116 },
117 },
118 }
119
120 if !reflect.DeepEqual(aggregate, expected) {
121 t.Fatal("aggregate profile incorrect")
122 }
123 }
124
View as plain text