-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdump_test.go
95 lines (73 loc) · 1.81 KB
/
dump_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"bytes"
"regexp"
"strings"
"testing"
"github.com/thatguystone/cog/check"
)
func testDump(file string, showCovered bool) (string, error) {
var out bytes.Buffer
err := dump(&out, file, showCovered)
return out.String(), err
}
func hasLines(t *testing.T, out string, lines []string) {
for _, line := range lines {
linere := strings.ReplaceAll(line, "\t", "\\s*")
r := regexp.MustCompile(linere)
check.Truef(t, r.MatchString(out), "%s did not match", line)
}
}
func TestDumpBasic(t *testing.T) {
t.Parallel()
out, err := testDump("testdata/basic/cover.out", false)
check.MustNil(t, err)
t.Log(out)
check.False(t, strings.Contains(out, "a.go"))
hasLines(t, out, []string{
"b.go 8 0 0.0% 3-20",
"TOTAL 17 9 52.9%",
})
}
func TestDumpShowCovered(t *testing.T) {
t.Parallel()
out, err := testDump("testdata/basic/cover.out", true)
check.MustNil(t, err)
t.Log(out)
hasLines(t, out, []string{
"a.go 8 8 100.0%",
"b.go 8 0 0.0% 3-20",
"TOTAL 17 9 52.9%",
})
}
func TestDumpNoFiles(t *testing.T) {
t.Parallel()
out, err := testDump("testdata/nofiles/cover.out", true)
check.MustNil(t, err)
check.Equal(t, out, "No files covered.\n")
}
func TestDumpCompleteCoverage(t *testing.T) {
t.Parallel()
out, err := testDump("testdata/fullcoverage/cover.out", false)
check.MustNil(t, err)
t.Log(out)
check.False(t, strings.Contains(out, "a.go"))
hasLines(t, out, []string{
"TOTAL 1 1 100.0%",
})
}
func TestDumpCompleteCoverageShowCovered(t *testing.T) {
t.Parallel()
out, err := testDump("testdata/fullcoverage/cover.out", true)
check.MustNil(t, err)
t.Log(out)
hasLines(t, out, []string{
"a.go 1 1 100.0%",
"TOTAL 1 1 100.0%",
})
}
func TestDumpInvalidCoverageFile(t *testing.T) {
t.Parallel()
_, err := testDump("testdata/basic/a.go", true)
check.NotNil(t, err)
}