]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modget: warn about unmatched packages exactly once
authorBryan C. Mills <bcmills@google.com>
Thu, 10 Sep 2020 13:34:15 +0000 (09:34 -0400)
committerBryan C. Mills <bcmills@google.com>
Tue, 15 Sep 2020 18:48:09 +0000 (18:48 +0000)
Due to an inverted condition, we were emitting a "matched no packages"
warning twice in some cases and not at all in others.

For #41315

Change-Id: I472cd2d4f75811c8734852f2bdd7346f4c612816
Reviewed-on: https://go-review.googlesource.com/c/go/+/254819
Trust: Bryan C. Mills <bcmills@google.com>
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
src/cmd/go/internal/modget/get.go
src/cmd/go/testdata/script/mod_get_nopkgs.txt [new file with mode: 0644]

index 829cfe055ada9fe0b25f5c5dc93857c1f0061fcf..1b5cf68840b1e5b70e04a8b56c0f0086e20484f8 100644 (file)
@@ -609,9 +609,12 @@ func runGet(ctx context.Context, cmd *base.Command, args []string) {
                }
                prevBuildList = buildList
        }
-       if !*getD {
-               // Only print warnings after the last iteration,
-               // and only if we aren't going to build.
+       if *getD {
+               // Only print warnings after the last iteration, and only if we aren't going
+               // to build (to avoid doubled warnings).
+               //
+               // Only local patterns in the main module, such as './...', can be unmatched.
+               // (See the mod_get_nopkgs test for more detail.)
                search.WarnUnmatched(matches)
        }
 
diff --git a/src/cmd/go/testdata/script/mod_get_nopkgs.txt b/src/cmd/go/testdata/script/mod_get_nopkgs.txt
new file mode 100644 (file)
index 0000000..078e71a
--- /dev/null
@@ -0,0 +1,40 @@
+cd subdir
+
+# 'go get' on empty patterns that are necessarily local to the module
+# should warn that the patterns are empty, exactly once.
+
+go get ./...
+stderr -count=1 'matched no packages'
+
+go get -d ./...
+stderr -count=1 'matched no packages'
+
+# 'go get' on patterns that could conceivably match nested modules
+# should report a module resolution error.
+
+go get -d example.net/emptysubdir/... # control case
+
+! go get -d example.net/emptysubdir/subdir/...
+! stderr 'matched no packages'
+stderr '^go get example\.net/emptysubdir/subdir/\.\.\.: module example\.net/emptysubdir/subdir: reading http://.*: 404 Not Found\n\tserver response: 404 page not found\n\z'
+
+# It doesn't make sense to 'go get' a path in the standard library,
+# since the standard library necessarily can't have unresolved imports.
+#
+# TODO(#30241): Maybe that won't always be the case?
+#
+# For that case, we emit a "malformed module path" error message,
+# which isn't ideal either.
+
+! go get -d builtin/...  # in GOROOT/src, but contains no packages
+stderr '^go get builtin/...: malformed module path "builtin": missing dot in first path element$'
+
+-- go.mod --
+module example.net/emptysubdir
+
+go 1.16
+-- emptysubdir.go --
+// Package emptysubdir has a subdirectory containing no packages.
+package emptysubdir
+-- subdir/README.txt --
+This module intentionally does not contain any p