go - 一些如何在 go 程序使用中显示各种测试参数标志

标签 go

我有一个以常规方式构建的小型 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/

相关文章:

google-app-engine - 使用 Go 的 App 脚本 appengine 教程

go - 如何将具有 byte slice 数据类型的结构转换为字节?

go - Hugo 增量构建 .某处是否存在未记录的开关?

go - 如何在 http.Request 中获取 URL

time - 我如何在 Go 语言中格式化时间

go - 从 channel 片段中选择(发送到免费 channel )?

visual-studio - 如何使用 VSCode 在 GOARCH=386 的 64 位 GO 项目上使用 32 位 DLL

json - 如何在 GJSON 中循环 slice

go - 我无法将包从另一个目录导入到 main.go

struct - 嵌入式结构方法可以了解父/子吗?