From 5a71a9e3c7736e1e85e614432680a49ab723e492 Mon Sep 17 00:00:00 2001 From: Peter Mescalchin Date: Tue, 7 Jun 2022 14:58:32 +1000 Subject: [PATCH] `README.md` cleanups --- README.md | 163 +++++++++++++++++++++++++++--------------------------- 1 file changed, 80 insertions(+), 83 deletions(-) diff --git a/README.md b/README.md index aff2161..10aee12 100644 --- a/README.md +++ b/README.md @@ -4,141 +4,138 @@ 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. - ## Usage -``` +```sh paralleltest ./... ``` ## Examples -### Missing t.Parallel() in the test method +### Missing `t.Parallel()` in the test method ```go // bad func TestFunctionMissingCallToParallel(t *testing.T) { -} +} // good func TestFunctionMissingCallToParallel(t *testing.T) { - t.Parallel() - // ^ call to t.Parallel() -} + t.Parallel() + // ^ call to t.Parallel() +} // Error displayed // Function TestFunctionMissingCallToParallel missing the call to method parallel ``` -### Missing t.Parallel() in the range method +### Missing `t.Parallel()` in the range method ```go // bad func TestFunctionRangeMissingCallToParallel(t *testing.T) { - t.Parallel() + t.Parallel() - testCases := []struct { - name string - }{{name: "foo"}} + testCases := []struct { + name string + }{{name: "foo"}} - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - fmt.Println(tc.name) - }) - } + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + fmt.Println(tc.name) + }) + } } // good func TestFunctionRangeMissingCallToParallel(t *testing.T) { - t.Parallel() - - testCases := []struct { - name string - }{{name: "foo"}} - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - t.Parallel() - // ^ call to t.Parallel() - fmt.Println(tc.name) - }) - } -} + t.Parallel() + + testCases := []struct { + name string + }{{name: "foo"}} + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + // ^ call to t.Parallel() + fmt.Println(tc.name) + }) + } +} // Error displayed // Range statement for test TestFunctionRangeMissingCallToParallel missing the call to method parallel in t.Run ``` - - -### t.Parallel() is called in the range method but testcase variable not being used +### `t.Parallel()` is called in the range method but testcase variable not being used ```go // bad func TestFunctionRangeNotUsingRangeValueInTDotRun(t *testing.T) { - t.Parallel() - - testCases := []struct { - name string - }{{name: "foo"}} - for _, tc := range testCases { - t.Run("this is a test name", func(t *testing.T) { - // ^ call to tc.name missing - t.Parallel() - fmt.Println(tc.name) - }) - } + t.Parallel() + + testCases := []struct { + name string + }{{name: "foo"}} + for _, tc := range testCases { + t.Run("this is a test name", func(t *testing.T) { + // ^ call to tc.name missing + t.Parallel() + fmt.Println(tc.name) + }) + } } // good func TestFunctionRangeNotUsingRangeValueInTDotRun(t *testing.T) { - t.Parallel() - - testCases := []struct { - name string - }{{name: "foo"}} - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - // ^ call to tc.name - t.Parallel() - fmt.Println(tc.name) - }) - } + t.Parallel() + + testCases := []struct { + name string + }{{name: "foo"}} + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + // ^ call to tc.name + t.Parallel() + fmt.Println(tc.name) + }) + } } // Error displayed // Range statement for test TestFunctionRangeNotUsingRangeValueInTDotRun does not use range value in t.Run ``` -### t.Parallel() is called in the range method and test case variable tc being used, but is not reinitialised (More Info) +### `t.Parallel()` is called in the range method and test case variable tc being used, but is not reinitialised (More Info) ```go // bad func TestFunctionRangeNotReInitialisingVariable(t *testing.T) { - t.Parallel() - - testCases := []struct { - name string - }{{name: "foo"}} - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - t.Parallel() - fmt.Println(tc.name) - }) - } + t.Parallel() + + testCases := []struct { + name string + }{{name: "foo"}} + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + fmt.Println(tc.name) + }) + } } // good func TestFunctionRangeNotReInitialisingVariable(t *testing.T) { - t.Parallel() - - testCases := []struct { - name string - }{{name: "foo"}} - for _, tc := range testCases { - tc:=tc - // ^ tc variable reinitialised - t.Run(tc.name, func(t *testing.T) { - t.Parallel() - fmt.Println(tc.name) - }) - } + t.Parallel() + + testCases := []struct { + name string + }{{name: "foo"}} + for _, tc := range testCases { + tc:=tc + // ^ tc variable reinitialised + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + fmt.Println(tc.name) + }) + } } // Error displayed // Range statement for test TestFunctionRangeNotReInitialisingVariable does not reinitialise the variable tc