go/analysis/passes/tests: add testcase from vet

vet's "divergent" testdata package exercises various mistakes
in naming Example functions.

vet's "incomplete" testdata package has been deleted because
it is no longer applicable. It was intended to ensure that a
x_test.go file specified on its own would not trigger false
positives without the corresponding x.go files, but the
new Analysis API always analysis complete packages.

Change-Id: I1a40ead340c806b571302fdaa537f481514b0c22
Reviewed-on: https://go-review.googlesource.com/c/143300
Reviewed-by: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
This commit is contained in:
Alan Donovan 2018-10-18 22:20:58 -04:00
parent 6adeb8aab2
commit 327a9b56d0
5 changed files with 40 additions and 70 deletions

View File

@ -0,0 +1,35 @@
// Test of examples with divergent packages.
package buf
func Example() {} // OK because is package-level.
func Example_suffix() {} // OK because refers to suffix annotation.
func Example_BadSuffix() {} // want "Example_BadSuffix has malformed example suffix: BadSuffix"
func ExampleBuf() {} // OK because refers to known top-level type.
func ExampleBuf_Append() {} // OK because refers to known method.
func ExampleBuf_Clear() {} // want "ExampleBuf_Clear refers to unknown field or method: Buf.Clear"
func ExampleBuf_suffix() {} // OK because refers to suffix annotation.
func ExampleBuf_Append_Bad() {} // want "ExampleBuf_Append_Bad has malformed example suffix: Bad"
func ExampleBuf_Append_suffix() {} // OK because refers to known method with valid suffix.
func ExampleDefaultBuf() {} // OK because refers to top-level identifier.
func ExampleBuf_Reset() bool { return true } // want "ExampleBuf_Reset should return nothing"
func ExampleBuf_Len(i int) {} // want "ExampleBuf_Len should be niladic"
// "Puffer" is German for "Buffer".
func ExamplePuffer() {} // want "ExamplePuffer refers to unknown identifier: Puffer"
func ExamplePuffer_Append() {} // want "ExamplePuffer_Append refers to unknown identifier: Puffer"
func ExamplePuffer_suffix() {} // want "ExamplePuffer_suffix refers to unknown identifier: Puffer"

View File

@ -13,6 +13,9 @@ import (
func Test(t *testing.T) { func Test(t *testing.T) {
testdata := analysistest.TestData() testdata := analysistest.TestData()
// Loads "a", "a [a.test]", and "a.test".
analysistest.Run(t, testdata, tests.Analyzer, "a") analysistest.Run(t, testdata, tests.Analyzer,
"a", // loads "a", "a [a.test]", and "a.test"
"divergent",
)
} }

View File

@ -1,35 +0,0 @@
// Test of examples with divergent packages.
package buf_test
func Example() {} // OK because is package-level.
func Example_suffix() {} // OK because refers to suffix annotation.
func Example_BadSuffix() {} // ERROR "Example_BadSuffix has malformed example suffix: BadSuffix"
func ExampleBuf() {} // OK because refers to known top-level type.
func ExampleBuf_Append() {} // OK because refers to known method.
func ExampleBuf_Clear() {} // ERROR "ExampleBuf_Clear refers to unknown field or method: Buf.Clear"
func ExampleBuf_suffix() {} // OK because refers to suffix annotation.
func ExampleBuf_Append_Bad() {} // ERROR "ExampleBuf_Append_Bad has malformed example suffix: Bad"
func ExampleBuf_Append_suffix() {} // OK because refers to known method with valid suffix.
func ExampleDefaultBuf() {} // OK because refers to top-level identifier.
func ExampleBuf_Reset() bool { return true } // ERROR "ExampleBuf_Reset should return nothing"
func ExampleBuf_Len(i int) {} // ERROR "ExampleBuf_Len should be niladic"
// "Puffer" is German for "Buffer".
func ExamplePuffer() {} // ERROR "ExamplePuffer refers to unknown identifier: Puffer"
func ExamplePuffer_Append() {} // ERROR "ExamplePuffer_Append refers to unknown identifier: Puffer"
func ExamplePuffer_suffix() {} // ERROR "ExamplePuffer_suffix refers to unknown identifier: Puffer"

View File

@ -1,33 +0,0 @@
// Test of examples.
package testdata
func Example() {} // OK because is package-level.
func Example_suffix() // OK because refers to suffix annotation.
func Example_BadSuffix() // OK because non-test package was excluded. No false positives wanted.
func ExampleBuf() // OK because non-test package was excluded. No false positives wanted.
func ExampleBuf_Append() {} // OK because non-test package was excluded. No false positives wanted.
func ExampleBuf_Clear() {} // OK because non-test package was excluded. No false positives wanted.
func ExampleBuf_suffix() {} // OK because refers to suffix annotation.
func ExampleBuf_Append_Bad() {} // OK because non-test package was excluded. No false positives wanted.
func ExampleBuf_Append_suffix() {} // OK because refers to known method with valid suffix.
func ExampleBuf_Reset() bool { return true } // ERROR "ExampleBuf_Reset should return nothing"
func ExampleBuf_Len(i int) {} // ERROR "ExampleBuf_Len should be niladic"
// "Puffer" is German for "Buffer".
func ExamplePuffer() // OK because non-test package was excluded. No false positives wanted.
func ExamplePuffer_Append() // OK because non-test package was excluded. No false positives wanted.
func ExamplePuffer_suffix() // OK because non-test package was excluded. No false positives wanted.