aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJay Conrod <jayconrod@google.com>2019-10-16 14:32:03 -0400
committerJay Conrod <jayconrod@google.com>2019-10-16 23:14:14 +0000
commit3b003c3edb013786caeea6c0913b2e21fc4ad66b (patch)
tree90a2475bf686c55c94384caa618d67af35a5cd08 /src
parent02196d36575636a64f868ee0ffe6bb61442e7245 (diff)
downloadgo-3b003c3edb013786caeea6c0913b2e21fc4ad66b.tar.xz
cmd/go/internal/module: fix inverted condition in MatchPathMajor
This was spotted in CL 200767. This change just ensures internal packages match their equivalents in x/mod. Also pulled in test added in CL 201517. Change-Id: I51d23d62697c256548f411930fcb6bccce51bf34 Reviewed-on: https://go-review.googlesource.com/c/go/+/201497 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/go/internal/module/module.go7
-rw-r--r--src/cmd/go/internal/module/module_test.go23
2 files changed, 28 insertions, 2 deletions
diff --git a/src/cmd/go/internal/module/module.go b/src/cmd/go/internal/module/module.go
index 5ef9fdc132..8d24c693f3 100644
--- a/src/cmd/go/internal/module/module.go
+++ b/src/cmd/go/internal/module/module.go
@@ -503,14 +503,17 @@ func splitGopkgIn(path string) (prefix, pathMajor string, ok bool) {
// MatchPathMajor reports whether the semantic version v
// matches the path major version pathMajor.
//
-// MatchPathMajor returns true if and only if CheckPathMajor returns non-nil.
+// MatchPathMajor returns true if and only if CheckPathMajor returns nil.
func MatchPathMajor(v, pathMajor string) bool {
- return CheckPathMajor(v, pathMajor) != nil
+ return CheckPathMajor(v, pathMajor) == nil
}
// CheckPathMajor returns a non-nil error if the semantic version v
// does not match the path major version pathMajor.
func CheckPathMajor(v, pathMajor string) error {
+ // TODO(jayconrod): return errors or panic for invalid inputs. This function
+ // (and others) was covered by integration tests for cmd/go, and surrounding
+ // code protected against invalid inputs like non-canonical versions.
if strings.HasPrefix(pathMajor, ".v") && strings.HasSuffix(pathMajor, "-unstable") {
pathMajor = strings.TrimSuffix(pathMajor, "-unstable")
}
diff --git a/src/cmd/go/internal/module/module_test.go b/src/cmd/go/internal/module/module_test.go
index 8f385afe2e..e61fa9f525 100644
--- a/src/cmd/go/internal/module/module_test.go
+++ b/src/cmd/go/internal/module/module_test.go
@@ -318,3 +318,26 @@ func TestUnescapePath(t *testing.T) {
}
}
}
+
+func TestMatchPathMajor(t *testing.T) {
+ for _, test := range []struct {
+ v, pathMajor string
+ want bool
+ }{
+ {"v0.0.0", "", true},
+ {"v0.0.0", "/v2", false},
+ {"v0.0.0", ".v0", true},
+ {"v0.0.0-20190510104115-cbcb75029529", ".v1", true},
+ {"v1.0.0", "/v2", false},
+ {"v1.0.0", ".v1", true},
+ {"v1.0.0", ".v1-unstable", true},
+ {"v2.0.0+incompatible", "", true},
+ {"v2.0.0", "", false},
+ {"v2.0.0", "/v2", true},
+ {"v2.0.0", ".v2", true},
+ } {
+ if got := MatchPathMajor(test.v, test.pathMajor); got != test.want {
+ t.Errorf("MatchPathMajor(%q, %q) = %v, want %v", test.v, test.pathMajor, got, test.want)
+ }
+ }
+}