@@ -2082,19 +2082,38 @@ func TestBuildmodePIE(t *testing.T) {
2082
2082
t .Skipf ("skipping test because buildmode=pie is not supported on %s" , platform )
2083
2083
}
2084
2084
t .Run ("non-cgo" , func (t * testing.T ) {
2085
- testBuildmodePIE (t , false )
2085
+ testBuildmodePIE (t , false , true )
2086
2086
})
2087
2087
if canCgo {
2088
2088
switch runtime .GOOS {
2089
2089
case "darwin" , "freebsd" , "linux" , "windows" :
2090
2090
t .Run ("cgo" , func (t * testing.T ) {
2091
- testBuildmodePIE (t , true )
2091
+ testBuildmodePIE (t , true , true )
2092
2092
})
2093
2093
}
2094
2094
}
2095
2095
}
2096
2096
2097
- func testBuildmodePIE (t * testing.T , useCgo bool ) {
2097
+ func TestWindowsDefaultBuildmodIsPIE (t * testing.T ) {
2098
+ if testing .Short () && testenv .Builder () == "" {
2099
+ t .Skipf ("skipping in -short mode on non-builder" )
2100
+ }
2101
+
2102
+ if runtime .GOOS != "windows" {
2103
+ t .Skip ("skipping windows only test" )
2104
+ }
2105
+
2106
+ t .Run ("non-cgo" , func (t * testing.T ) {
2107
+ testBuildmodePIE (t , false , false )
2108
+ })
2109
+ if canCgo {
2110
+ t .Run ("cgo" , func (t * testing.T ) {
2111
+ testBuildmodePIE (t , true , false )
2112
+ })
2113
+ }
2114
+ }
2115
+
2116
+ func testBuildmodePIE (t * testing.T , useCgo , setBuildmodeToPIE bool ) {
2098
2117
tg := testgo (t )
2099
2118
defer tg .cleanup ()
2100
2119
tg .parallel ()
@@ -2106,7 +2125,12 @@ func testBuildmodePIE(t *testing.T, useCgo bool) {
2106
2125
tg .tempFile ("main.go" , fmt .Sprintf (`package main;%s func main() { print("hello") }` , s ))
2107
2126
src := tg .path ("main.go" )
2108
2127
obj := tg .path ("main.exe" )
2109
- tg .run ("build" , "-buildmode=pie" , "-o" , obj , src )
2128
+ args := []string {"build" }
2129
+ if setBuildmodeToPIE {
2130
+ args = append (args , "-buildmode=pie" )
2131
+ }
2132
+ args = append (args , "-o" , obj , src )
2133
+ tg .run (args ... )
2110
2134
2111
2135
switch runtime .GOOS {
2112
2136
case "linux" , "android" , "freebsd" :
0 commit comments