-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
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
)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/aron/gofoo"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
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"
CXX="clang++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
What did you do?
Create src/pathing/pathing_test.go
with the content:
package pathing
import (
"testing"
)
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
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
FAIL pathing 0.007s
Notice that test failures are always the filename with no pathing. This appears to come from the decorate
function: https://github.com/golang/go/blob/release-branch.go1.8/src/testing/testing.go#L303
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
https://github.com/golang/go/blob/release-branch.go1.8/src/cmd/internal/obj/line.go#L218
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.