mirror of
https://github.com/scratchfoundation/golangci-lint.git
synced 2025-08-01 17:09:18 -04:00
Add tparallel linter (#1380)
This commit is contained in:
parent
c88841dac4
commit
926e76dcf2
8 changed files with 130 additions and 8 deletions
test
|
@ -252,11 +252,55 @@ func TestExtractRunContextFromComments(t *testing.T) {
|
|||
assert.Equal(t, []string{"-Egoimports"}, rc.args)
|
||||
}
|
||||
|
||||
func TestGolintConsumesXTestFiles(t *testing.T) {
|
||||
dir := getTestDataDir("withxtest")
|
||||
const expIssue = "`if` block ends with a `return` statement, so drop this `else` and outdent its block"
|
||||
func TestTparallel(t *testing.T) {
|
||||
t.Run("should fail on missing top-level Parallel()", func(t *testing.T) {
|
||||
sourcePath := filepath.Join(testdataDir, "tparallel", "missing_toplevel_test.go")
|
||||
args := []string{
|
||||
"--disable-all", "--print-issued-lines=false", "--print-linter-name=false", "--out-format=line-number", "--enable", "tparallel",
|
||||
sourcePath,
|
||||
}
|
||||
rc := extractRunContextFromComments(t, sourcePath)
|
||||
args = append(args, rc.args...)
|
||||
|
||||
r := testshared.NewLintRunner(t)
|
||||
r.Run("--no-config", "--disable-all", "-Egolint", dir).ExpectHasIssue(expIssue)
|
||||
r.Run("--no-config", "--disable-all", "-Egolint", filepath.Join(dir, "p_test.go")).ExpectHasIssue(expIssue)
|
||||
cfg, err := yaml.Marshal(rc.config)
|
||||
assert.NoError(t, err)
|
||||
|
||||
testshared.NewLintRunner(t).RunWithYamlConfig(string(cfg), args...).
|
||||
ExpectHasIssue(
|
||||
"testdata/tparallel/missing_toplevel_test.go:7:6: TestTopLevel should call t.Parallel on the top level as well as its subtests\n",
|
||||
)
|
||||
})
|
||||
|
||||
t.Run("should fail on missing subtest Parallel()", func(t *testing.T) {
|
||||
sourcePath := filepath.Join(testdataDir, "tparallel", "missing_subtest_test.go")
|
||||
args := []string{
|
||||
"--disable-all", "--print-issued-lines=false", "--print-linter-name=false", "--out-format=line-number", "--enable", "tparallel",
|
||||
sourcePath,
|
||||
}
|
||||
rc := extractRunContextFromComments(t, sourcePath)
|
||||
args = append(args, rc.args...)
|
||||
|
||||
cfg, err := yaml.Marshal(rc.config)
|
||||
assert.NoError(t, err)
|
||||
|
||||
testshared.NewLintRunner(t).RunWithYamlConfig(string(cfg), args...).
|
||||
ExpectHasIssue(
|
||||
"testdata/tparallel/missing_subtest_test.go:7:6: TestSubtests's subtests should call t.Parallel\n",
|
||||
)
|
||||
})
|
||||
|
||||
t.Run("should pass on parallel test with no subtests", func(t *testing.T) {
|
||||
sourcePath := filepath.Join(testdataDir, "tparallel", "happy_path_test.go")
|
||||
args := []string{
|
||||
"--disable-all", "--print-issued-lines=false", "--print-linter-name=false", "--out-format=line-number", "--enable", "tparallel",
|
||||
sourcePath,
|
||||
}
|
||||
rc := extractRunContextFromComments(t, sourcePath)
|
||||
args = append(args, rc.args...)
|
||||
|
||||
cfg, err := yaml.Marshal(rc.config)
|
||||
assert.NoError(t, err)
|
||||
|
||||
testshared.NewLintRunner(t).RunWithYamlConfig(string(cfg), args...).ExpectNoIssues()
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue