...
1# Regression test for golang.org/issue/34189 and golang.org/issue/34165:
2# @latest, @upgrade, and @patch should prefer compatible versions over
3# +incompatible ones, even if offered by a proxy.
4
5env GO111MODULE=on
6env GOSUMDB=off
7
8# vcs-test.golang.org/git/prefercompatible.git v2.0.0+incompatible exists,
9# and should be resolved if we ask for it explicitly.
10
11go list -m vcs-test.golang.org/git/prefercompatible.git@v2.0.0+incompatible
12stdout '^vcs-test.golang.org/git/prefercompatible.git v2\.0\.0\+incompatible$'
13
14# prefercompatible v1.5.2 has a go.mod file, so v1.5.2 should be preferred over
15# v2.0.0+incompatible when resolving latest, upgrade, and patch.
16
17go list -m vcs-test.golang.org/git/prefercompatible.git@latest
18stdout '^vcs-test.golang.org/git/prefercompatible.git v1\.'
19
20go list -m vcs-test.golang.org/git/prefercompatible.git@upgrade
21stdout '^vcs-test.golang.org/git/prefercompatible.git v1\.'
22
23! go list -m vcs-test.golang.org/git/prefercompatible.git@patch
24stderr '^go: vcs-test.golang.org/git/prefercompatible.git@patch: can''t query version "patch" of module vcs-test.golang.org/git/prefercompatible.git: no existing version is required$'
25
26
27# If we're fetching directly from version control, ignored +incompatible
28# versions should also be omitted by 'go list'.
29
30# (Note that they may still be included in results from a proxy: in proxy mode,
31# we would need to fetch the whole zipfile for the latest compatible version in
32# order to determine whether it contains a go.mod file, and part of the point of
33# the proxy is to avoid fetching unnecessary data.)
34
35[short] stop
36[!git] stop
37env GOPROXY=direct
38
39go list -versions -m vcs-test.golang.org/git/prefercompatible.git
40stdout '^vcs-test.golang.org/git/prefercompatible.git v1\.5\.1 v1\.5\.2' # and possibly others
41! stdout ' v2\.'
42
43# For this module, v2.1.0 exists and has a go.mod file.
44# 'go list -m vcs-test.golang.org/git/prefercompatible.git@v2.0' will check
45# the latest v2.0 tag, discover that it isn't the right module, and stop there
46# (instead of spending the time to check O(N) previous tags).
47
48! go list -m vcs-test.golang.org/git/prefercompatible.git@v2.0
49stderr '^go: module vcs-test.golang.org/git/prefercompatible.git: no matching versions for query "v2\.0\"'
50
51# (But asking for exactly v2.0.0+incompatible should still succeed.)
52go list -m vcs-test.golang.org/git/prefercompatible.git@v2.0.0+incompatible
53stdout '^vcs-test.golang.org/git/prefercompatible.git v2\.0\.0\+incompatible$'
54
55
56# However, if the latest compatible version does not include a go.mod file,
57# +incompatible versions should still be listed, as they may still reflect the
58# intent of the module author.
59
60go list -versions -m vcs-test.golang.org/git/legacytest.git
61stdout '^vcs-test.golang.org/git/legacytest.git v1\.0\.0 v1\.1\.0-pre v1\.2\.0 v2\.0\.0\+incompatible'
62
63# If we're fetching directly from version control, asking for a commit hash
64# corresponding to a +incompatible version should continue to produce the
65# +incompatible version tagged for that commit, even if it is no longer listed.
66
67go list -m vcs-test.golang.org/git/prefercompatible.git@7a6f627326
68stdout '^vcs-test.golang.org/git/prefercompatible.git v2\.0\.0\+incompatible$'
69
70# Similarly, requesting an untagged commit should continue to produce a +incompatible
71# pseudo-version.
72
73go list -m vcs-test.golang.org/git/legacytest.git@7303f7796364
74stdout '^vcs-test.golang.org/git/legacytest.git v2\.0\.1-0\.20180717164253-7303f7796364\+incompatible$'
75
76-- go.mod --
77module github.com/golang.org/issue/34165
View as plain text