为什么”go test -v”命令无法看到GOPATH或GOPATH,而”go env”命令可以看到呢?

huangapple go评论84阅读模式
英文:

Why "go test -v" doesn't see the GOPATH or GOPATH but "go env" does?

问题

应用程序在本地运行时正常工作:
$ dev_appserver.py app.yaml

然而,当我尝试运行测试时,环境似乎没有设置。
$ go test -v

skincare.go:6:5: 找不到任何包“appengine”:
	/usr/local/go/src/appengine(来自$GOROOT)
	/Users/bryan/go/src/appengine(来自$GOPATH)
skincare.go:7:5: 找不到任何包“appengine/datastore”:
	/usr/local/go/src/appengine/datastore(来自$GOROOT)
	/Users/bryan/go/src/appengine/datastore(来自$GOPATH)
skincare.go:8:5: 找不到任何包“appengine/user”:
	/usr/local/go/src/appengine/user(来自$GOROOT)
	/Users/bryan/go/src/appengine/user(来自$GOPATH)

$ go env

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/bryan/go/"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"
英文:

The application works fine when I run it locally with:
$ dev_appserver.py app.yaml

However, when I attempt to run tests, the ENV doesn't seem to be set.

$ go test -v

skincare.go:6:5: cannot find package "appengine" in any of:
	/usr/local/go/src/appengine (from $GOROOT)
	/Users/bryan/go/src/appengine (from $GOPATH)
skincare.go:7:5: cannot find package "appengine/datastore" in any of:
	/usr/local/go/src/appengine/datastore (from $GOROOT)
	/Users/bryan/go/src/appengine/datastore (from $GOPATH)
skincare.go:8:5: cannot find package "appengine/user" in any of:
	/usr/local/go/src/appengine/user (from $GOROOT)
	/Users/bryan/go/src/appengine/user (from $GOPATH)

$ go env

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/bryan/go/"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"

答案1

得分: 3

$GOPATH 不应包含路径中的 src 部分。因此,应该将其指向 /Users/bryan/go,而不是 /Users/bryan/go/src/

英文:

$GOPATH should not not contain the src part of the path. So instead of pointing to /Users/bryan/go/src/ it should point to /Users/bryan/go.

答案2

得分: 0

我怀疑你的测试失败是因为你直接使用go test来调用它们,而不是使用App Engine SDK的测试运行器goapp test,后者在运行时会将你链接到appengine包。

英文:

I suspect your tests are failing because you're invoking them directly with go test rather than using the App Engine SDK's test runner, goapp test, which will link you to the appengine package when it runs.

huangapple
  • 本文由 发表于 2017年6月10日 05:14:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/44466785.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定