summaryrefslogtreecommitdiffstats
path: root/src/cmd/go/testdata/script/run_issue51125.txt
blob: 8fa4486ca4186d375087edba0b4c2ce6c04eae21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Regression test for https://go.dev/issue/51125:
# Relative import paths (a holdover from GOPATH) were accidentally allowed in module mode.

cd $WORK

# Relative imports should not be allowed with a go.mod file.

! go run driver.go
stderr '^driver.go:3:8: "./mypkg" is relative, but relative import paths are not supported in module mode$'

go list -e -f '{{with .Error}}{{.}}{{end}}' -deps driver.go
stdout '^driver.go:3:8: "./mypkg" is relative, but relative import paths are not supported in module mode$'
! stderr .


# Relative imports should not be allowed in module mode even without a go.mod file.
rm go.mod

! go run driver.go
stderr '^driver.go:3:8: "./mypkg" is relative, but relative import paths are not supported in module mode$'

go list -e -f '{{with .Error}}{{.}}{{end}}' -deps driver.go
stdout '^driver.go:3:8: "./mypkg" is relative, but relative import paths are not supported in module mode$'
! stderr .


# In GOPATH mode, they're still allowed (but only outside of GOPATH/src).
env GO111MODULE=off

[!short] go run driver.go

go list -deps driver.go


-- $WORK/go.mod --
module example

go 1.17
-- $WORK/driver.go --
package main

import "./mypkg"

func main() {
	mypkg.MyFunc()
}
-- $WORK/mypkg/code.go --
package mypkg

import "fmt"

func MyFunc() {
	fmt.Println("Hello, world!")
}