From 43bf63fce1abad1d5fe673e2c869e4d32f62885e Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor <iant@golang.org> Date: Wed, 3 Jan 2018 11:27:26 -0800 Subject: [PATCH] cmd/go, testing: test names don't have to be alphanumeric In func TestXxxx(*testing.T) the Xxxx can be anything that can appear in an identifier, but can't start with a lowercase letter. Clarify the docs. Fixes #23322 Change-Id: I5c297916981f7e3890ee955d12bc7422a75488e2 Reviewed-on: https://go-review.googlesource.com/86001 Reviewed-by: Rob Pike <r@golang.org> --- src/cmd/go/alldocs.go | 14 +++++++------- src/cmd/go/internal/test/test.go | 14 +++++++------- src/testing/testing.go | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go index fd5b01c92a..af5e572b23 100644 --- a/src/cmd/go/alldocs.go +++ b/src/cmd/go/alldocs.go @@ -1707,14 +1707,14 @@ // The 'go test' command expects to find test, benchmark, and example functions // in the "*_test.go" files corresponding to the package under test. // -// A test function is one named TestXXX (where XXX is any alphanumeric string -// not starting with a lower case letter) and should have the signature, +// A test function is one named TestXxx (where Xxx does not start with a +// lower case letter) and should have the signature, // -// func TestXXX(t *testing.T) { ... } +// func TestXxx(t *testing.T) { ... } // -// A benchmark function is one named BenchmarkXXX and should have the signature, +// A benchmark function is one named BenchmarkXxx and should have the signature, // -// func BenchmarkXXX(b *testing.B) { ... } +// func BenchmarkXxx(b *testing.B) { ... } // // An example function is similar to a test function but, instead of using // *testing.T to report success or failure, prints output to os.Stdout. @@ -1725,8 +1725,8 @@ // comment is compiled but not executed. An example with no text after // "Output:" is compiled, executed, and expected to produce no output. // -// Godoc displays the body of ExampleXXX to demonstrate the use -// of the function, constant, or variable XXX. An example of a method M with +// Godoc displays the body of ExampleXxx to demonstrate the use +// of the function, constant, or variable Xxx. An example of a method M with // receiver type T or *T is named ExampleT_M. There may be multiple examples // for a given function, constant, or variable, distinguished by a trailing _xxx, // where xxx is a suffix not beginning with an upper case letter. diff --git a/src/cmd/go/internal/test/test.go b/src/cmd/go/internal/test/test.go index 4ea852c06f..94844b5c68 100644 --- a/src/cmd/go/internal/test/test.go +++ b/src/cmd/go/internal/test/test.go @@ -406,14 +406,14 @@ var HelpTestfunc = &base.Command{ The 'go test' command expects to find test, benchmark, and example functions in the "*_test.go" files corresponding to the package under test. -A test function is one named TestXXX (where XXX is any alphanumeric string -not starting with a lower case letter) and should have the signature, +A test function is one named TestXxx (where Xxx does not start with a +lower case letter) and should have the signature, - func TestXXX(t *testing.T) { ... } + func TestXxx(t *testing.T) { ... } -A benchmark function is one named BenchmarkXXX and should have the signature, +A benchmark function is one named BenchmarkXxx and should have the signature, - func BenchmarkXXX(b *testing.B) { ... } + func BenchmarkXxx(b *testing.B) { ... } An example function is similar to a test function but, instead of using *testing.T to report success or failure, prints output to os.Stdout. @@ -424,8 +424,8 @@ comment, however the order of the lines is ignored. An example with no such comment is compiled but not executed. An example with no text after "Output:" is compiled, executed, and expected to produce no output. -Godoc displays the body of ExampleXXX to demonstrate the use -of the function, constant, or variable XXX. An example of a method M with +Godoc displays the body of ExampleXxx to demonstrate the use +of the function, constant, or variable Xxx. An example of a method M with receiver type T or *T is named ExampleT_M. There may be multiple examples for a given function, constant, or variable, distinguished by a trailing _xxx, where xxx is a suffix not beginning with an upper case letter. diff --git a/src/testing/testing.go b/src/testing/testing.go index 3a4e256b49..f56dbf8f6d 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -6,8 +6,8 @@ // It is intended to be used in concert with the ``go test'' command, which automates // execution of any function of the form // func TestXxx(*testing.T) -// where Xxx can be any alphanumeric string (but the first letter must not be in -// [a-z]) and serves to identify the test routine. +// where Xxx does not start with a lowercase letter. The function name +// serves to identify the test routine. // // Within these functions, use the Error, Fail or related methods to signal failure. // -- 2.30.9