-
Notifications
You must be signed in to change notification settings - Fork 9
/
gotesplit_test.go
173 lines (162 loc) · 4.05 KB
/
gotesplit_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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package gotesplit
import (
"os"
"reflect"
"testing"
)
func TestGetTestList(t *testing.T) {
const sample = `TestDoCreate
TestCommandGet
TestLook
TestDoGet_bulk
TestCommandList
TestCommandListUnique
TestCommandListUnknown
TestDoList_query
TestDoList_unique
TestDoList_unknownRoot
TestDoList_notPermittedRoot
TestDoList_withSystemHiddenDir
TestDoRoot
TestDetectLocalRepoRoot
TestDetectVCSAndRepoURL
TestLocalRepositoryFromFullPath
TestNewLocalRepository
TestLocalRepositoryRoots
TestList_Symlink
TestList_Symlink_In_Same_Directory
TestFindVCSBackend
TestLocalRepository_VCS
TestLocalRepositoryRoots_URLMatchLocalRepositoryRoots
TestNewRemoteRepository
TestNewRemoteRepository_vcs_error
TestNewRemoteRepository_error
TestNewURL
TestConvertGitURLHTTPToSSH
TestNewURL_err
TestFillUsernameToPath_err
TestVCSBackend
TestCvsDummyBackend
TestBranchOptionIgnoredErrors
ok github.com/x-motemen/ghq 0.114s
TestRunInDirSilently
TestRun
TestRunInDir
TestRunSilently
ok github.com/x-motemen/ghq/cmdutil 0.059s
? github.com/x-motemen/ghq/hoge [no test files]
TestLog
ok github.com/x-motemen/ghq/logger 0.106s`
var expect []testList = []testList{{
pkg: "github.com/x-motemen/ghq/logger",
list: []string{
"TestLog",
}}, {
pkg: "github.com/x-motemen/ghq/cmdutil",
list: []string{
"TestRun",
"TestRunInDir",
"TestRunInDirSilently",
"TestRunSilently",
}}, {
pkg: "github.com/x-motemen/ghq",
list: []string{
"TestBranchOptionIgnoredErrors",
"TestCommandGet",
"TestCommandList",
"TestCommandListUnique",
"TestCommandListUnknown",
"TestConvertGitURLHTTPToSSH",
"TestCvsDummyBackend",
"TestDetectLocalRepoRoot",
"TestDetectVCSAndRepoURL",
"TestDoCreate",
"TestDoGet_bulk",
"TestDoList_notPermittedRoot",
"TestDoList_query",
"TestDoList_unique",
"TestDoList_unknownRoot",
"TestDoList_withSystemHiddenDir",
"TestDoRoot",
"TestFillUsernameToPath_err",
"TestFindVCSBackend",
"TestList_Symlink",
"TestList_Symlink_In_Same_Directory",
"TestLocalRepositoryFromFullPath",
"TestLocalRepositoryRoots",
"TestLocalRepositoryRoots_URLMatchLocalRepositoryRoots",
"TestLocalRepository_VCS",
"TestLook",
"TestNewLocalRepository",
"TestNewRemoteRepository",
"TestNewRemoteRepository_error",
"TestNewRemoteRepository_vcs_error",
"TestNewURL",
"TestNewURL_err",
"TestVCSBackend",
}}}
got := getTestLists(sample)
if !reflect.DeepEqual(expect, got) {
t.Errorf("expect: %#v\ngot: %#v", expect, got)
}
}
func TestDetectTags(t *testing.T) {
testCases := []struct {
input []string
expect string
}{
{[]string{"aa", "bb"}, ""},
{[]string{"aa", "-tags", "bb"}, "-tags=bb"},
{[]string{"aa", "--tags=ccc", "bb"}, "--tags=ccc"},
{[]string{"aa", "-tags"}, "-tags"},
}
for _, tc := range testCases {
t.Run(tc.expect, func(t *testing.T) {
out := detectTags(tc.input)
if out != tc.expect {
t.Errorf("got: %s, expect: %s", out, tc.expect)
}
})
}
}
func TestDetectRace(t *testing.T) {
testCases := []struct {
input []string
expect bool
desc string
}{
{[]string{"-race"}, true, "-race only"},
{[]string{"-tags", "aaa", "-race", "-bench"}, true, "-race with other flags"},
{[]string{"--race", "-p", "1"}, true, "--race with other flags"},
{[]string{}, false, "no flags"},
{[]string{"-short", "-p", "1"}, false, "flags without -race"},
}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
out := detectRace(tc.input)
if out != tc.expect {
t.Errorf("got: %t, expect: %t", out, tc.expect)
}
})
}
}
func TestGetTestListFromPkgs(t *testing.T) {
if err := os.Chdir("testdata/withtags"); err != nil {
wd, _ := os.Getwd()
t.Fatalf("unexpected error: %v, cwd: %s", err, wd)
}
expect := []testList{{
pkg: "github.com/Songmu/gotesplit/testdata/withtags",
list: []string{
"TestNoTag",
"TestTagA",
},
}}
got, err := getTestListsFromPkgs([]string{"."}, "-tags=a", false)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if !reflect.DeepEqual(expect, got) {
t.Errorf("expect: %#v\ngot: %#v", expect, got)
}
}