在 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
这甚至可以用 Go 实现吗?如果是,怎么办?
最佳答案
只需使用 build constraint在测试文件上。
// +build windows
A build constraint is evaluated as the OR of space-separated options; each option evaluates as the AND of its comma-separated terms; and each term is an alphanumeric word or, preceded by !, its negation. That is, the build constraint:
关于testing - 为特定的操作系统或架构去测试文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28387378/