Golang:如何跳过特定 Go 版本的测试

huangapple go评论86阅读模式
英文:

Golang: How to skip test for specific go version

问题

我正在处理这个 PR(https://github.com/gin-contrib/i18n/pull/7),它使用了从 go 1.16 开始支持的 embed 包(https://tip.golang.org/doc/go1.16#library-embed)。
由于 gin-contrib/i18n 包支持从 go 1.13 开始的 go 版本,如果 go 版本 < 1.16,我想让它跳过对 embed 的构建和测试。我应该怎么做?我尝试使用构建标签,像这样:

//go:build go1.16

但是这种方法并不像我预期的那样起作用。提前谢谢。

英文:

I'm working on this PR(https://github.com/gin-contrib/i18n/pull/7) and it uses embed package which was supported from go 1.16(https://tip.golang.org/doc/go1.16#library-embed).
As the gin-contrib/i18n package support go version from go 1.13, I want to make it skip build and test for embed if go version < 1.16. What should I do? I tried using build tag like

//go:build go1.16

but this approach doesn't work as I expected. Thanks in advance.

答案1

得分: 2

根据文档中提到的,//go:build约束在Go 1.16中已经包含,还可以使用// +build go1.16

该包解析原始的“// +build”语法和将在Go 1.17中添加的“//go:build”语法。解析器被包含在Go 1.16中,以允许需要处理Go 1.17源代码的工具仍然可以构建在Go 1.16版本上。有关“//go:build”语法的详细信息,请参阅https://golang.org/design/draft-gobuild。

英文:

as mentioned in the docs. //go:build constraint is included in Go 1.16, use also // +build go1.16.

> This package parses both the original “// +build” syntax and the “//go:build” syntax that will be added in Go 1.17. The parser is being included in Go 1.16 to allow tools that need to process Go 1.17 source code to still be built against the Go 1.16 release. See https://golang.org/design/draft-gobuild for details about the “//go:build” syntax.

huangapple
  • 本文由 发表于 2022年3月10日 22:40:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/71425996.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定