Skip to content

Commit 9946437

Browse files
committed
cmd/go/testdata: add tests for 'go mod init' in v0 and v1 directories
1 parent 5f0c451 commit 9946437

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/cmd/go/testdata/script/mod_init_empty.txt

+23
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ stdout '^example.com$'
88
go list
99
stdout '^example.com$'
1010

11+
# Reset $GOPATH
12+
env GOPATH=$WORK/gopath
13+
14+
# 'go mod init' should not create a go.mod file in v0 or v1 directory.
15+
cd $GOPATH/src/example.com/m/v0
16+
! go mod init
17+
stderr '(?s)^go: cannot determine module path for source directory(.*)example.com/m/v0 \(bad module path inferred from directory in GOPATH: major version suffixes must be in the form of /vN and are only allowed for v2 or later\)(.*)Example usage:(.*)''go mod init example.com/m'' to initialize a v0 or v1 module(.*)''go mod init example.com/m/v2'' to initialize a v2 module(.*)Run ''go help mod init'' for more information.$'
18+
19+
cd $GOPATH/src/example.com/m/v1
20+
! go mod init
21+
stderr '(?s)^go: cannot determine module path for source directory(.*)example.com/m/v1 \(bad module path inferred from directory in GOPATH: major version suffixes must be in the form of /vN and are only allowed for v2 or later\)(.*)Example usage:(.*)''go mod init example.com/m'' to initialize a v0 or v1 module(.*)''go mod init example.com/m/v2'' to initialize a v2 module(.*)Run ''go help mod init'' for more information.$'
22+
23+
cd $GOPATH/src/example.com/m/v2
24+
go mod init
25+
stderr '^go: creating new go.mod: module example.com/m/v2$'
26+
1127
-- go.mod --
1228
module example.com
1329

@@ -19,3 +35,10 @@ func main() {}
1935

2036
-- $WORK/invalid-gopath
2137
This is a text file, not a directory.
38+
39+
-- example.com/m/v0/main.go --
40+
package main
41+
-- example.com/m/v1/main.go --
42+
package main
43+
-- example.com/m/v2/main.go --
44+
package main

0 commit comments

Comments
 (0)