转到特定操作系统或体系结构的测试文件



在Go中,文件名具有语义意义。例如:

*_windows.go // Only include in compilations for Windows
*_unix.go    // Only include in compilations for Unix
*_386.go     // Only include in compilations for 386 systems
*_test.go    // Only include when run with `go test`

然而,我似乎无法让以下内容发挥作用:

*_windows_test.go // Only include when running `go test` on windows
*_test_windows.go // Another attempt

围棋有可能做到这一点吗?如果是,如何?

只需对测试文件使用构建约束。

// +build windows

构建约束被评估为空间分隔选项的OR;每个选项计算为逗号分隔项的AND;每个术语都是一个字母数字单词,或者前面加上!,它的否定。也就是说,构建约束:

原来我错了。它确实有效。问题是,我还有一个名为foo_unix_test.go的文件,显然Go不支持*_unix.go语法作为特例。

相关内容

最新更新