Skip to content

Commit e60d0f5

Browse files
committed
go/packages: skip TestLoadImportsC when Go has been built without cgo
This test is unsurprisingly failing on the nocgo builder because the cgo packages don't exist on those builders. Updates golang/go#28040 Change-Id: I633b73bb48e76824645e4e8dd141fb42c9adc19f Reviewed-on: https://go-review.googlesource.com/c/140121 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 59602fd commit e60d0f5

File tree

2 files changed

+60
-46
lines changed

2 files changed

+60
-46
lines changed

go/packages/packages_test.go

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -282,52 +282,6 @@ func TestLoadImportsTestVariants(t *testing.T) {
282282
}
283283
}
284284

285-
func TestLoadImportsC(t *testing.T) {
286-
// This test checks that when a package depends on the
287-
// test variant of "syscall", "unsafe", or "runtime/cgo", that dependency
288-
// is not removed when those packages are added when it imports "C".
289-
//
290-
// For this test to work, the external test of syscall must have a dependency
291-
// on net, and net must import "syscall" and "C".
292-
if runtime.GOOS == "windows" {
293-
t.Skipf("skipping on windows; packages on windows do not satisfy conditions for test.")
294-
}
295-
if runtime.GOOS == "plan9" {
296-
// See https://github.com/golang/go/issues/27100.
297-
t.Skip(`skipping on plan9; for some reason "net [syscall.test]" is not loaded`)
298-
}
299-
300-
cfg := &packages.Config{
301-
Mode: packages.LoadImports,
302-
Tests: true,
303-
}
304-
initial, err := packages.Load(cfg, "syscall", "net")
305-
if err != nil {
306-
t.Fatalf("failed to load imports: %v", err)
307-
}
308-
309-
_, all := importGraph(initial)
310-
311-
for _, test := range []struct {
312-
pattern string
313-
wantImport string // an import to check for
314-
}{
315-
{"net", "syscall:syscall"},
316-
{"net [syscall.test]", "syscall:syscall [syscall.test]"},
317-
{"syscall_test [syscall.test]", "net:net [syscall.test]"},
318-
} {
319-
// Test the import paths.
320-
pkg := all[test.pattern]
321-
if pkg == nil {
322-
t.Errorf("package %q not loaded", test.pattern)
323-
continue
324-
}
325-
if imports := strings.Join(imports(pkg), " "); !strings.Contains(imports, test.wantImport) {
326-
t.Errorf("package %q: got \n%s, \nwant to have %s", test.pattern, imports, test.wantImport)
327-
}
328-
}
329-
}
330-
331285
func TestLoadAbsolutePath(t *testing.T) {
332286
tmp, cleanup := makeTree(t, map[string]string{
333287
"gopatha/src/a/a.go": `package a`,

go/packages/packagescgo_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright 2018 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build cgo
6+
7+
package packages_test
8+
9+
import (
10+
"golang.org/x/tools/go/packages"
11+
"runtime"
12+
"strings"
13+
"testing"
14+
)
15+
16+
func TestLoadImportsC(t *testing.T) {
17+
// This test checks that when a package depends on the
18+
// test variant of "syscall", "unsafe", or "runtime/cgo", that dependency
19+
// is not removed when those packages are added when it imports "C".
20+
//
21+
// For this test to work, the external test of syscall must have a dependency
22+
// on net, and net must import "syscall" and "C".
23+
if runtime.GOOS == "windows" {
24+
t.Skipf("skipping on windows; packages on windows do not satisfy conditions for test.")
25+
}
26+
if runtime.GOOS == "plan9" {
27+
// See https://github.com/golang/go/issues/27100.
28+
t.Skip(`skipping on plan9; for some reason "net [syscall.test]" is not loaded`)
29+
}
30+
31+
cfg := &packages.Config{
32+
Mode: packages.LoadImports,
33+
Tests: true,
34+
}
35+
initial, err := packages.Load(cfg, "syscall", "net")
36+
if err != nil {
37+
t.Fatalf("failed to load imports: %v", err)
38+
}
39+
40+
_, all := importGraph(initial)
41+
42+
for _, test := range []struct {
43+
pattern string
44+
wantImport string // an import to check for
45+
}{
46+
{"net", "syscall:syscall"},
47+
{"net [syscall.test]", "syscall:syscall [syscall.test]"},
48+
{"syscall_test [syscall.test]", "net:net [syscall.test]"},
49+
} {
50+
// Test the import paths.
51+
pkg := all[test.pattern]
52+
if pkg == nil {
53+
t.Errorf("package %q not loaded", test.pattern)
54+
continue
55+
}
56+
if imports := strings.Join(imports(pkg), " "); !strings.Contains(imports, test.wantImport) {
57+
t.Errorf("package %q: got \n%s, \nwant to have %s", test.pattern, imports, test.wantImport)
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)