Skip to content

Commit 52543a7

Browse files
committed
tests: use proper testenv checks
1 parent 89abef2 commit 52543a7

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

src/cmd/link/internal/ld/elf_test.go

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -187,42 +187,46 @@ func main() {
187187
func TestElfBindNow(t *testing.T) {
188188
t.Parallel()
189189
testenv.MustHaveGoBuild(t)
190-
testenv.MustInternalLink(t, false)
191190

192191
const (
193-
prog = `package main; func main() {}`
194-
prog_C = `package main; import "C"; func main() {}`
192+
prog = `package main; func main() {}`
193+
progC = `package main; import "C"; func main() {}`
195194
)
196195

197196
tests := []struct {
198-
name string
199-
args []string
200-
prog string
201-
wantDf1Now bool
202-
wantDf1Pie bool
203-
wantDfBindNow bool
197+
name string
198+
args []string
199+
prog string
200+
mustHaveCGO bool
201+
mustHaveBuildModePIE bool
202+
wantDf1Now bool
203+
wantDf1Pie bool
204+
wantDfBindNow bool
204205
}{
205206
{name: "default", prog: prog},
206207
{
207-
name: "pie",
208-
args: []string{"-buildmode=pie", "-ldflags", "-linkmode=internal"},
209-
prog: prog,
210-
wantDf1Pie: true,
208+
name: "pie",
209+
args: []string{"-buildmode=pie", "-ldflags", "-linkmode=internal"},
210+
mustHaveBuildModePIE: true,
211+
prog: prog,
212+
wantDf1Pie: true,
211213
},
212214
{
213215
name: "bindnow",
214216
args: []string{"-ldflags", "-bindnow -linkmode=internal"},
215-
prog: prog_C,
217+
prog: progC,
218+
mustHaveCGO: true,
216219
wantDf1Now: true,
217220
wantDfBindNow: true,
218221
},
219222
{
220-
name: "bindnow-pie",
221-
args: []string{"-buildmode=pie", "-ldflags", "-bindnow -linkmode=internal"},
222-
prog: prog,
223-
wantDf1Now: true,
224-
wantDf1Pie: true,
225-
wantDfBindNow: true,
223+
name: "bindnow-pie",
224+
args: []string{"-buildmode=pie", "-ldflags", "-bindnow -linkmode=internal"},
225+
prog: prog,
226+
mustHaveBuildModePIE: true,
227+
wantDf1Now: true,
228+
wantDf1Pie: true,
229+
wantDfBindNow: true,
226230
},
227231
}
228232

@@ -238,6 +242,14 @@ func TestElfBindNow(t *testing.T) {
238242

239243
for _, test := range tests {
240244
t.Run(test.name, func(t *testing.T) {
245+
testenv.MustInternalLink(t, test.mustHaveCGO)
246+
if test.mustHaveCGO {
247+
testenv.MustHaveCGO(t)
248+
}
249+
if test.mustHaveBuildModePIE {
250+
testenv.MustHaveBuildMode(t, "pie")
251+
}
252+
241253
var (
242254
gotDfBindNow, gotDf1Now, gotDf1Pie bool
243255

0 commit comments

Comments
 (0)