Skip to content

testing: test naming guidelines are inconsistent with real-world practice #23322

@koiuo

Description

@koiuo

What version of Go are you using (go version)?

1.9.2

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

linux amd64

What did you do?

$ cat << EOF > foo_test.go
package foo
import "testing"

func Test_Foo(t *testing.T) {
    println("hello")
}
EOF
$ go test -v ./

What did you expect to see?

ok      _/some/dir     0.001s [no tests to run]

What did you see instead?

=== RUN   Test_Foo
hello
--- PASS: Test_Foo (0.00s)
PASS
ok      _/some/dir     0.002s

Official documentation for Go testing package states, that go test

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.

There are tons of open-source go projects that use _ (underscore) in tests names (although all Google projects I've seen so far do follow these naming guidelines), yet _ is not alphanumeric and, according to the documentation, should not work.

I believe either this statement in documentation has to be clarified or go test behavior has to be adjusted to conform to the documentation (unlikely, considering how ubiquitous _ became)

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions