Skip to content

Commit e1467c5

Browse files
authored
Merge branch 'main' into add-ignore-missing-flag
2 parents c59622a + c61ab88 commit e1467c5

File tree

84 files changed

+316
-1393
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+316
-1393
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Test
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
test:
11+
name: Test
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout source
15+
uses: actions/checkout@v3
16+
- name: Setup Golang
17+
uses: actions/setup-go@v3
18+
with:
19+
go-version: ~1.17
20+
- name: Get dependencies
21+
run: go get -v -t -d ./...
22+
- name: Build
23+
run: go build -v
24+
- name: Test
25+
run: go test -v -race ./...

README.md

Lines changed: 81 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,148 +1,143 @@
11
# paralleltest
22

3-
4-
[![Build Status](https://github.com/kunwardeep/paralleltest/workflows/CI/badge.svg)](https://github.com/kunwardeep/paralleltest/actions)
5-
3+
[![Test](https://github.com/kunwardeep/paralleltest/actions/workflows/test.yml/badge.svg)](https://github.com/kunwardeep/paralleltest/actions/workflows/test.yml)
64

75
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.
86

9-
107
## Usage
118

12-
```
9+
```sh
1310
paralleltest ./...
1411
```
1512

1613
To ignore missing calls to `t.Parallel` and only report incorrect uses of it, pass the flag `-i`.
1714

1815
## Examples
1916

20-
### Missing t.Parallel() in the test method
17+
### Missing `t.Parallel()` in the test method
2118

2219
```go
2320
// bad
2421
func TestFunctionMissingCallToParallel(t *testing.T) {
25-
}
22+
}
2623

2724
// good
2825
func TestFunctionMissingCallToParallel(t *testing.T) {
29-
t.Parallel()
30-
// ^ call to t.Parallel()
31-
}
26+
t.Parallel()
27+
// ^ call to t.Parallel()
28+
}
3229
// Error displayed
3330
// Function TestFunctionMissingCallToParallel missing the call to method parallel
3431
```
3532

36-
### Missing t.Parallel() in the range method
33+
### Missing `t.Parallel()` in the range method
3734

3835
```go
3936
// bad
4037
func TestFunctionRangeMissingCallToParallel(t *testing.T) {
41-
t.Parallel()
38+
t.Parallel()
4239

43-
testCases := []struct {
44-
name string
45-
}{{name: "foo"}}
40+
testCases := []struct {
41+
name string
42+
}{{name: "foo"}}
4643

47-
for _, tc := range testCases {
48-
t.Run(tc.name, func(t *testing.T) {
49-
fmt.Println(tc.name)
50-
})
51-
}
44+
for _, tc := range testCases {
45+
t.Run(tc.name, func(t *testing.T) {
46+
fmt.Println(tc.name)
47+
})
48+
}
5249
}
5350

5451
// good
5552
func TestFunctionRangeMissingCallToParallel(t *testing.T) {
56-
t.Parallel()
57-
58-
testCases := []struct {
59-
name string
60-
}{{name: "foo"}}
61-
62-
for _, tc := range testCases {
63-
t.Run(tc.name, func(t *testing.T) {
64-
t.Parallel()
65-
// ^ call to t.Parallel()
66-
fmt.Println(tc.name)
67-
})
68-
}
69-
}
53+
t.Parallel()
54+
55+
testCases := []struct {
56+
name string
57+
}{{name: "foo"}}
58+
59+
for _, tc := range testCases {
60+
t.Run(tc.name, func(t *testing.T) {
61+
t.Parallel()
62+
// ^ call to t.Parallel()
63+
fmt.Println(tc.name)
64+
})
65+
}
66+
}
7067
// Error displayed
7168
// Range statement for test TestFunctionRangeMissingCallToParallel missing the call to method parallel in t.Run
7269
```
7370

74-
75-
76-
### t.Parallel() is called in the range method but testcase variable not being used
71+
### `t.Parallel()` is called in the range method but testcase variable not being used
7772

7873
```go
7974
// bad
8075
func TestFunctionRangeNotUsingRangeValueInTDotRun(t *testing.T) {
81-
t.Parallel()
82-
83-
testCases := []struct {
84-
name string
85-
}{{name: "foo"}}
86-
for _, tc := range testCases {
87-
t.Run("this is a test name", func(t *testing.T) {
88-
// ^ call to tc.name missing
89-
t.Parallel()
90-
fmt.Println(tc.name)
91-
})
92-
}
76+
t.Parallel()
77+
78+
testCases := []struct {
79+
name string
80+
}{{name: "foo"}}
81+
for _, tc := range testCases {
82+
t.Run("this is a test name", func(t *testing.T) {
83+
// ^ call to tc.name missing
84+
t.Parallel()
85+
fmt.Println(tc.name)
86+
})
87+
}
9388
}
9489

9590
// good
9691
func TestFunctionRangeNotUsingRangeValueInTDotRun(t *testing.T) {
97-
t.Parallel()
98-
99-
testCases := []struct {
100-
name string
101-
}{{name: "foo"}}
102-
for _, tc := range testCases {
103-
t.Run(tc.name, func(t *testing.T) {
104-
// ^ call to tc.name
105-
t.Parallel()
106-
fmt.Println(tc.name)
107-
})
108-
}
92+
t.Parallel()
93+
94+
testCases := []struct {
95+
name string
96+
}{{name: "foo"}}
97+
for _, tc := range testCases {
98+
t.Run(tc.name, func(t *testing.T) {
99+
// ^ call to tc.name
100+
t.Parallel()
101+
fmt.Println(tc.name)
102+
})
103+
}
109104
}
110105
// Error displayed
111106
// Range statement for test TestFunctionRangeNotUsingRangeValueInTDotRun does not use range value in t.Run
112107
```
113108

114-
### 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>)
109+
### `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>)
115110
```go
116111
// bad
117112
func TestFunctionRangeNotReInitialisingVariable(t *testing.T) {
118-
t.Parallel()
119-
120-
testCases := []struct {
121-
name string
122-
}{{name: "foo"}}
123-
for _, tc := range testCases {
124-
t.Run(tc.name, func(t *testing.T) {
125-
t.Parallel()
126-
fmt.Println(tc.name)
127-
})
128-
}
113+
t.Parallel()
114+
115+
testCases := []struct {
116+
name string
117+
}{{name: "foo"}}
118+
for _, tc := range testCases {
119+
t.Run(tc.name, func(t *testing.T) {
120+
t.Parallel()
121+
fmt.Println(tc.name)
122+
})
123+
}
129124
}
130125

131126
// good
132127
func TestFunctionRangeNotReInitialisingVariable(t *testing.T) {
133-
t.Parallel()
134-
135-
testCases := []struct {
136-
name string
137-
}{{name: "foo"}}
138-
for _, tc := range testCases {
139-
tc:=tc
140-
// ^ tc variable reinitialised
141-
t.Run(tc.name, func(t *testing.T) {
142-
t.Parallel()
143-
fmt.Println(tc.name)
144-
})
145-
}
128+
t.Parallel()
129+
130+
testCases := []struct {
131+
name string
132+
}{{name: "foo"}}
133+
for _, tc := range testCases {
134+
tc:=tc
135+
// ^ tc variable reinitialised
136+
t.Run(tc.name, func(t *testing.T) {
137+
t.Parallel()
138+
fmt.Println(tc.name)
139+
})
140+
}
146141
}
147142
// Error displayed
148143
// Range statement for test TestFunctionRangeNotReInitialisingVariable does not reinitialise the variable tc

coverage.out

Lines changed: 0 additions & 78 deletions
This file was deleted.

go.mod

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
module github.com/kunwardeep/paralleltest
22

3-
go 1.14
3+
go 1.17
44

55
require golang.org/x/tools v0.1.10
6+
7+
require (
8+
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
9+
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654 // indirect
10+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
11+
)

0 commit comments

Comments
 (0)