我有一个以常规方式构建的小型 go 命令行实用程序:
go build
我使用 flag
包来添加命令行标志。一切都进行得很顺利,直到我开始出现很多测试标志。现在,当我使用 flag.Usage
打印用法时,我看到了很多额外的标志:
-test.bench string
regular expression to select benchmarks to run
-test.benchmem
print memory allocations for benchmarks
-test.benchtime duration
approximate run time for each benchmark (default 1s)
-test.blockprofile string
write a goroutine blocking profile to the named file after execution
-test.blockprofilerate int
if >= 0, calls runtime.SetBlockProfileRate() (default 1)
还有很多。
我正在使用主标志集并使用 flag.IntVar
等添加标志。
我无法弄清楚我做了什么或如何启用它。我的其他程序都没有在默认使用消息中包含这些测试标志。我感谢任何指示。
最佳答案
testing
包的 init()
使用 flags 包将命令行参数添加到您的应用。
您可能从一些非测试代码中引用了testing
。
关于go - 一些如何在 go 程序使用中显示各种测试参数标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37240065/