$GOPATH/src/…和vendor/…的版本不同

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

$GOPATH/src/... and vendor/... versions are different

问题

我的项目使用Go 1.8,并且依赖于github.com/stretchr/testify。我使用go get -u github.com/stretchr/testify命令获取了最新版本,并且在$GOPATH/src目录下的版本看起来是正确的。

我在Gopkg.toml文件中添加了最新版本号的约束:

[[constraint]]
  name = "github.com/stretchr/testify"
  version = "1.1.4"

然后我运行了dep ensure -update命令,然后运行了dep status命令来更新vendor目录(dep status的输出结果):

github.com/stretchr/testify  ^1.1.4  v1.1.4  69483b4  69483b4  1   

$GOPATH/src目录下的版本中,文件github.com/stretchr/testify/assert/assertions.go中包含了函数PanicsWithValue

func Panics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool {
    // ...
}

func PanicsWithValue(t TestingT, expected interface{}, f PanicTestFunc, msgAndArgs ...interface{}) bool {
    // ...
}

func NotPanics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool {
    // ...
}

但是在vendor目录下的版本中,这个函数缺失了:

func Panics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool {
    // ...
}

func NotPanics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool {
    // ...
}

我做错了什么?我想在我的测试中使用PanicsWithValue函数。我甚至尝试删除整个vendor目录并重新构建,但问题仍然存在。

英文:

My project, using Go 1.8, has a dependency on github.com/stretchr/testify. I retrieved the latest using go get -u github.com/stretchr/testify and the version in $GOPATH/src appears to be correct.

I added the latest version number as a contraint in Gopkg.toml:

[[constraint]]
  name = "github.com/stretchr/testify"
  version = "1.1.4"

I then ran dep ensure -update and then dep status to update the vendor directory (output of dep status):

github.com/stretchr/testify  ^1.1.4  v1.1.4  69483b4  69483b4  1   

The version in $GOPATH/src contains, in the file github.com/stretchr/testify/assert/assertions.go, the function PanicsWithValue:

func Panics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool {
    // ...
}

func PanicsWithValue(t TestingT, expected interface{}, f PanicTestFunc, msgAndArgs ...interface{}) bool {
    // ...
}

func NotPanics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool {
    // ...
}

but in the version in vendor, that function is missing:

func Panics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool {
    // ...
}

func NotPanics(t TestingT, f PanicTestFunc, msgAndArgs ...interface{}) bool {
    // ...
}

What am I doing wrong? I would like to use the function PanicsWithValue in my testing. I even tried deleting the entire vendor directory and rebuilding it.

答案1

得分: 0

通过将版本固定为v1.1.4,你明确告诉dep使用不包含你想要的功能的版本(在GitHub上检查testify包的历史记录 - v1.1.4是去年9月的版本,PanicsWithValue是在今年6月添加的)。如果你取消固定版本(version = "*"),它应该使用包含PanicsWithValue的master@HEAD版本。

英文:

By pinning the version to v1.1.4, you're specifically telling dep to use a version that does not include the feature you want (check the history of the testify package on GitHub - v1.1.4 is from last September, PanicsWithValue was added this past June). If you unpin the version (version = "*") it should use master@HEAD which includes PanicsWithValue.

huangapple
  • 本文由 发表于 2017年8月23日 22:36:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/45842740.html
匿名

发表评论

匿名网友

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

确定