Skip to content

Commit c61ab88

Browse files
authored
Merge pull request #21 from magnetikonline/test-workflow-tweaks
2 parents 705a44e + ac8eaea commit c61ab88

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

-16
This file was deleted.

.github/workflows/test.yml

+25
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

+81-86
Original file line numberDiff line numberDiff line change
@@ -1,146 +1,141 @@
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
## Examples
1714

18-
### Missing t.Parallel() in the test method
15+
### Missing `t.Parallel()` in the test method
1916

2017
```go
2118
// bad
2219
func TestFunctionMissingCallToParallel(t *testing.T) {
23-
}
20+
}
2421

2522
// good
2623
func TestFunctionMissingCallToParallel(t *testing.T) {
27-
t.Parallel()
28-
// ^ call to t.Parallel()
29-
}
24+
t.Parallel()
25+
// ^ call to t.Parallel()
26+
}
3027
// Error displayed
3128
// Function TestFunctionMissingCallToParallel missing the call to method parallel
3229
```
3330

34-
### Missing t.Parallel() in the range method
31+
### Missing `t.Parallel()` in the range method
3532

3633
```go
3734
// bad
3835
func TestFunctionRangeMissingCallToParallel(t *testing.T) {
39-
t.Parallel()
36+
t.Parallel()
4037

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

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

5249
// good
5350
func TestFunctionRangeMissingCallToParallel(t *testing.T) {
54-
t.Parallel()
55-
56-
testCases := []struct {
57-
name string
58-
}{{name: "foo"}}
59-
60-
for _, tc := range testCases {
61-
t.Run(tc.name, func(t *testing.T) {
62-
t.Parallel()
63-
// ^ call to t.Parallel()
64-
fmt.Println(tc.name)
65-
})
66-
}
67-
}
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+
}
6865
// Error displayed
6966
// Range statement for test TestFunctionRangeMissingCallToParallel missing the call to method parallel in t.Run
7067
```
7168

72-
73-
74-
### 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
7570

7671
```go
7772
// bad
7873
func TestFunctionRangeNotUsingRangeValueInTDotRun(t *testing.T) {
79-
t.Parallel()
80-
81-
testCases := []struct {
82-
name string
83-
}{{name: "foo"}}
84-
for _, tc := range testCases {
85-
t.Run("this is a test name", func(t *testing.T) {
86-
// ^ call to tc.name missing
87-
t.Parallel()
88-
fmt.Println(tc.name)
89-
})
90-
}
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+
}
9186
}
9287

9388
// good
9489
func TestFunctionRangeNotUsingRangeValueInTDotRun(t *testing.T) {
95-
t.Parallel()
96-
97-
testCases := []struct {
98-
name string
99-
}{{name: "foo"}}
100-
for _, tc := range testCases {
101-
t.Run(tc.name, func(t *testing.T) {
102-
// ^ call to tc.name
103-
t.Parallel()
104-
fmt.Println(tc.name)
105-
})
106-
}
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+
}
107102
}
108103
// Error displayed
109104
// Range statement for test TestFunctionRangeNotUsingRangeValueInTDotRun does not use range value in t.Run
110105
```
111106

112-
### 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>)
113108
```go
114109
// bad
115110
func TestFunctionRangeNotReInitialisingVariable(t *testing.T) {
116-
t.Parallel()
117-
118-
testCases := []struct {
119-
name string
120-
}{{name: "foo"}}
121-
for _, tc := range testCases {
122-
t.Run(tc.name, func(t *testing.T) {
123-
t.Parallel()
124-
fmt.Println(tc.name)
125-
})
126-
}
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+
}
127122
}
128123

129124
// good
130125
func TestFunctionRangeNotReInitialisingVariable(t *testing.T) {
131-
t.Parallel()
132-
133-
testCases := []struct {
134-
name string
135-
}{{name: "foo"}}
136-
for _, tc := range testCases {
137-
tc:=tc
138-
// ^ tc variable reinitialised
139-
t.Run(tc.name, func(t *testing.T) {
140-
t.Parallel()
141-
fmt.Println(tc.name)
142-
})
143-
}
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+
}
144139
}
145140
// Error displayed
146141
// Range statement for test TestFunctionRangeNotReInitialisingVariable does not reinitialise the variable tc

coverage.out

-78
This file was deleted.

go.mod

+7-1
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)