...
1# For 1.23+, vendored packages that are missing in modules.txt should result in an error.
2cp incorrect_modules.txt vendor/modules.txt
3# incorrect_modules is missing foo.com/internal/bar/b so the build should fail.
4! go build ./vendor/foo.com/internal/bar/a
5stderr 'cannot find module providing package foo.com/internal/bar/b: import lookup disabled by -mod=vendor'
6stderr 'go: ignoring package foo.com/internal/bar/b which exists in the vendor directory but is missing from vendor/modules.txt. To sync the vendor directory run go mod vendor.'
7
8cp correct_modules.txt vendor/modules.txt
9go build ./vendor/foo.com/internal/bar/a
10
11# For go versions < 1.23, vendored packages that are missing in modules.txt should not result in an error.
12cp 122go.mod go.mod
13
14cp incorrect_modules.txt vendor/modules.txt
15
16# go version < 1.23 and incorrect_modules is missing foo.com/internal/bar/b so the build should not fail
17go build ./vendor/foo.com/internal/bar/a
18
19cp correct_modules.txt vendor/modules.txt
20go build ./vendor/foo.com/internal/bar/a
21
22-- 122go.mod --
23module example.com/x
24go 1.22
25
26require "foo.com/internal/bar" v1.0.0
27
28-- go.mod --
29module example.com/x
30go 1.23
31
32require "foo.com/internal/bar" v1.0.0
33
34-- incorrect_modules.txt --
35# foo.com/internal/bar v1.0.0
36## explicit
37foo.com/internal/bar/a
38
39-- correct_modules.txt --
40# foo.com/internal/bar v1.0.0
41## explicit
42foo.com/internal/bar/a
43foo.com/internal/bar/b
44
45-- vendor/foo.com/internal/bar/a/a.go --
46package a
47import _ "foo.com/internal/bar/b"
48
49-- vendor/foo.com/internal/bar/b/b.go --
50package b
View as plain text