我的项目使用 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
目录并重建它。
最佳答案
通过将版本固定到 v1.1.4,您明确告诉 dep
使用不包含您想要的功能的版本(检查 GitHub 上 testify 包的历史 - v1. 1.4 来自去年 9 月,PanicsWithValue
是今年 6 月添加的)。如果您取消固定版本 (version = "*"
),它应该使用包含 PanicsWithValue
的 master@HEAD。
关于go - $GOPATH/src/... 和 vendor/... 版本不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45842740/