go语言rc文件编译 go语言编译可执行文件( 二 )


time go test std -short -timeout=$(expr 120 \* $timeout_scale)s
echo
接下来 run.bash 会在标准库里所有的包上来运行用 testing 包编写的单元测试 。由于 $GOPATH 和 $GOROOT 中有着相同的命名空间,所以不能直接使用 go test … 否则 $GOPATH 中的每个包也会被逐一测试 , 因此创建了一个用于标准库中的包的别名:std 。由于一些测试需要比较长的时间,且会消耗大量内存,因此用 -short 标志对一些测试进行了过滤 。
第七步. runtime 和 cgo 测试
run.bash 接下来的部分会运行平台对 cgo 支持的测试,执行一些性能测试 , 并且编译一些伴随 Go 发行版一起的杂项程序 。随着时间的流逝,这些杂项程序的清单会越来越长,那么它们也就会不可避免的被从编译过程中悄悄剥离出去 。
第八步. go run test
(xcd ../test
unset GOMAXPROCS
time go run run.go
) || exit $?
run.bash 的倒数第二步会调用在 $GOROOT 下的 test 目录里的编译器和运行时的测试 。他们是对于编译器和运行时自身的,较为低级细节的测试 。会执行语言规格测试 , test/bugs 和 test/fixedbugs 子目录保存有那些已经被发现并被修复的问题的独立的测试 。驱动测试的是一个小 Go 程序 $GOROOT/test/run.go,会执行 test 目录里的每个 .go 文件 。一些 .go 文件的首行包含了指导 run.go 对结果作出判断的指令,例如,程序将会失败,或提供一个确定的输出队列 。
第九步. go tool api
echo '# Checking API compatibility.'
go tool api -c $GOROOT/api/go1.txt,$GOROOT/api/go1.1.txt \
-next $GOROOT/api/next.txt -except $GOROOT/api/except.txt
run.bash 的最后一步调用了 api 工具 。
windows 怎么编译 go语言1、解压压缩包到go工作目录 , 如解压到E:\opensource\go\go,解压后的目录结构如下:
E:\opensource\go\go
├─api
├─bin
│├─go.exe
│├─godoc.exe
│└─gofmt.exe
├─doc
├─include
├─lib
├─misc
├─pkg
├─src
└─test
2、增加环境变量GOROOT,取值为上面的go工作目录
3、Path环境变量中添加";%GOROOT%\bin",以便能够直接调用go命令来编译go代码,至此go编译环境就配置好了
注:如果不想手动设置系统环境变量 , 也可下载go启动环境批处理附件,
修改goenv.bat文件中的GOROOT值为上面的go工作目录后直接双击该bat文件,go编译环境变量即设置完成 。
4、测试go编译环境,启动一个cmd窗口,直接输入go,看到下面的提示就是搭建成功了
E:\opensource\go\gogo
Go is a tool for managing Go source code.
Usage:
go command [arguments]
The commands are:
buildcompile packages and dependencies
cleanremove object files
docrun godoc on package sources
envprint Go environment information
fixrun go tool fix on packages
fmtrun gofmt on package sources
getdownload and install packages and dependencies
installcompile and install packages and dependencies
listlist packages
runcompile and run Go program
testtest packages
toolrun specified go tool
versionprint Go version
vetrun go tool vet on packages
Use "go help [command]" for more information about a command.
Additional help topics:
gopathGOPATH environment variable
packagesdescription of package lists
remoteremote import path syntax
testflagdescription of testing flags
testfuncdescription of testing functions
Use "go help [topic]" for more information about that topic.
5、编译helloworld测试程序,go语言包中test目录带有helloworld.go测试程序,源码见"附一 helloworld.go",

推荐阅读