英文:
How to run go core library tests with an `internal` import?
问题
我正在尝试运行crypto/tls
中的测试。问题是,每次我尝试运行测试时,我都会收到以下错误信息:
common.go:20:2: 不允许使用内部包internal/cpu
这是有道理的,因为tls
是一个包,不像普通包那样有一个本地的internal
目录。
所以我的问题是,如何绕过这个限制来运行这些测试?
英文:
I am trying to run the tests in crypto/tls
. The problem is that every time I try to run tests I get:
common.go:20:2: use of internal package internal/cpu not allowed
This makes sense as tls
is a package and does not have a local internal
directory like a normal package.
So my question is how are these test run to get around this restriction?
答案1
得分: 1
好的,以下是运行标准/核心库中自定义测试的快速而简单的方法:
- 编译核心库和编译器:
GOOS=linux GOARCH=amd64 ./all.bash
- 将GOROOT设置为代码库,并使用包名运行测试:
GOROOT=$PWD GOBIN=$PWD/bin GOMODCACHE=$PWD/pkg/mod GOPATH=/tmp/gotest ./bin/go test crypto/tls
英文:
Ok so here is the Quick and dirty method to run custom tests in the standard/core library:
- Compile the core library and compiler:
GOOS=linux GOARCH=amd64 ./all.bash
- Set the GOROOT to the repo and run the test using package names:
$GOROOT=$PWD GOBIN=$PWD/bin GOMODCACHE=$PWD/pkg/mod GOPATH=/tmp/gotest ./bin/go test crypto/tls
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论