Skip to content

Commit

Permalink
go/packages: fix TestCgoOption to work on Windows
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
matloob committed Dec 23, 2019
1 parent c734170 commit 142b776
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions go/packages/stdlib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 142b776

Please sign in to comment.