From de1f797c8cbf482ddfa7f117750930ae45a129a0 Mon Sep 17 00:00:00 2001 From: kunwardeep Date: Thu, 12 Nov 2020 23:21:51 +1100 Subject: [PATCH] added tests --- go.mod | 2 +- go.sum | 4 +-- test/linters_test.go | 62 ++--------------------------------- test/testdata/paralleltest.go | 18 +++++----- 4 files changed, 14 insertions(+), 72 deletions(-) diff --git a/go.mod b/go.mod index 9993bf399719..b6ed68ae90cd 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index fb1e40602537..e9dc62d84f97 100644 --- a/go.sum +++ b/go.sum @@ -231,8 +231,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/kunwardeep/paralleltest v0.0.0-20201102045442-db8265575033 h1:Dc5N6s5u4oM1KQOrdztFy4t7qYTMmI3pju0RK3ZE4ks= -github.com/kunwardeep/paralleltest v0.0.0-20201102045442-db8265575033/go.mod h1:cPK5Qwrb6nc97Xzq4K4fc1QvCtyV+xQo9wqOtx469bQ= +github.com/kunwardeep/paralleltest v1.0.1 h1:TBVkR3XY7BQh4/k16VImTYWm5quSKNjlqA+WRXV0Q0I= +github.com/kunwardeep/paralleltest v1.0.1/go.mod h1:cPK5Qwrb6nc97Xzq4K4fc1QvCtyV+xQo9wqOtx469bQ= github.com/kyoh86/exportloopref v0.1.7 h1:u+iHuTbkbTS2D/JP7fCuZDo/t3rBVGo3Hf58Rc+lQVY= github.com/kyoh86/exportloopref v0.1.7/go.mod h1:h1rDl2Kdj97+Kwh4gdz3ujE7XHmH51Q0lUiZ1z4NLj8= github.com/kyoh86/exportloopref v0.1.8 h1:5Ry/at+eFdkX9Vsdw3qU4YkvGtzuVfzT4X7S77LoN/M= diff --git a/test/linters_test.go b/test/linters_test.go index 1b5270f458db..a0583a275b4a 100644 --- a/test/linters_test.go +++ b/test/linters_test.go @@ -2,7 +2,6 @@ package test import ( "bufio" - "fmt" "io/ioutil" "os" "os/exec" @@ -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) } } @@ -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", -// ) -// // }) -// } +} \ No newline at end of file diff --git a/test/testdata/paralleltest.go b/test/testdata/paralleltest.go index 68d78c7b7f00..0b8c15e0bece 100644 --- a/test/testdata/paralleltest.go +++ b/test/testdata/paralleltest.go @@ -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) }) @@ -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) @@ -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) @@ -107,10 +107,10 @@ 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") }) } @@ -118,7 +118,7 @@ func TestFunctionTwoTestRunMissingCallToParallel(t *testing.T) { 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) { @@ -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") }) }