1 cp go.mod go.mod.orig
2
3
4 # Both 'go get' and 'go get -d' should fail, without updating go.mod,
5 # if the transitive dependencies of the requested package (by default,
6 # the package in the current directory) cannot be resolved.
7
8 ! go get
9 stderr '^example.com/m imports\n\texample.com/badimport imports\n\texample.net/oops: cannot find module providing package example.net/oops$'
10 cmp go.mod.orig go.mod
11
12 ! go get -d
13 stderr '^example.com/m imports\n\texample.com/badimport imports\n\texample.net/oops: cannot find module providing package example.net/oops$'
14 cmp go.mod.orig go.mod
15
16 cd importsyntax
17
18
19 # If 'go get' fails due to a compile error (such as a syntax error),
20 # it should not update the go.mod file.
21
22 ! go get
23 stderr '^..[/\\]badimport[/\\]syntaxerror[/\\]syntaxerror.go:1:1: expected ''package'', found pack$' # TODO: An import stack would be nice.
24 cmp ../go.mod.orig ../go.mod
25
26
27 # A syntax error in a dependency prevents the compiler from needing that
28 # dependency's imports, so 'go get -d' should not report an error when those
29 # imports cannot be resolved: it has all of the dependencies that the compiler
30 # needs, and the user did not request to run the compiler.
31
32 go get -d
33 cmp ../go.mod.syntax-d ../go.mod
34
35
36 -- go.mod --
37 module example.com/m
38
39 go 1.16
40
41 replace example.com/badimport v0.1.0 => ./badimport
42 -- go.mod.syntax-d --
43 module example.com/m
44
45 go 1.16
46
47 replace example.com/badimport v0.1.0 => ./badimport
48
49 require example.com/badimport v0.1.0
50 -- m.go --
51 package m
52
53 import _ "example.com/badimport"
54 -- importsyntax/importsyntax.go --
55 package importsyntax
56
57 import _ "example.com/badimport/syntaxerror"
58 -- badimport/go.mod --
59 module example.com/badimport
60
61 go 1.16
62 -- badimport/badimport.go --
63 package badimport
64
65 import "example.net/oops"
66 -- badimport/syntaxerror/syntaxerror.go --
67 pack-age syntaxerror // sic
68
69 import "example.net/oops"
70
View as plain text