Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing: document how to place tests in a _test package #5144

Closed
kisielk opened this issue Mar 28, 2013 · 5 comments
Closed

testing: document how to place tests in a _test package #5144

kisielk opened this issue Mar 28, 2013 · 5 comments
Labels
FrozenDueToAge Suggested Issues that may be good for new contributors looking for work to do.
Milestone

Comments

@kisielk
Copy link
Contributor

kisielk commented Mar 28, 2013

The current testing package documentation states:

"These TestXxx routines should be declared within the package they are
testing."

There's no mention of the commonly used technique of creating a file with 

package foo_test

instead of 

package foo

for blackbox or example purposes.
@davecheney
Copy link
Contributor

Comment 1:

I reckon it's yours for the taking if you feel like it.

Labels changed: added priority-later, go1.1maybe, suggested, removed priority-triage.

@kisielk
Copy link
Contributor Author

kisielk commented Mar 28, 2013

Comment 2:

I'm willing to, but I'm not sure about the specifics of how the mechanism works.
Does the package name need to end in _test? It seems so, since otherwise go build and go
test complain about multiple packages in the directory.
Any other subtleties I should be aware of?

@davecheney
Copy link
Contributor

Comment 3:

> Does the package name need to end in _test? It seems so, since otherwise go build and
go test complain about multiple packages in the directory.
Yes. It's actually codified in cmd/go/test.go +420, and doc.go +343. These fields are
can be inspected by go list, 
    lucky(~) % go list -f '{{ .TestGoFiles }}' bytes
    [export_test.go]
    lucky(~) % go list -f '{{ .XTestGoFiles }}' bytes
    [buffer_test.go bytes_test.go example_test.go reader_test.go]
But you are correct that package $PKG_test is special. 
> Any other subtleties I should be aware of?
Watch out for the duplication test.go has a description of the command which is part of
the go help output, but doc.go has the godoc string, those two need to be kept in sync.

Status changed to Accepted.

@robpike
Copy link
Contributor

robpike commented Mar 29, 2013

Comment 4:

See mkdoc.sh in that directory, plus this comment in doc.go:
// DO NOT EDIT THIS FILE. GENERATED BY mkdoc.sh.
// Edit the documentation in other files and rerun mkdoc.sh to generate this one.

@adg
Copy link
Contributor

adg commented Apr 8, 2013

Comment 5:

This issue was closed by revision 091970c.

Status changed to Fixed.

@kisielk kisielk added fixed Suggested Issues that may be good for new contributors looking for work to do. labels Apr 8, 2013
@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1maybe label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge Suggested Issues that may be good for new contributors looking for work to do.
Projects
None yet
Development

No branches or pull requests

6 participants