1
0
mirror of https://github.com/golang/go synced 2024-11-18 13:04:46 -07:00

go/packages: fix TestCgoOption to work on Windows

The cgoLookupHost function isn't defined on Windows in the net package in the
standard library, but the addrinfoErrno type is (and is also defined on Unix).
Look for that instead.

Fixes golang/go#35839

Change-Id: I5a3b18d51209549002add1397b8f46de9ef2ee5a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/212478
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
This commit is contained in:
Michael Matloob 2019-12-23 11:31:25 -05:00
parent c7341709c6
commit 142b776bb0

View File

@ -96,10 +96,10 @@ func TestCgoOption(t *testing.T) {
// The test also loads the actual file to verify that the
// object is indeed defined at that location.
for _, test := range []struct {
pkg, name, genericFile string
pkg, declKeyword, name, genericFile string
}{
{"net", "cgoLookupHost", "cgo_stub.go"},
{"os/user", "current", "lookup_stubs.go"},
{"net", "type", "addrinfoErrno", "cgo_stub.go"},
{"os/user", "func", "current", "lookup_stubs.go"},
} {
cfg := &packages.Config{Mode: packages.LoadSyntax}
pkgs, err := packages.Load(cfg, test.pkg)
@ -134,7 +134,7 @@ func TestCgoOption(t *testing.T) {
}
line := string(bytes.Split(b, []byte("\n"))[posn.Line-1])
// Don't assume posn.Column is accurate.
if !strings.Contains(line, "func "+test.name) {
if !strings.Contains(line, test.declKeyword+" "+test.name) {
t.Errorf("%s: %s not declared here (looking at %q)", posn, obj, line)
}
}