Example:
mkdir $GOPATH/src/gotest/
touch go_test.go
package gotest import "testing" var time string var version string func TestBuild(t *testing.T) { t.Log(time) t.Log(version) }
ReadMe.txt
go test -ldflags="-X 'gotest.time=`date`' -X gotest.version=1.0.1" gotest -v
GO111MODULE=off go test -ldflags="-X 'gotest.time=`date`' -X gotest.version=1.0.1" gotest -v
=== RUN TestBuild
TestBuild: go_test.go:9: 2020年 8月 9日 星期日 18时57分49秒 CST
TestBuild: go_test.go:10: 1.0.1
--- PASS: TestBuild (0.00s)
PASS
ok gotest 0.009s
标签:包中,gotest,golang,test,version,TestBuild,ldflags,go From: https://www.cnblogs.com/gongxianjin/p/17389982.html