-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
paralleltest.go
140 lines (116 loc) · 3.85 KB
/
paralleltest.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
//args: -Eparalleltest
package testdata
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(t *testing.T) {
t.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) {} // ERROR "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 { // ERROR "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) { // ERROR "Function TestFunctionMissingCallToParallelAndRangeNotUsingRangeValueInTDotRun missing the call to method parallel"
testCases := []struct {
name string
}{{name: "foo"}}
for _, tc := range testCases { // ERROR "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 { // ERROR "Range statement for test TestFunctionRangeNotUsingRangeValueInTDotRun does not use range value in test Run"
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 { // ERROR "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) { // ERROR "Function TestFunctionTwoTestRunMissingCallToParallel has missing the call to method parallel in the test run"
fmt.Println("1")
})
t.Run("2", func(t *testing.T) { // ERROR "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) { // ERROR "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(t *testing.T) {
t.Parallel()
fmt.Println("1")
})
t.Run("2", func(t *testing.T) { // ERROR "Function TestFunctionSecondOneTestRunMissingCallToParallel has missing the call to method parallel in the test run"
fmt.Println("2")
})
}