gpt4 book ai didi

去测试 coverprofile 找不到包

转载 作者:IT王子 更新时间:2023-10-29 00:37:30 26 4
gpt4 key购买 nike

当我尝试以下操作时

go test -coverprofile=coverage.out

我得到了这个 coverage.out:

mode: set
_/Users/gert/Desktop/httx/auth.go:10.66,11.54 1 0
_/Users/gert/Desktop/httx/auth.go:11.54,13.89 2 0
_/Users/gert/Desktop/httx/auth.go:17.3,17.11 1 0
_/Users/gert/Desktop/httx/auth.go:13.89,16.4 2 0
_/Users/gert/Desktop/httx/auth.go:22.42,25.2 2 0
...

但是当我这样做的时候

go tool cover -func=coverage.out

coverage.out 的格式似乎不正确?

cover: can't find "auth.go": cannot find package "_/Users/gert/Desktop/httx/" in any of:                                     
/usr/local/Cellar/go/1.7.1/libexec/src/_/Users/gert/Desktop/httx (from $GOROOT)
/Users/gert/go/src/_/Users/gert/Desktop/httx (from $GOPATH)

编辑:请注意 go test -cover 有效。

PASS                                                                                                                         
coverage: 29.7% of statements
ok _/Users/gert/Desktop/httx 0.015s

最佳答案

您的包 /Users/gert/Desktop/httx/ 在您的 $GOPATH 之外,即 /Users/gert/go。将 httx 包移动到 $GOPATH 下的某处,它将正常工作。您可以将其移动到 /Users/gert/go/src/httx 或者类似 /Users/gert/go/src/github.com/your-github-name/httx(假设您使用 GitHub)。

关于去测试 coverprofile 找不到包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39756930/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com