go/internal/gcimporter: fix tests on darwin

It appears that /var/folders is a symlink to /private/var/folders on
macOS, and further that go/loader uses the original name whereas
cmd/compile uses the dereferenced name. (Judging based on error
messages.)

Change-Id: I3515b223031e3e7a1508acfdbb6dca3009ead398
Reviewed-on: https://go-review.googlesource.com/c/tools/+/292910
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
diff --git a/go/internal/gcimporter/bexport_test.go b/go/internal/gcimporter/bexport_test.go
index 73585a6..7fc5a3e 100644
--- a/go/internal/gcimporter/bexport_test.go
+++ b/go/internal/gcimporter/bexport_test.go
@@ -118,8 +118,15 @@
 
 func fileLine(fset *token.FileSet, obj types.Object) string {
 	posn := fset.Position(obj.Pos())
-	filename := filepath.Clean(strings.ReplaceAll(posn.Filename, "$GOROOT", build.Default.GOROOT))
-	return fmt.Sprintf("%s:%d", filename, posn.Line)
+	filename := strings.ReplaceAll(posn.Filename, "$GOROOT", build.Default.GOROOT)
+	if runtime.GOOS == "darwin" {
+		// cmd/compile and go/loader are inconsistent about which spelling
+		// to use in os/signal/internal/pty's position information.
+		// TODO(mdempsky): Investigate why they're inconsistent, and why
+		// for only that one package.
+		filename = strings.ReplaceAll(filename, "/private/var/folders/", "/var/folders/")
+	}
+	return fmt.Sprintf("%s:%d", filepath.Clean(filename), posn.Line)
 }
 
 // equalObj reports how x and y differ.  They are assumed to belong to