如何使用`internal`导入运行Go核心库测试?

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

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

好的,以下是运行标准/核心库中自定义测试的快速而简单的方法:

  1. 编译核心库和编译器:
GOOS=linux GOARCH=amd64 ./all.bash
  1. 将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:

  1. Compile the core library and compiler:
 GOOS=linux GOARCH=amd64 ./all.bash
  1. 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 

huangapple
  • 本文由 发表于 2021年3月31日 03:34:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/66877394.html
匿名

发表评论

匿名网友

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

确定