Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kunwardeep committed Nov 12, 2020
1 parent 856c761 commit de1f797
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 72 deletions.
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -29,7 +29,7 @@ require (
github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4
github.com/jingyugao/rowserrcheck v0.0.0-20191204022205-72ab7603b68a
github.com/jirfag/go-printf-func-name v0.0.0-20191110105641-45db9963cdd3
github.com/kunwardeep/paralleltest v0.0.0-20201102045442-db8265575033
github.com/kunwardeep/paralleltest v1.0.1
github.com/kyoh86/exportloopref v0.1.8
github.com/maratori/testpackage v1.0.1
github.com/matoous/godox v0.0.0-20190911065817-5d6d842e92eb // v1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 2 additions & 60 deletions test/linters_test.go
Expand Up @@ -2,7 +2,6 @@ package test

import (
"bufio"
"fmt"
"io/ioutil"
"os"
"os/exec"
Expand Down Expand Up @@ -157,10 +156,7 @@ func testOneSource(t *testing.T, sourcePath string) {

cmd := exec.Command(binName, caseArgs...)
t.Log(caseArgs)
fmt.Println("======================", sourcePath)
if sourcePath == `testdata/paralleltest.go` {
runGoErrchk(cmd, []string{sourcePath}, t)
}
runGoErrchk(cmd, []string{sourcePath}, t)
}
}

Expand Down Expand Up @@ -307,58 +303,4 @@ func TestTparallel(t *testing.T) {

testshared.NewLintRunner(t).RunWithYamlConfig(string(cfg), args...).ExpectNoIssues()
})
}

// func TestParallelTest(t *testing.T) {
// var args = []string{
// "--disable-all", "--print-issued-lines=false", "--print-linter-name=false", "--out-format=line-number", "--enable", "paralleltest",
// }

// t.Run("positive tests, should pass", func(t *testing.T) {
// sourcePath := filepath.Join(testdataDir, "paralleltest", "happy_path_test.go")
// args = append(args, 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()
// })

// t.Run("function is missing call to parallel", func(t *testing.T) {
// sourcePath := filepath.Join(testdataDir, "paralleltest", "func_missing_call_to_Parallel.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(
// "ssss\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",
// )
// // })
// }
}
18 changes: 9 additions & 9 deletions test/testdata/paralleltest.go
Expand Up @@ -57,19 +57,19 @@ func TestFunctionRangeMissingCallToParallel(t *testing.T) {
fmt.Println(tc.name)
}

for _, tc := range testCases { // want "Range statement for test TestFunctionRangeMissingCallToParallel missing the call to method parallel in test Run"
for _, tc := range testCases { // ERROR "Range statement for test TestFunctionRangeMissingCallToParallel missing the call to method parallel in test Run"
t.Run(tc.name, func(t *testing.T) {
fmt.Println(tc.name)
})
}
}

func TestFunctionMissingCallToParallelAndRangeNotUsingRangeValueInTDotRun(t *testing.T) { // want "Function TestFunctionMissingCallToParallelAndRangeNotUsingRangeValueInTDotRun missing the call to method parallel"
func TestFunctionMissingCallToParallelAndRangeNotUsingRangeValueInTDotRun(t *testing.T) { // ERROR "Function TestFunctionMissingCallToParallelAndRangeNotUsingRangeValueInTDotRun missing the call to method parallel"
testCases := []struct {
name string
}{{name: "foo"}}

for _, tc := range testCases { // want "Range statement for test TestFunctionMissingCallToParallelAndRangeNotUsingRangeValueInTDotRun missing the call to method parallel in test Run"
for _, tc := range testCases { // ERROR "Range statement for test TestFunctionMissingCallToParallelAndRangeNotUsingRangeValueInTDotRun missing the call to method parallel in test Run"
t.Run(tc.name, func(t *testing.T) {
fmt.Println(tc.name)
})
Expand All @@ -82,7 +82,7 @@ func TestFunctionRangeNotUsingRangeValueInTDotRun(t *testing.T) {
testCases := []struct {
name string
}{{name: "foo"}}
for _, tc := range testCases { // want "Range statement for test TestFunctionRangeNotUsingRangeValueInTDotRun does not use range value in test Run"
for _, tc := range testCases { // ERROR "Range statement for test TestFunctionRangeNotUsingRangeValueInTDotRun does not use range value in test Run"
t.Run("tc.name", func(t *testing.T) {
t.Parallel()
fmt.Println(tc.name)
Expand All @@ -96,7 +96,7 @@ func TestFunctionRangeNotReInitialisingVariable(t *testing.T) {
testCases := []struct {
name string
}{{name: "foo"}}
for _, tc := range testCases { // want "Range statement for test TestFunctionRangeNotReInitialisingVariable does not reinitialise the variable tc"
for _, tc := range testCases { // ERROR "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)
Expand All @@ -107,18 +107,18 @@ func TestFunctionRangeNotReInitialisingVariable(t *testing.T) {
func TestFunctionTwoTestRunMissingCallToParallel(t *testing.T) {
t.Parallel()

t.Run("1", func(t *testing.T) { // want "Function TestFunctionTwoTestRunMissingCallToParallel has missing the call to method parallel in the test run"
t.Run("1", func(t *testing.T) { // ERROR "Function TestFunctionTwoTestRunMissingCallToParallel has missing the call to method parallel in the test run"
fmt.Println("1")
})
t.Run("2", func(t *testing.T) { // want "Function TestFunctionTwoTestRunMissingCallToParallel has missing the call to method parallel in the test run"
t.Run("2", func(t *testing.T) { // ERROR "Function TestFunctionTwoTestRunMissingCallToParallel has missing the call to method parallel in the test run"
fmt.Println("2")
})
}

func TestFunctionFirstOneTestRunMissingCallToParallel(t *testing.T) {
t.Parallel()

t.Run("1", func(t *testing.T) { // want "Function TestFunctionFirstOneTestRunMissingCallToParallel has missing the call to method parallel in the test run"
t.Run("1", func(t *testing.T) { // ERROR "Function TestFunctionFirstOneTestRunMissingCallToParallel has missing the call to method parallel in the test run"
fmt.Println("1")
})
t.Run("2", func(t *testing.T) {
Expand All @@ -134,7 +134,7 @@ func TestFunctionSecondOneTestRunMissingCallToParallel(t *testing.T) {
t.Parallel()
fmt.Println("1")
})
t.Run("2", func(t *testing.T) { // want "Function TestFunctionSecondOneTestRunMissingCallToParallel has missing the call to method parallel in the test run"
t.Run("2", func(t *testing.T) { // ERROR "Function TestFunctionSecondOneTestRunMissingCallToParallel has missing the call to method parallel in the test run"
fmt.Println("2")
})
}

0 comments on commit de1f797

Please sign in to comment.