@@ -2082,19 +2082,38 @@ func TestBuildmodePIE(t *testing.T) {
20822082 t .Skipf ("skipping test because buildmode=pie is not supported on %s" , platform )
20832083 }
20842084 t .Run ("non-cgo" , func (t * testing.T ) {
2085- testBuildmodePIE (t , false )
2085+ testBuildmodePIE (t , false , true )
20862086 })
20872087 if canCgo {
20882088 switch runtime .GOOS {
20892089 case "darwin" , "freebsd" , "linux" , "windows" :
20902090 t .Run ("cgo" , func (t * testing.T ) {
2091- testBuildmodePIE (t , true )
2091+ testBuildmodePIE (t , true , true )
20922092 })
20932093 }
20942094 }
20952095}
20962096
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 ) {
20982117 tg := testgo (t )
20992118 defer tg .cleanup ()
21002119 tg .parallel ()
@@ -2106,7 +2125,12 @@ func testBuildmodePIE(t *testing.T, useCgo bool) {
21062125 tg .tempFile ("main.go" , fmt .Sprintf (`package main;%s func main() { print("hello") }` , s ))
21072126 src := tg .path ("main.go" )
21082127 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 ... )
21102134
21112135 switch runtime .GOOS {
21122136 case "linux" , "android" , "freebsd" :
0 commit comments