-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from turbolent/add-ignore-missing-flag
- Loading branch information
Showing
5 changed files
with
220 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,40 @@ | ||
package paralleltest | ||
|
||
import ( | ||
"flag" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
"golang.org/x/tools/go/analysis/analysistest" | ||
) | ||
|
||
func TestAll(t *testing.T) { | ||
func TestMissing(t *testing.T) { | ||
t.Parallel() | ||
|
||
wd, err := os.Getwd() | ||
if err != nil { | ||
t.Fatalf("Failed to get wd: %s", err) | ||
} | ||
|
||
testdata := filepath.Join(filepath.Dir(wd), "paralleltest", "testdata") | ||
analysistest.Run(t, testdata, NewAnalyzer(), "t") | ||
analysistest.Run(t, testdata, Analyzer, "t") | ||
} | ||
|
||
func TestIgnoreMissing(t *testing.T) { | ||
t.Parallel() | ||
|
||
wd, err := os.Getwd() | ||
if err != nil { | ||
t.Fatalf("Failed to get wd: %s", err) | ||
} | ||
|
||
options := flag.NewFlagSet("", flag.ExitOnError) | ||
options.Bool("i", true, "") | ||
|
||
analyzer := *Analyzer | ||
analyzer.Flags = *options | ||
|
||
testdata := filepath.Join(filepath.Dir(wd), "paralleltest", "testdata") | ||
analysistest.Run(t, testdata, &analyzer, "i") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) {} | ||
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 { | ||
t.Run(tc.name, func(t *testing.T) { | ||
fmt.Println(tc.name) | ||
}) | ||
} | ||
} | ||
|
||
func TestFunctionMissingCallToParallelAndRangeNotUsingRangeValueInTDotRun(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
}{{name: "foo"}} | ||
|
||
for _, tc := range testCases { | ||
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) { | ||
fmt.Println("1") | ||
}) | ||
t.Run("2", func(t *testing.T) { | ||
fmt.Println("2") | ||
}) | ||
} | ||
|
||
func TestFunctionFirstOneTestRunMissingCallToParallel(t *testing.T) { | ||
t.Parallel() | ||
|
||
t.Run("1", func(t *testing.T) { | ||
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) { | ||
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) { | ||
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() | ||
} |