mirror of
https://github.com/golang/go
synced 2024-11-06 08:16:11 -07:00
a25a8d567b
In spite of https://blog.golang.org/examples and http://golang.org/pkg/testing/#pkg-examples, a number of internal Go authors have found writing documentation examples to be problematic in the sense that the syntax is error-prone due to loose coupling with identifiers found in the source corpus. This commit introduces a suite of validations for documentation examples: Overall: - Correct suffices, if present - Niladic function argument and return signatures func Example() {} func ExampleF() {} - F exists func ExampleT() {} - T exists func ExampleT_M() {} - T exists - M exists within T Further, if the example is in `package foo_test`, vet attempts to resolve the respective lookups in `package foo`, if `package foo` exists (cf., `package stringutil_test`). Change-Id: Ifa13906363541ebf28325681b749b14b7f8b103d Reviewed-on: https://go-review.googlesource.com/11982 Reviewed-by: Andrew Gerrand <adg@golang.org>
34 lines
1.3 KiB
Go
34 lines
1.3 KiB
Go
// 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.
|