Skip to content

Commit 5a71a9e

Browse files
README.md cleanups
1 parent bc80137 commit 5a71a9e

File tree

1 file changed

+80
-83
lines changed

1 file changed

+80
-83
lines changed

README.md

Lines changed: 80 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -4,141 +4,138 @@
44

55
The Go linter `paralleltest` checks that the t.Parallel gets called for the test method and for the range of test cases within the test.
66

7-
87
## Usage
98

10-
```
9+
```sh
1110
paralleltest ./...
1211
```
1312

1413
## Examples
1514

16-
### Missing t.Parallel() in the test method
15+
### Missing `t.Parallel()` in the test method
1716

1817
```go
1918
// bad
2019
func TestFunctionMissingCallToParallel(t *testing.T) {
21-
}
20+
}
2221

2322
// good
2423
func TestFunctionMissingCallToParallel(t *testing.T) {
25-
t.Parallel()
26-
// ^ call to t.Parallel()
27-
}
24+
t.Parallel()
25+
// ^ call to t.Parallel()
26+
}
2827
// Error displayed
2928
// Function TestFunctionMissingCallToParallel missing the call to method parallel
3029
```
3130

32-
### Missing t.Parallel() in the range method
31+
### Missing `t.Parallel()` in the range method
3332

3433
```go
3534
// bad
3635
func TestFunctionRangeMissingCallToParallel(t *testing.T) {
37-
t.Parallel()
36+
t.Parallel()
3837

39-
testCases := []struct {
40-
name string
41-
}{{name: "foo"}}
38+
testCases := []struct {
39+
name string
40+
}{{name: "foo"}}
4241

43-
for _, tc := range testCases {
44-
t.Run(tc.name, func(t *testing.T) {
45-
fmt.Println(tc.name)
46-
})
47-
}
42+
for _, tc := range testCases {
43+
t.Run(tc.name, func(t *testing.T) {
44+
fmt.Println(tc.name)
45+
})
46+
}
4847
}
4948

5049
// good
5150
func TestFunctionRangeMissingCallToParallel(t *testing.T) {
52-
t.Parallel()
53-
54-
testCases := []struct {
55-
name string
56-
}{{name: "foo"}}
57-
58-
for _, tc := range testCases {
59-
t.Run(tc.name, func(t *testing.T) {
60-
t.Parallel()
61-
// ^ call to t.Parallel()
62-
fmt.Println(tc.name)
63-
})
64-
}
65-
}
51+
t.Parallel()
52+
53+
testCases := []struct {
54+
name string
55+
}{{name: "foo"}}
56+
57+
for _, tc := range testCases {
58+
t.Run(tc.name, func(t *testing.T) {
59+
t.Parallel()
60+
// ^ call to t.Parallel()
61+
fmt.Println(tc.name)
62+
})
63+
}
64+
}
6665
// Error displayed
6766
// Range statement for test TestFunctionRangeMissingCallToParallel missing the call to method parallel in t.Run
6867
```
6968

70-
71-
72-
### t.Parallel() is called in the range method but testcase variable not being used
69+
### `t.Parallel()` is called in the range method but testcase variable not being used
7370

7471
```go
7572
// bad
7673
func TestFunctionRangeNotUsingRangeValueInTDotRun(t *testing.T) {
77-
t.Parallel()
78-
79-
testCases := []struct {
80-
name string
81-
}{{name: "foo"}}
82-
for _, tc := range testCases {
83-
t.Run("this is a test name", func(t *testing.T) {
84-
// ^ call to tc.name missing
85-
t.Parallel()
86-
fmt.Println(tc.name)
87-
})
88-
}
74+
t.Parallel()
75+
76+
testCases := []struct {
77+
name string
78+
}{{name: "foo"}}
79+
for _, tc := range testCases {
80+
t.Run("this is a test name", func(t *testing.T) {
81+
// ^ call to tc.name missing
82+
t.Parallel()
83+
fmt.Println(tc.name)
84+
})
85+
}
8986
}
9087

9188
// good
9289
func TestFunctionRangeNotUsingRangeValueInTDotRun(t *testing.T) {
93-
t.Parallel()
94-
95-
testCases := []struct {
96-
name string
97-
}{{name: "foo"}}
98-
for _, tc := range testCases {
99-
t.Run(tc.name, func(t *testing.T) {
100-
// ^ call to tc.name
101-
t.Parallel()
102-
fmt.Println(tc.name)
103-
})
104-
}
90+
t.Parallel()
91+
92+
testCases := []struct {
93+
name string
94+
}{{name: "foo"}}
95+
for _, tc := range testCases {
96+
t.Run(tc.name, func(t *testing.T) {
97+
// ^ call to tc.name
98+
t.Parallel()
99+
fmt.Println(tc.name)
100+
})
101+
}
105102
}
106103
// Error displayed
107104
// Range statement for test TestFunctionRangeNotUsingRangeValueInTDotRun does not use range value in t.Run
108105
```
109106

110-
### t.Parallel() is called in the range method and test case variable tc being used, but is not reinitialised (<a href="https://gist.github.com/kunwardeep/80c2e9f3d3256c894898bae82d9f75d0" target="_blank">More Info</a>)
107+
### `t.Parallel()` is called in the range method and test case variable tc being used, but is not reinitialised (<a href="https://gist.github.com/kunwardeep/80c2e9f3d3256c894898bae82d9f75d0" target="_blank">More Info</a>)
111108
```go
112109
// bad
113110
func TestFunctionRangeNotReInitialisingVariable(t *testing.T) {
114-
t.Parallel()
115-
116-
testCases := []struct {
117-
name string
118-
}{{name: "foo"}}
119-
for _, tc := range testCases {
120-
t.Run(tc.name, func(t *testing.T) {
121-
t.Parallel()
122-
fmt.Println(tc.name)
123-
})
124-
}
111+
t.Parallel()
112+
113+
testCases := []struct {
114+
name string
115+
}{{name: "foo"}}
116+
for _, tc := range testCases {
117+
t.Run(tc.name, func(t *testing.T) {
118+
t.Parallel()
119+
fmt.Println(tc.name)
120+
})
121+
}
125122
}
126123

127124
// good
128125
func TestFunctionRangeNotReInitialisingVariable(t *testing.T) {
129-
t.Parallel()
130-
131-
testCases := []struct {
132-
name string
133-
}{{name: "foo"}}
134-
for _, tc := range testCases {
135-
tc:=tc
136-
// ^ tc variable reinitialised
137-
t.Run(tc.name, func(t *testing.T) {
138-
t.Parallel()
139-
fmt.Println(tc.name)
140-
})
141-
}
126+
t.Parallel()
127+
128+
testCases := []struct {
129+
name string
130+
}{{name: "foo"}}
131+
for _, tc := range testCases {
132+
tc:=tc
133+
// ^ tc variable reinitialised
134+
t.Run(tc.name, func(t *testing.T) {
135+
t.Parallel()
136+
fmt.Println(tc.name)
137+
})
138+
}
142139
}
143140
// Error displayed
144141
// Range statement for test TestFunctionRangeNotReInitialisingVariable does not reinitialise the variable tc

0 commit comments

Comments
 (0)