-
Notifications
You must be signed in to change notification settings - Fork 17.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/go: avoid generating "malformed module path" errors for standard-…
…library paths If the path looks like it belongs in GOROOT/src and isn't there, we should mention that in the error message — instead of the fact that the path is not a valid module path, which the user likely already knows. Fixes #34769 Fixes #35734 Change-Id: I3589336d102e420a5ad3bf246816e29f3cbe6d71 Reviewed-on: https://go-review.googlesource.com/c/go/+/210339 Run-TryBot: Bryan C. Mills <[email protected]> Reviewed-by: Jay Conrod <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
- Loading branch information
Bryan C. Mills
committed
Dec 6, 2019
1 parent
bf86582
commit 1de3131
Showing
5 changed files
with
84 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
env GO111MODULE=on | ||
|
||
# Regression test for https://golang.org/issue/34769. | ||
# Missing standard-library imports should refer to GOROOT rather than | ||
# complaining about a malformed module path. | ||
# This is especially important when GOROOT is set incorrectly, | ||
# since such an error will occur for every package in std. | ||
|
||
# Building a nonexistent std package directly should fail usefully. | ||
|
||
! go build -mod=readonly nonexist | ||
! stderr 'import lookup disabled' | ||
! stderr 'missing dot' | ||
stderr '^can''t load package: package nonexist is not in GOROOT \('$GOROOT'[/\\]src[/\\]nonexist\)$' | ||
|
||
! go build nonexist | ||
! stderr 'import lookup disabled' | ||
! stderr 'missing dot' | ||
stderr '^can''t load package: package nonexist is not in GOROOT \('$GOROOT'[/\\]src[/\\]nonexist\)$' | ||
|
||
# Building a nonexistent std package indirectly should also fail usefully. | ||
|
||
! go build -mod=readonly ./importnonexist | ||
! stderr 'import lookup disabled' | ||
! stderr 'missing dot' | ||
stderr '^importnonexist[/\\]x.go:2:8: package nonexist is not in GOROOT \('$GOROOT'[/\\]src[/\\]nonexist\)$' | ||
|
||
! go build ./importnonexist | ||
! stderr 'import lookup disabled' | ||
! stderr 'missing dot' | ||
stderr '^importnonexist[/\\]x.go:2:8: package nonexist is not in GOROOT \('$GOROOT'[/\\]src[/\\]nonexist\)$' | ||
|
||
# Building an *actual* std package should fail if GOROOT is set to something bogus. | ||
|
||
[!short] go build ./importjson # Prove that it works when GOROOT is valid. | ||
|
||
env GOROOT=$WORK/not-a-valid-goroot | ||
! go build ./importjson | ||
! stderr 'import lookup disabled' | ||
! stderr 'missing dot' | ||
stderr 'importjson[/\\]x.go:2:8: package encoding/json is not in GOROOT \('$WORK'[/\\]not-a-valid-goroot[/\\]src[/\\]encoding[/\\]json\)$' | ||
|
||
-- go.mod -- | ||
module example.com | ||
go 1.14 | ||
-- importnonexist/x.go -- | ||
package importnonexist | ||
import _ "nonexist" | ||
-- importjson/x.go -- | ||
package importjson | ||
import _ "encoding/json" | ||
-- $WORK/not-a-valid-goroot/README -- | ||
This directory is not a valid GOROOT. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters