-
Notifications
You must be signed in to change notification settings - Fork 11
/
unix_only_test.go
123 lines (107 loc) · 3.51 KB
/
unix_only_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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
//go:build !windows
// +build !windows
package main
import (
"reflect"
"testing"
)
func Test_getCoverForDir(t *testing.T) {
t.Run("error", func(t *testing.T) {
_, _, err := getCoverForDir("./testdata/not_exists.out", []string{}, Config{colors256: false})
if err == nil {
t.Errorf("1. getCoverForDir() error failed")
}
})
t.Run("cover", func(t *testing.T) {
bytes, _, err := getCoverForDir("./testdata/cover_00.out", []string{}, Config{colors256: false})
if err != nil {
t.Errorf("2. getCoverForDir() failed: %v", err)
}
expect, err := readFile("./testdata/colored_00.txt")
if err != nil {
t.Errorf("3. getCoverForDir() failed: %v", err)
}
if !reflect.DeepEqual(bytes, expect) {
t.Errorf("4. getCoverForDir() not equal")
}
})
t.Run("cover with 256 colors", func(t *testing.T) {
bytes, _, err := getCoverForDir("./testdata/cover_00.out", []string{}, Config{colors256: true})
if err != nil {
t.Errorf("5. getCoverForDir() failed: %v", err)
}
expect, err := readFile("./testdata/colored_01.txt")
if err != nil {
t.Errorf("6. getCoverForDir() failed: %v", err)
}
if !reflect.DeepEqual(bytes, expect) {
t.Errorf("7. getCoverForDir() not equal")
}
})
t.Run("cover with 256 colors with error", func(t *testing.T) {
_, _, err := getCoverForDir("./testdata/cover_01.out", []string{}, Config{colors256: true})
if err == nil {
t.Errorf("8. getCoverForDir() not exists go file")
}
})
t.Run("cover 01 without 256 colors", func(t *testing.T) {
bytes, _, err := getCoverForDir("./testdata/cover_00.out", []string{"file_01.go"}, Config{colors256: false})
if err != nil {
t.Errorf("9. getCoverForDir() failed: %v", err)
}
expect, err := readFile("./testdata/colored_02.txt")
if err != nil {
t.Errorf("10. getCoverForDir() failed: %v", err)
}
if !reflect.DeepEqual(bytes, expect) {
t.Errorf("11. getCoverForDir() not equal")
}
})
t.Run("cover 02 without 256 colors", func(t *testing.T) {
bytes, _, err := getCoverForDir("./testdata/cover_02.out", []string{}, Config{colors256: false})
if err != nil {
t.Errorf("12. getCoverForDir() failed: %v", err)
}
expect, err := readFile("./testdata/colored_03.txt")
if err != nil {
t.Errorf("13. getCoverForDir() failed: %v", err)
}
if !reflect.DeepEqual(bytes, expect) {
t.Errorf("14. getCoverForDir() not equal\ngot:\n%s\nexpect:\n%s\n", bytes, expect)
}
})
}
func Test_getCoverForDir_mincov_flag(t *testing.T) {
t.Run("covered 100% mincov 100%", func(t *testing.T) {
conf := Config{
colors256: false,
minCoverage: 100.0,
}
// cover_00.out has 100% coverage of 2 files
_, profileBlocks, err := getCoverForDir("./testdata/cover_00.out", []string{"file_01.go"}, conf)
if err != nil {
t.Errorf("getCoverForDir() failed with error: %s", err)
}
expectLen := 2
actualLen := len(profileBlocks)
if expectLen != actualLen {
t.Errorf("1. minimum coverage 100%% should print all the blocks. want %v, got: %v", expectLen, actualLen)
}
})
t.Run("covered 100% mincov 50%", func(t *testing.T) {
conf := Config{
colors256: false,
minCoverage: 50.0,
}
// cover_00.out has 100% coverage of 2 files
_, profileBlocks, err := getCoverForDir("./testdata/cover_00.out", []string{"file_01.go"}, conf)
if err != nil {
t.Errorf("getCoverForDir() failed with error: %s", err)
}
expectLen := 0
actualLen := len(profileBlocks)
if expectLen != actualLen {
t.Errorf("2. minimum coverage 50%% for 100%% covered source should print nothing. want %v, got: %v", expectLen, actualLen)
}
})
}