forked from kunwardeep/paralleltest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
t_test.go
163 lines (133 loc) · 4.45 KB
/
t_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
package t
import (
"fmt"
"testing"
)
func NoATestFunction() {}
func TestingFunctionLooksLikeATestButIsNotWithParam() {}
func TestingFunctionLooksLikeATestButIsWithParam(i int) {}
func AbcFunctionSuccessful(t *testing.T) {}
func TestFunctionSuccessfulRangeTest(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
}{{name: "foo"}}
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(x *testing.T) {
x.Parallel()
fmt.Println(tc.name)
})
}
}
func TestFunctionSuccessfulNoRangeTest(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
}{{name: "foo"}, {name: "bar"}}
t.Run(testCases[0].name, func(t *testing.T) {
t.Parallel()
fmt.Println(testCases[0].name)
})
t.Run(testCases[1].name, func(t *testing.T) {
t.Parallel()
fmt.Println(testCases[1].name)
})
}
func TestFunctionMissingCallToParallel(t *testing.T) {} // want "Function TestFunctionMissingCallToParallel missing the call to method parallel"
func TestFunctionRangeMissingCallToParallel(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
}{{name: "foo"}}
// this range loop should be okay as it does not have test Run
for _, tc := range testCases {
fmt.Println(tc.name)
}
for _, tc := range testCases { // want "Range statement for test TestFunctionRangeMissingCallToParallel missing the call to method parallel in test Run"
t.Run(tc.name, func(t *testing.T) {
fmt.Println(tc.name)
})
}
}
func TestFunctionMissingCallToParallelAndRangeNotUsingRangeValueInTDotRun(t *testing.T) { // want "Function TestFunctionMissingCallToParallelAndRangeNotUsingRangeValueInTDotRun missing the call to method parallel"
testCases := []struct {
name string
}{{name: "foo"}}
for _, tc := range testCases { // want "Range statement for test TestFunctionMissingCallToParallelAndRangeNotUsingRangeValueInTDotRun missing the call to method parallel in test Run"
t.Run(tc.name, func(t *testing.T) {
fmt.Println(tc.name)
})
}
}
func TestFunctionRangeNotUsingRangeValueInTDotRun(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
}{{name: "foo"}}
for _, tc := range testCases { // want "Range statement for test TestFunctionRangeNotUsingRangeValueInTDotRun does not reinitialise the variable tc"
t.Run("tc.name", func(t *testing.T) {
t.Parallel()
fmt.Println(tc.name)
})
}
}
func TestFunctionRangeNotReInitialisingVariable(t *testing.T) {
t.Parallel()
testCases := []struct {
name string
}{{name: "foo"}}
for _, tc := range testCases { // want "Range statement for test TestFunctionRangeNotReInitialisingVariable does not reinitialise the variable tc"
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
fmt.Println(tc.name)
})
}
}
func TestFunctionTwoTestRunMissingCallToParallel(t *testing.T) {
t.Parallel()
t.Run("1", func(t *testing.T) { // want "Function TestFunctionTwoTestRunMissingCallToParallel has missing the call to method parallel in the test run"
fmt.Println("1")
})
t.Run("2", func(t *testing.T) { // want "Function TestFunctionTwoTestRunMissingCallToParallel has missing the call to method parallel in the test run"
fmt.Println("2")
})
}
func TestFunctionFirstOneTestRunMissingCallToParallel(t *testing.T) {
t.Parallel()
t.Run("1", func(t *testing.T) { // want "Function TestFunctionFirstOneTestRunMissingCallToParallel has missing the call to method parallel in the test run"
fmt.Println("1")
})
t.Run("2", func(t *testing.T) {
t.Parallel()
fmt.Println("2")
})
}
func TestFunctionSecondOneTestRunMissingCallToParallel(t *testing.T) {
t.Parallel()
t.Run("1", func(x *testing.T) {
x.Parallel()
fmt.Println("1")
})
t.Run("2", func(t *testing.T) { // want "Function TestFunctionSecondOneTestRunMissingCallToParallel has missing the call to method parallel in the test run"
fmt.Println("2")
})
}
type notATest int
func (notATest) Run(args ...interface{}) {}
func (notATest) Parallel() {}
func TestFunctionWithRunLookalike(t *testing.T) {
t.Parallel()
var other notATest
// These aren't t.Run, so they shouldn't be flagged as Run invocations missing calls to Parallel.
other.Run(1, 1)
other.Run(2, 2)
}
func TestFunctionWithParallelLookalike(t *testing.T) { // want "Function TestFunctionWithParallelLookalike missing the call to method parallel"
var other notATest
// This isn't t.Parallel, so it doesn't qualify as a call to Parallel.
other.Parallel()
}
func TestFunctionWithOtherTestingVar(q *testing.T) {
q.Parallel()
}