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

cmd/go: document that "go test" sets the PWD to the package directory #13538

Closed
dsnet opened this issue Dec 8, 2015 · 1 comment
Closed

cmd/go: document that "go test" sets the PWD to the package directory #13538

dsnet opened this issue Dec 8, 2015 · 1 comment

Comments

@dsnet
Copy link
Member

dsnet commented Dec 8, 2015

Using go1.5.1

I have been relying on this behavior for some time and just assumed that it was always true, but when I looked through the documentation for go help test it doesn't mention this fact at all.

Many benchmarks make this assumption when they load test files from a testdata directory that is relative to the package directory.

Because go test sets the PWD, stuff like this works from anywhere:

rawr@carbonite: /tmp $ go test compress/flate -run none -bench .
PASS
BenchmarkDecodeDigitsSpeed1e4-4        10000        194030 ns/op      51.54 MB/s       40301 B/op          7 allocs/op
...

But compiling the test binary does not:

rawr@carbonite: /tmp $ go test -c compress/flate
rawr@carbonite: /tmp $ ./flate.test -test.run none -test.bench .
PASS
BenchmarkDecodeDigitsSpeed1e4-4     --- FAIL: BenchmarkDecodeDigitsSpeed1e4-4
    reader_test.go:45: open ../testdata/e.txt: no such file or directory
...

I think the fact that the compiled version fails is WAI, but this behavior should be documented.

@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Dec 8, 2015
@gopherbot
Copy link

CL https://golang.org/cl/17949 mentions this issue.

@rsc rsc closed this as completed in f9137c5 Dec 17, 2015
@golang golang locked and limited conversation to collaborators Dec 29, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants