【问题标题】:How do I run a go test using bazel with the -race option?如何使用带有 -race 选项的 bazel 运行 go 测试?
【发布时间】:2021-07-12 09:05:44
【问题描述】:

在运行中,我可以使用 -race 选项为测试启用竞争检测器,例如

go test -race ./foo/bar

如何在 bazel 中做到这一点?

【问题讨论】:

    标签: go bazel


    【解决方案1】:

    使用--@io_bazel_rules_go//go/config:race (docs) 作为标志进行 bazel 测试。

    --features=race 不再受支持,测试将警告不支持。

    bazel test --@io_bazel_rules_go//go/config:race //src/foo/bar
    

    【讨论】:

    • 哈哈谢谢乔!
    • 您知道如何将其添加到go_test 以便自动包含在其中吗?编辑:nvm 只需将race = "on" 添加到规则中
    【解决方案2】:

    https://github.com/bazelbuild/rules_go/pull/635 开始,您可以使用选项 --features race 运行 bazel 测试,以提供 -race 标志来进行测试。例如

    bazel test --features race //src/foo/bar
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-02
      相关资源
      最近更新 更多