2015-02-07 74 views
1

在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 

這甚至可能一起去?如果是這樣,怎麼樣?

回答

2

只需在測試文件上使用build constraint即可。

// +build windows 

甲構建約束作爲空間分隔的選項或評價;每個選項評估爲逗號分隔術語的AND;並且每個術語都是一個字母數字字,或者以!開頭,否定。也就是構建約束:

+0

是的,我擔心我可能必須這麼做......哦。 – joshlf 2015-02-07 21:50:54

1

原來我錯了。它確實有效。問題是我也有一個名爲foo_unix_test.go的文件,顯然Go不支持*_unix.go語法作爲特例。

+0

哪一個作品@joshif? – Matt 2018-03-01 11:17:50

+0

我不記得了,對不起。這是很久以前的事了。試試他們兩個,看看哪一個工作,我猜? – joshlf 2018-03-03 02:43:01

相關問題