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: test errors do not include full path name #21119

aronatkins opened this issue Jul 21, 2017 · 1 comment

testing: test errors do not include full path name #21119

aronatkins opened this issue Jul 21, 2017 · 1 comment


Copy link

@aronatkins aronatkins commented Jul 21, 2017

Please answer these questions before submitting your issue. Thanks!

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

go version go1.8.3 darwin/amd64

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

GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/ts/s940qvdj5vj1czr9qh07fvtw0000gn/T/go-build353906001=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Create src/pathing/pathing_test.go with the content:

package pathing

import (

func Name() string {
	return "pathing"

func TestName(t *testing.T) {
	//var name string
	if name = Name(); name != "Pathing" {
		t.Error("unexpected name")

What did you expect to see?

When there is a compilation error (name is not defined):

$ go test pathing
# pathing
src/pathing/pathing_test.go:13: undefined: name
FAIL	pathing [build failed]

When there is a test failure (uncomment the name declaration):

go test pathing
--- FAIL: TestName (0.00s)
	src/pathing/pathing_test.go:14: unexpected name
FAIL	pathing	0.007s

What did you see instead?

When there is a test failure:

go test pathing
--- FAIL: TestName (0.00s)
	pathing_test.go:14: unexpected name
FAIL	pathing	0.007s

Notice that test failures are always the filename with no pathing. This appears to come from the decorate function:

Test-time build failures contain more context when run outside the package directory. They are always an accurate relative path to the file-under-test. This appears to come from LineHist.LineString

Here is an example build failure when run from some other package:

$ go test pathing
# pathing
../pathing/pathing_test.go:13: undefined: name
FAIL	pathing [build failed]

The way go test failures are reported makes it difficult for tooling that processes compilation/test output (emacs electric compilation buffers) to locate the reported file. The errors that come from the build phase are relative paths; the ones coming from test are filenames-only.

Test failures should include path to the file-under-test.

@ianlancetaylor ianlancetaylor changed the title test failures and compile failures use different file:lineno pathing testing: test errors do not include full path name Jul 22, 2017
@ianlancetaylor ianlancetaylor added this to the Go1.10 milestone Jul 22, 2017
Copy link

@rsc rsc commented Nov 29, 2017

I think that ship has sailed. I don't see how to do that without breaking lots of people. Also, the reason the compiler errors can do that is that the go command arranges to get the entire path and then rewrites the printed absolute paths to be relative to the current directory.

Unlike the compiler, test binaries are frequently run separate from the go command, so this trick does not work. Test binaries are also copied to other machines and so on. Users also expect the current output, because that's what has been there for a long time. For all these reasons I think we can't change this. Sorry.

@rsc rsc closed this Nov 29, 2017
@golang golang locked and limited conversation to collaborators Nov 29, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants