简体   繁体   English

如何使用“内部”导入运行 go 核心库测试?

[英]How to run go core library tests with an `internal` import?

I am trying to run the tests in crypto/tls .我正在尝试在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.这是有道理的,因为tls是 package 并且没有像普通 package 那样的本地internal目录。

So my question is how are these test run to get around this restriction?所以我的问题是这些测试如何运行来绕过这个限制?

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 设置为 repo 并使用 package 名称运行测试:
$GOROOT=$PWD GOBIN=$PWD/bin GOMODCACHE=$PWD/pkg/mod GOPATH=/tmp/gotest ./bin/go test crypto/tls 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM