Set GO111MODULE=off explicitly in tests specific to GOPATH mode.
Added a go.mod file to other tests that assumed GOPATH mode.
Fixed an issue in the build metadata file generated in
modload/build.go, which did not end with a newline. This broke the
build_dash_x test, which expects to be able to run the script printed
by 'go build -x' to produce the same result. The script is broken if
the build metadata file doesn't end with a newline.
Change-Id: I59f2a492a9f5a66f6c4aa702f429909d5c5e815d
Reviewed-on: https://go-review.googlesource.com/c/go/+/255051
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Trust: Jay Conrod <jayconrod@google.com>
import _ "unsafe"
//go:linkname __debug_modinfo__ runtime.modinfo
var __debug_modinfo__ = %q
- `, string(infoStart)+info+string(infoEnd)))
+`, string(infoStart)+info+string(infoEnd)))
} else {
return []byte(fmt.Sprintf(`package main
import _ "unsafe"
//go:linkname __set_debug_modinfo__ runtime.setmodinfo
func __set_debug_modinfo__(string)
func init() { __set_debug_modinfo__(%q) }
- `, string(infoStart)+info+string(infoEnd)))
+`, string(infoStart)+info+string(infoEnd)))
}
}
[short] skip
# 386
-cd $GOPATH/src/mycmd
env GOOS=linux
env GOARCH=386
env GO386=387
stale mycmd
# arm
-cd $GOPATH/src/mycmd
env GOOS=linux
env GOARCH=arm
env GOARM=5
stale mycmd
--- mycmd/x.go --
+-- go.mod --
+module mycmd
+
+go 1.16
+-- x.go --
package main
-func main() {}
\ No newline at end of file
+func main() {}
go doc fmt
stdout Printf
-go fmt .
-
! go tool compile -h
stderr usage:
go mod verify
+
+# Commands that load but don't build packages should work.
+go fmt .
+
+go doc .
+
-- main.go --
package main
[gccgo] skip 'gccgo does not support -ldflags -X'
+env GO111MODULE=off
go build run_go.go
# Apply identity function to GOPATH
cmp $WORK/exe1$GOEXE $WORK/exe2$GOEXE
--- cgotest/m.go --
+-- go.mod --
+module cgotest
+
+go 1.16
+-- m.go --
package cgotest
import "C"
-- header.txt --
set -e
-- hello.txt --
-hello
\ No newline at end of file
+hello
-# go build with -o and -buildmode=exe should on a non-main package should throw an error
+# go build with -o and -buildmode=exe should report an error on a non-main package.
-! go build -buildmode=exe -o out$GOEXE not_main
+! go build -buildmode=exe -o out$GOEXE ./not_main
stderr '-buildmode=exe requires exactly one main package'
! exists out$GOEXE
-! go build -buildmode=exe -o out$GOEXE main_one main_two
+! go build -buildmode=exe -o out$GOEXE ./main_one ./main_two
stderr '-buildmode=exe requires exactly one main package'
! exists out$GOEXE
+-- go.mod --
+module m
+
+go 1.16
-- not_main/not_main.go --
package not_main
-- main_two/main_two.go --
package main
-func main() {}
\ No newline at end of file
+func main() {}
# -I arguments to compiler could end up not in GOPATH order,
# leading to unexpected import resolution in the compiler.
+env GO111MODULE=off
env GOPATH=$WORK/p1${:}$WORK/p2
mkdir $WORK/p1/src/foo $WORK/p2/src/baz
mkdir $WORK/p2/pkg/${GOOS}_${GOARCH} $WORK/p1/src/bar
-- bar.go --
package bar
import _ "baz"
-import _ "foo"
\ No newline at end of file
+import _ "foo"
-# TODO: add a go.mod file and test with GO111MODULE explicitly on and off.
-# We only report the 'expects import' error when modules are disabled.
-# Do we report comment parse errors or conflicts in module mode? We shouldn't.
+# Test in GOPATH mode first.
+env GO111MODULE=off
+cd m
# Import comment matches
go build -n works.go
! go build -n conflict.go
stderr 'found import comments'
--- bad.go --
+
+# Test in module mode.
+# We ignore import comments, so these commands should succeed.
+env GO111MODULE=on
+
+# Import comment matches
+go build -n works.go
+
+# Import comment mismatch
+go build -n wrongplace.go
+
+# Import comment syntax error
+go build -n bad.go
+
+# Import comment conflict
+go build -n conflict.go
+
+-- m/go.mod --
+module m
+
+go 1.16
+-- m/bad.go --
package p
-import "bad"
--- conflict.go --
+import "m/bad"
+-- m/conflict.go --
package p
-import "conflict"
--- works.go --
+import "m/conflict"
+-- m/works.go --
package p
-import _ "works/x"
--- wrongplace.go --
+import _ "m/works/x"
+-- m/wrongplace.go --
package p
-import "wrongplace"
--- bad/bad.go --
+import "m/wrongplace"
+-- m/bad/bad.go --
package bad // import
--- conflict/a.go --
+-- m/conflict/a.go --
package conflict // import "a"
--- conflict/b.go --
+-- m/conflict/b.go --
package conflict /* import "b" */
--- works/x/x.go --
-package x // import "works/x"
--- works/x/x1.go --
+-- m/works/x/x.go --
+package x // import "m/works/x"
+-- m/works/x/x1.go --
package x // important! not an import comment
--- wrongplace/x.go --
+-- m/wrongplace/x.go --
package x // import "my/x"
+# mod_import_cycle covers this error in module mode.
+env GO111MODULE=off
+
! go build selfimport
stderr -count=1 'import cycle not allowed'
# Test internal package errors are handled
-go list ./testinternal3
+cd testinternal3
+go list .
stdout 'testinternal3'
# Test internal cache
-env GOPATH=$WORK/gopath/src/testinternal4
-! go build p
+cd ../testinternal4
+! go build testinternal4/p
stderr 'internal'
# Test internal packages outside GOROOT are respected
-! go build -v ./testinternal2
-stderr 'testinternal2(\/|\\)p\.go\:3\:8\: use of internal package .*internal/w not allowed'
+cd ../testinternal2
+! go build -v .
+stderr 'p\.go:3:8: use of internal package .*internal/w not allowed'
[gccgo] skip # gccgo does not have GOROOT
-! go build -v ./testinternal
-stderr 'testinternal(\/|\\)p\.go\:3\:8\: use of internal package net/http/internal not allowed'
+cd ../testinternal
+! go build -v .
+stderr 'p\.go:3:8: use of internal package net/http/internal not allowed'
+-- testinternal/go.mod --
+module testinternal
+
+go 1.16
-- testinternal/p.go --
package p
import _ "net/http/internal"
+-- testinternal2/go.mod --
+module testinternal2
+
+go 1.16
-- testinternal2/p.go --
package p
import _ "./x/y/z/internal/w"
-- testinternal2/x/y/z/internal/w/w.go --
package w
+-- testinternal3/go.mod --
+module testinternal3
+
+go 1.16
-- testinternal3/t.go --
package t
import _ "internal/does-not-exist"
--- testinternal4/src/p/p.go --
+-- testinternal4/go.mod --
+module testinternal4
+
+go 1.16
+-- testinternal4/p/p.go --
package p
import (
- _ "q/internal/x"
- _ "q/j"
+ _ "testinternal4/q/internal/x"
+ _ "testinternal4/q/j"
)
--- testinternal4/src/q/internal/x/x.go --
+-- testinternal4/q/internal/x/x.go --
package x
--- testinternal4/src/q/j/j.go --
+-- testinternal4/q/j/j.go --
package j
-import _ "q/internal/x"
+import _ "testinternal4/q/internal/x"
# Install some commands to compare mtimes
env GOBIN=$WORK/tmp/bin
-go install now mtime before
+go install m/now m/mtime m/before
# Initial builds
go test -c -test.bench=XXX errors
cp stdout errors2_mod_time.txt
exec $GOBIN/before start_time.txt errors2_mod_time.txt
+-- go.mod --
+module m
+
+go 1.16
-- now/now.go --
// Writes time.Now() to a file
package main
fmt.Fprintf(os.Stderr, "time in %v (%v) is not before time in %v (%v)", os.Args[1], t1, os.Args[2], t2)
os.Exit(1)
}
-}
\ No newline at end of file
+}
exec ./linkx$GOEXE
stderr '^linkXworked$'
--- my.pkg/main/main.go --
+-- go.mod --
+module my.pkg
+
+go 1.16
+-- main/main.go --
package main
import "my.pkg"
func main() {
println(pkg.Text)
}
--- my.pkg/pkg.go --
+-- pkg.go --
package pkg
var Text = "unset"
go build -n
! stderr '[/\\]\$WORK'
+-- go.mod --
+module m
+
+go 1.16
-- main.go --
package main
! go build ./exclude/empty
stderr 'no Go files in '
+-- go.mod --
+module m
+
+go 1.16
-- empty/test/test_test.go --
package p
-- empty/testxtest/test_test.go --
[windows] env NONEXE=''
env GOBIN=$WORK/tmp/bin
-go install isarchive &
+go install m/isarchive &
go build x.go
exists -exec x$GOEXE
! go build -o whatever cmd/gofmt sync/atomic
stderr 'multiple packages'
+-- go.mod --
+module m
+
+go 1.16
-- x.go --
package main
fmt.Fprintf(os.Stderr, "file %s exists but is not an archive\n", os.Args[1])
os.Exit(1)
}
-}
\ No newline at end of file
+}
# Tests issue #18778
+[short] skip
cd pkgs
+
+env GO111MODULE=off
go build ./...
! stdout .
go test ./...
stdout 'pkgs$'
stdout 'pkgs/a'
+-- pkgs/go.mod --
+module pkgs
+
+go 1.16
-- pkgs/a.go --
package x
-- pkgs/a_test.go --
import "testing"
func TestA(t *testing.T) {
-}
\ No newline at end of file
+}
[!linux] [!darwin] skip
[!cgo] skip
-go build -n testdep/p2
-! go build -buildmode=plugin testdep/p2
+go build -n testdep
+! go build -buildmode=plugin testdep
stderr '-buildmode=plugin requires exactly one main package'
--- testdep/p1/p1.go --
-package p1
--- testdep/p1/p1_test.go --
-package p1
-
-import _ "testdep/p2"
--- testdep/p2/p2.go --
-package p2
+-- go.mod --
+module testdep
+go 1.16
+-- testdep.go --
+package p
# Named explicitly, test-only packages should be reported as
# unbuildable/uninstallable, even if there is a wildcard also matching.
-! go build testonly testonly...
+! go build m/testonly m/testonly...
stderr 'no non-test Go files in'
! go install ./testonly
stderr 'no non-test Go files in'
# Named through a wildcard, the test-only packages should be silently ignored.
-go build testonly...
+go build m/testonly...
go install ./testonly...
+-- go.mod --
+module m
+
+go 1.16
-- testonly/t_test.go --
package testonly
-- testonly2/t.go --
# Build
+env GO111MODULE=off
go build vend/x
! stdout .
! stderr .
! go build cgoasm
stderr 'package using cgo has Go assembly file'
--- cgoasm/p.go --
+-- go.mod --
+module cgoasm
+
+go 1.16
+-- p.go --
package p
/*
import "C"
func F() {}
--- cgoasm/p.s --
+-- p.s --
TEXT asm(SB),$0
RET
[!cgo] skip
[short] skip
-mkdir x
-cp x.go.txt x/x.go
+cp x.go.txt x.go
# Only allow //go:cgo_ldflag .* in cgo-generated code
-[gc] cp x_gc.go.txt x/x.go
+[gc] cp x_gc.go.txt x.go
[gc] ! go build x
[gc] stderr '//go:cgo_ldflag .* only allowed in cgo-generated code'
# Ignore _* files
-rm x/x.go
-! go build x
+rm x.go
+! go build .
stderr 'no Go files'
-cp cgo_yy.go.txt x/_cgo_yy.go
-! go build x
+cp cgo_yy.go.txt _cgo_yy.go
+! go build .
stderr 'no Go files' #_* files are ignored...
-[gc] ! go build x/_cgo_yy.go # ... but if forced, the comment is rejected
+[gc] ! go build _cgo_yy.go # ... but if forced, the comment is rejected
# Actually, today there is a separate issue that _ files named
# on the command line are ignored. Once that is fixed,
# we want to see the cgo_ldflag error.
[gc] stderr '//go:cgo_ldflag only allowed in cgo-generated code|no Go files'
-rm x/_cgo_yy.go
+rm _cgo_yy.go
# Reject #cgo CFLAGS: -fplugin=foo.so
-cp x.go.txt x/x.go
-cp y_fplugin.go.txt x/y.go
+cp x.go.txt x.go
+cp y_fplugin.go.txt y.go
! go build x
stderr 'invalid flag in #cgo CFLAGS: -fplugin=foo.so'
# Reject #cgo CFLAGS: -lbar -fplugin=foo.so
-cp y_lbar_fplugin.go.txt x/y.go
+cp y_lbar_fplugin.go.txt y.go
! go build x
stderr 'invalid flag in #cgo CFLAGS: -fplugin=foo.so'
# Reject #cgo pkg-config: -foo
-cp y_pkgconfig_dash_foo.txt x/y.go
+cp y_pkgconfig_dash_foo.txt y.go
! go build x
stderr 'invalid pkg-config package name: -foo'
# Reject #cgo pkg-config: @foo
-cp y_pkgconfig_at_foo.txt x/y.go
+cp y_pkgconfig_at_foo.txt y.go
! go build x
stderr 'invalid pkg-config package name: @foo'
# Reject #cgo CFLAGS: @foo
-cp y_cflags_at_foo.txt x/y.go
+cp y_cflags_at_foo.txt y.go
! go build x
stderr 'invalid flag in #cgo CFLAGS: @foo'
# Reject #cgo CFLAGS: -D
-cp y_cflags_dash_d.txt x/y.go
+cp y_cflags_dash_d.txt y.go
! go build x
stderr 'invalid flag in #cgo CFLAGS: -D without argument'
# before the check is applied. There's no such rewrite for -D.
# Reject #cgo CFLAGS: -D @foo
-cp y_cflags_dash_d_space_at_foo.txt x/y.go
+cp y_cflags_dash_d_space_at_foo.txt y.go
! go build x
stderr 'invalid flag in #cgo CFLAGS: -D @foo'
# Reject #cgo CFLAGS -D@foo
-cp y_cflags_dash_d_at_foo.txt x/y.go
+cp y_cflags_dash_d_at_foo.txt y.go
! go build x
stderr 'invalid flag in #cgo CFLAGS: -D@foo'
# Check for CFLAGS in commands
env CGO_CFLAGS=-D@foo
-cp y_no_cflags.txt x/y.go
+cp y_no_cflags.txt y.go
go build -n x
stderr '-D@foo'
+-- go.mod --
+module x
+
+go 1.16
-- x_gc.go.txt --
package x
import "C"
-- y_no_cflags.txt --
package x
-import "C"
\ No newline at end of file
+import "C"
go list -race -deps foo
stdout syscall
--- foo/foo.go --
+-- go.mod --
+module foo
+
+go 1.16
+-- foo.go --
package foo
// #include <stdio.h>
stdout '\tg\t*100.0%' # Check g is 100% covered.
! stdout '\tf\t*[0-9]' # Check for no coverage on the assembly function
--- coverasm/p.go --
+-- go.mod --
+module coverasm
+
+go 1.16
+-- p.go --
package p
func f()
func g() {
println("g")
}
--- coverasm/p.s --
+-- p.s --
// empty asm file,
// so go test doesn't complain about declaration of f in p.go.
--- coverasm/p_test.go --
+-- p_test.go --
package p
import "testing"
[short] skip
-go test -cover ./coverblank
+go test -cover coverblank
stdout 'coverage: 100.0% of statements'
--- coverblank/a.go --
+-- go.mod --
+module coverblank
+
+go 1.16
+-- a.go --
package coverblank
func _() {
println("unreachable")
}
--- coverblank/a_test.go --
+-- a_test.go --
package coverblank
import "testing"
stdout 'coverage:.*[1-9][0-9.]+%'
! stderr '[^0-9]0\.0%'
--- cgocover/p.go --
+-- go.mod --
+module cgocover
+
+go 1.16
+-- p.go --
package p
/*
}
C.f()
}
--- cgocover/p_test.go --
+-- p_test.go --
package p
import "testing"
stdout 'coverage:.*[1-9][0-9.]+%'
! stderr '[^0-9]0\.0%'
--- cgocover4/notcgo.go --
+-- go.mod --
+module cgocover4
+
+go 1.16
+-- notcgo.go --
package p
--- cgocover4/p.go --
+-- p.go --
package p
/*
}
C.f()
}
--- cgocover4/x_test.go --
+-- x_test.go --
package p_test
import (
func TestF(t *testing.T) {
F()
-}
\ No newline at end of file
+}
stdout 'coverage:.*[1-9][0-9.]+%'
! stderr '[^0-9]0\.0%'
--- cgocover3/p.go --
+-- go.mod --
+module cgocover3
+
+go 1.16
+-- p.go --
package p
/*
}
C.f()
}
--- cgocover3/p_test.go --
+-- p_test.go --
package p
--- cgocover3/x_test.go --
+-- x_test.go --
package p_test
import (
func TestF(t *testing.T) {
F()
-}
\ No newline at end of file
+}
stdout 'coverage:.*[1-9][0-9.]+%'
! stderr '[^0-9]0\.0%'
--- cgocover2/p.go --
+-- go.mod --
+module cgocover2
+
+go 1.16
+-- p.go --
package p
/*
}
C.f()
}
--- cgocover2/x_test.go --
+-- x_test.go --
package p_test
import (
func TestF(t *testing.T) {
F()
-}
\ No newline at end of file
+}
go test -c -o $WORK/coverdep -coverprofile=$WORK/no/such/dir/cover.out coverdep
exists -exec $WORK/coverdep
--- coverdep/p.go --
+-- go.mod --
+module coverdep
+
+go 1.16
+-- p.go --
package p
import _ "coverdep/p1"
func F() {
}
--- coverdep/p1/p1.go --
+-- p1/p1.go --
package p1
import _ "errors"
--- coverdep/p_test.go --
+-- p_test.go --
package p
import "testing"
go test -short -cover coverdep2/p1
stdout 'coverage: 100.0% of statements' # expect 100.0% coverage
--- coverdep2/p1/p.go --
+-- go.mod --
+module coverdep2
+
+go 1.16
+-- p1/p.go --
package p1
func F() int { return 1 }
--- coverdep2/p1/p_test.go --
+-- p1/p_test.go --
package p1_test
import (
func Test(t *testing.T) {
p2.F()
}
--- coverdep2/p2/p2.go --
+-- p2/p2.go --
package p2
import "coverdep2/p1"
[short] skip
[gccgo] skip # gccgo has no cover tool
-go test -coverpkg=coverdot1,coverdot2 coverdot2
+go test -coverpkg=coverdot/a,coverdot/b coverdot/b
! stderr '[^0-9]0\.0%'
! stdout '[^0-9]0\.0%'
--- coverdot1/p.go --
-package coverdot1
+-- go.mod --
+module coverdot
+
+go 1.16
+-- a/a.go --
+package a
func F() {}
--- coverdot2/p.go --
-package coverdot2
+-- b/b.go --
+package b
-import . "coverdot1"
+import . "coverdot/a"
func G() { F() }
--- coverdot2/p_test.go --
-package coverdot2
+-- b/b_test.go --
+package b
import "testing"
# Get errors from a go test into stderr.txt
! go test coverbad
-stderr 'coverbad[\\/]p\.go:4' # look for error at coverbad/p.go:4
-[cgo] stderr 'coverbad[\\/]p1\.go:6' # look for error at coverbad/p.go:6
+stderr 'p\.go:4' # look for error at coverbad/p.go:4
+[cgo] stderr 'p1\.go:6' # look for error at coverbad/p.go:6
! stderr $WORK # make sure temporary directory isn't in error
cp stderr $WORK/stderr.txt
cmp $WORK/stderr.txt $WORK/stderr2.txt
--- coverbad/p.go --
+-- go.mod --
+module coverbad
+
+go 1.16
+-- p.go --
package p
func f() {
g()
}
--- coverbad/p1.go --
+-- p1.go --
package p
import "C"
func h() {
j()
}
--- coverbad/p_test.go --
+-- p_test.go --
package p
import "testing"
func Test(t *testing.T) {}
-- clean_charpos.go --
+// +build ignore
+
package main
import (
if err != nil {
log.Fatal(err)
}
-}
\ No newline at end of file
+}
! go test -n -cover importmain/test
stderr 'not an importable package' # check that import main was detected
--- importmain/ismain/main.go --
+-- go.mod --
+module importmain
+
+go 1.16
+-- ismain/main.go --
package main
import _ "importmain/test"
func main() {}
--- importmain/test/test.go --
+-- test/test.go --
package test
--- importmain/test/test_test.go --
+-- test/test_test.go --
package test_test
import "testing"
[gccgo] skip
-# If coverpkg=sleepy... expands by package loading
+# If coverpkg=m/sleepy... expands by package loading
# (as opposed to pattern matching on deps)
# then it will try to load sleepybad, which does not compile,
# and the test command will fail.
-! go list sleepy...
-go test -c -n -coverprofile=$TMPDIR/cover.out -coverpkg=sleepy... -run=^$ sleepy1
+! go list m/sleepy...
+go test -c -n -coverprofile=$TMPDIR/cover.out -coverpkg=m/sleepy... -run=^$ m/sleepy1
+-- go.mod --
+module m
+
+go 1.16
-- sleepy1/p_test.go --
package p
stdout 'pkg3 \S+ coverage: 100.0% of statements'
stdout 'pkg4 \S+ coverage: \[no statements\]'
+-- go.mod --
+module m
+
+go 1.16
-- pkg1/a.go --
package pkg1
go test -short -cover -covermode=atomic -coverpkg=coverdep/p1 coverdep
--- coverdep/p.go --
+-- go.mod --
+module coverdep
+
+go 1.16
+-- p.go --
package p
import _ "coverdep/p1"
func F() {
}
--- coverdep/p1/p1.go --
+-- p1/p1.go --
package p1
import _ "errors"
--- coverdep/p_test.go --
+-- p_test.go --
package p
import "testing"
func Test(t *testing.T) {
F()
-}
\ No newline at end of file
+}
go generate gencycle
stdout 'hello world' # check go generate gencycle ran the generator
--- gencycle/gencycle.go --
+-- go.mod --
+module gencycle
+
+go 1.16
+-- gencycle.go --
//go:generate echo hello world
package gencycle
fmt.Println()
}
+-- go.mod --
+module m
+
+go 1.16
-- nogo/foo.txt --
Text file in a directory without go files.
Go generate should ignore this directory.
package importerr
import "moo"
-//go:generate echo Success c
\ No newline at end of file
+//go:generate echo Success c
[!net] skip
[!exec:git] skip
+env GO111MODULE=off
go get -u rsc.io/pdf/...
-exists $GOPATH/bin/pdfpasswd$GOEXE
\ No newline at end of file
+exists $GOPATH/bin/pdfpasswd$GOEXE
[!net] skip
[!exec:git] skip
+env GO111MODULE=off
go get -v -t github.com/rsc/go-get-issue-8181/a github.com/rsc/go-get-issue-8181/b
go list ...
-stdout 'x/build/gerrit'
\ No newline at end of file
+stdout 'x/build/gerrit'
[!net] skip
[!exec:git] skip
+env GO111MODULE=off
# go-get-issue-9357.appspot.com is running
# the code at github.com/rsc/go-get-issue-9357,
go get go-get-issue-9357.appspot.com
rm $GOPATH/src/go-get-issue-9357.appspot.com
-go get -u go-get-issue-9357.appspot.com
\ No newline at end of file
+go get -u go-get-issue-9357.appspot.com
[!net] skip
[!exec:git] skip
+env GO111MODULE=off
# Tests Issues #9797 and #19769
mkdir $WORK/tmp/src/rsc.io
env GOPATH=$WORK/tmp
cd $WORK/tmp/src/rsc.io
-go get ./pprof_mac_fix
\ No newline at end of file
+go get ./pprof_mac_fix
[!net] skip
+env GO111MODULE=off
# Issue 4186. go get cannot be used to download packages to $GOROOT.
# Test that without GOPATH set, go get should fail.
env GOPATH=
env GOROOT=$WORK/home/go/
! go get -d github.com/golang/example/hello
-stderr '\$GOPATH not set'
\ No newline at end of file
+stderr '\$GOPATH not set'
[!net] skip
[!exec:git] skip
+env GO111MODULE=off
! go get -d insecure.go-get-issue-15410.appspot.com/pkg/p
-go get -d -insecure insecure.go-get-issue-15410.appspot.com/pkg/p
\ No newline at end of file
+go get -d -insecure insecure.go-get-issue-15410.appspot.com/pkg/p
[!net] skip
[!exec:git] skip
+env GO111MODULE=off
# Clone the repo via HTTP manually.
exec git clone -q http://github.com/golang/example github.com/golang/example
# Update with -insecure should succeed.
# We need -f to ignore import comments.
! go get -d -u -f github.com/golang/example/hello
-go get -d -u -f -insecure github.com/golang/example/hello
\ No newline at end of file
+go get -d -u -f -insecure github.com/golang/example/hello
[!net] skip
[!exec:git] skip
+env GO111MODULE=off
# This used to fail with errors about internal packages
-go get github.com/rsc/go-get-issue-11960/...
\ No newline at end of file
+go get github.com/rsc/go-get-issue-11960/...
[!net] skip
[!exec:git] skip
+env GO111MODULE=off
env GOPATH=$WORK/tmp/gopath
go get github.com/rsc/go-get-issue-11307
-go get -u github.com/rsc/go-get-issue-11307 # was failing
\ No newline at end of file
+go get -u github.com/rsc/go-get-issue-11307 # was failing
[short] skip
[!exec:git] skip
+env GO111MODULE=off
env GOPATH=$WORK/tmp/d1
go get vcs-test.golang.org/git/modlegacy1-old.git/p1
go get github.com/rsc/vgotest5 github.com/myitcv/vgo_example_compat github.com/rsc/vgotest4
rm $GOPATH
-go get github.com/rsc/vgotest5 github.com/rsc/vgotest4 github.com/myitcv/vgo_example_compat
\ No newline at end of file
+go get github.com/rsc/vgotest5 github.com/rsc/vgotest4 github.com/myitcv/vgo_example_compat
[!net] skip
[!exec:git] skip
[!race] skip
+env GO111MODULE=off
-go get -race github.com/rsc/go-get-issue-9224-cmd
\ No newline at end of file
+go get -race github.com/rsc/go-get-issue-9224-cmd
[!net] skip
[!exec:git] skip
+env GO111MODULE=off
go get golang.org/x/tour/content...
-go get -t golang.org/x/tour/content...
\ No newline at end of file
+go get -t golang.org/x/tour/content...
[!net] skip
[!exec:git] skip
+env GO111MODULE=off
# Rewind
go get github.com/rsc/go-get-issue-9224-cmd
cd $GOPATH/src
# (Again with -d -u) Run get
-go get -d -u 'github.com/rsc/go-get-issue-9224-cmd'
\ No newline at end of file
+go get -d -u 'github.com/rsc/go-get-issue-9224-cmd'
[!net] skip
[!exec:git] skip
+env GO111MODULE=off
# Clone the repo via HTTPS manually.
exec git clone -q https://github.com/golang/example github.com/golang/example
exec git remote set-url origin xyz://github.com/golang/example
exec git config --local url.https://github.com/.insteadOf xyz://github.com/
-go get -d -u -f github.com/golang/example/hello
\ No newline at end of file
+go get -d -u -f github.com/golang/example/hello
[!net] skip
[!exec:git] skip
+env GO111MODULE=off
go get github.com/tmwh/go-get-issue-14450/a
! go get -u .../
exists github.com/tmwh/go-get-issue-14450-b-dependency/c
exists github.com/tmwh/go-get-issue-14450-b-dependency/d
-! exists github.com/tmwh/go-get-issue-14450-c-dependency/e
\ No newline at end of file
+! exists github.com/tmwh/go-get-issue-14450-c-dependency/e
# Test that the Version Control error message includes the correct directory
+env GO111MODULE=off
! go get -u foo
stderr gopath(\\\\|/)src(\\\\|/)foo
[short] skip
+env GO111MODULE=off
cd $GOPATH/src/v
go run m.go
}
-- v/vendor/vendor.org/p/p.go --
package p
-const C = 1
\ No newline at end of file
+const C = 1
[!net] skip
+env GO111MODULE=off
# Issue 17119: Test more duplicate load errors.
! go build dupload
! go install cgotest
stderr 'build constraints exclude all Go files'
--- cgotest/m.go --
+-- go.mod --
+module cgotest
+
+go 1.16
+-- m.go --
package cgotest
import "C"
! go install
stderr 'cannot install, GOBIN must be an absolute path'
+-- go.mod --
+module triv
+
+go 1.16
-- triv.go --
package main
-func main() {}
\ No newline at end of file
+func main() {}
[!net] skip
+env GO111MODULE=off
env GOPATH=$WORK/gopath1${:}$WORK/gopath2
mkdir $WORK/gopath1/src/test
-- main.go --
package main
-func main() {}
\ No newline at end of file
+func main() {}
cc -c -o syso/objTestImpl.syso syso/src/objTestImpl.c
go build -ldflags='-linkmode=external' ./cmd/main.go
+-- go.mod --
+module m
+
+go 1.16
-- syso/objTest.s --
#include "textflag.h"
-- cmd/main.go --
package main
-import "syso"
+import "m/syso"
func main() {
syso.ObjTest()
# List files explicitly on command line, to encounter case-checking
# logic even on case-insensitive filesystems.
-cp example/b/file.go example/b/FILE.go # no-op on case-insensitive filesystems
-! go list example/b/file.go example/b/FILE.go
+cp b/file.go b/FILE.go # no-op on case-insensitive filesystems
+! go list b/file.go b/FILE.go
stderr 'case-insensitive file name collision'
-mkdir example/a/Pkg # no-op on case-insensitive filesystems
-cp example/a/pkg/pkg.go example/a/Pkg/pkg.go # no-op on case-insensitive filesystems
+mkdir a/Pkg # no-op on case-insensitive filesystems
+cp a/pkg/pkg.go a/Pkg/pkg.go # no-op on case-insensitive filesystems
! go list example/a/pkg example/a/Pkg
# Test that the path reported with an indirect import is correct.
-cp example/b/file.go example/b/FILE.go
+cp b/file.go b/FILE.go
[case-sensitive] ! go build example/c
[case-sensitive] stderr '^package example/c\n\timports example/b: case-insensitive file name collision: "FILE.go" and "file.go"$'
--- example/a/a.go --
+-- go.mod --
+module example
+
+go 1.16
+-- a/a.go --
package p
import (
_ "example/a/pkg"
_ "example/a/Pkg"
)
--- example/a/pkg/pkg.go --
+-- a/pkg/pkg.go --
package pkg
--- example/b/file.go --
+-- b/file.go --
package b
--- example/c/c.go --
+-- c/c.go --
package c
import _ "example/b"
# Setup
+env GO111MODULE=off
mkdir $WORK/tmp/testdata/src/xtestonly
cp f.go $WORK/tmp/testdata/src/xtestonly/f.go
cp f_test.go $WORK/tmp/testdata/src/xtestonly/f_test.go
[!symlink] skip
+env GO111MODULE=off
mkdir $WORK/tmp/src
symlink $WORK/tmp/src/dir1 -> $WORK/tmp
[!symlink] skip
+env GO111MODULE=off
mkdir $WORK/tmp/gopath/src/dir1/internal/v
cp p.go $WORK/tmp/gopath/src/dir1/p.go
func main() {}
-- v.go --
-package v
\ No newline at end of file
+package v
[!symlink] skip
+env GO111MODULE=off
mkdir $WORK/tmp/gopath/src/dir1/vendor/v
cp p.go $WORK/tmp/gopath/src/dir1/p.go
func main () {}
-- v.go --
-package v
\ No newline at end of file
+package v
[!symlink] skip
+env GO111MODULE=off
mkdir $WORK/tmp/gopath/src/x/y/_vendor/src/x
symlink $WORK/tmp/gopath/src/x/y/_vendor/src/x/y -> ../../..
import "x/y/z"
-- z.go --
-package z
\ No newline at end of file
+package z
[short] skip
-cd $WORK
-
# Test
-go test './gopath/src/testlist/...' -list=Test
+go test -list=Test
stdout TestSimple
# Benchmark
-go test './gopath/src/testlist/...' -list=Benchmark
+go test -list=Benchmark
stdout BenchmarkSimple
# Examples
-go test './gopath/src/testlist/...' -list=Example
+go test -list=Example
stdout ExampleSimple
stdout ExampleWithEmptyOutput
--- testlist/bench_test.go --
+-- go.mod --
+module m
+
+go 1.16
+-- bench_test.go --
package testlist
import (
_ = fmt.Sprint("Test for bench")
}
}
--- testlist/example_test.go --
+-- example_test.go --
package testlist
import (
func ExampleNoOutput() {
_ = fmt.Sprint("Test with no output")
}
--- testlist/test_test.go --
+-- test_test.go --
package testlist
import (
func TestSimple(t *testing.T) {
_ = fmt.Sprint("Test simple")
-}
\ No newline at end of file
+}
# Test that wildcards don't look in useless directories.
# First make sure that badpkg fails the list of '...'.
-! go list ...
+! go list ./...
stderr badpkg
-# Check that the list of 'm...' succeeds. That implies badpkg was skipped.
-go list m...
+# Check that the list of './goodpkg...' succeeds. That implies badpkg was skipped.
+go list ./goodpkg...
--- m/x.go --
-package m
+-- go.mod --
+module m
+
+go 1.16
+-- goodpkg/x.go --
+package goodpkg
-- badpkg/x.go --
-pkg badpkg
\ No newline at end of file
+pkg badpkg
d
d.test
d_test [d.test]
--- d/d.go --
+-- go.mod --
+module d
+
+go 1.16
+-- d.go --
package d
import "net/http"
const d = http.MethodGet
func Get() string { return d; }
--- d/d2.go --
--- d/d_test.go --
+-- d2.go --
+-- d_test.go --
package d_test
import "testing"
import "golang.org/fake/d"
-func TestD(t *testing.T) { d.Get(); }
\ No newline at end of file
+func TestD(t *testing.T) { d.Get(); }
-cd $GOPATH
-go run hello
+go run m/hello
stderr 'hello, world'
-cd src/hello
+cd hello
go run .
stderr 'hello, world'
+-- go.mod --
+module m
+
+go 1.16
-- hello/hello.go --
package main
# Run
+env GO111MODULE=off
cd vend/hello
go run hello.go
stdout 'hello, world'
! stderr ^ok
stdout FAIL.*benchfatal
--- benchfatal/x_test.go --
+-- go.mod --
+module benchfatal
+
+go 1.16
+-- x_test.go --
package benchfatal
import "testing"
! stdout 'pkg:.*pkg: '
! stderr 'pkg:.*pkg:'
--- bench/x_test.go --
+-- go.mod --
+module bench
+
+go 1.16
+-- x_test.go --
package bench
import "testing"
stderr 'undefined: g'
stderr 'undefined: j'
--- coverbad/p.go --
+-- go.mod --
+module coverbad
+
+go 1.16
+-- p.go --
package p
func f() {
g()
}
--- coverbad/p1.go --
+-- p1.go --
package p
import "C"
func h() {
j()
}
--- coverbad/p_test.go --
+-- p_test.go --
package p
import "testing"
go test -timeout=1m -run=TestDeadlineWithinMinute
go test -timeout=1m -run=TestSubtestDeadlineWithinMinute
+-- go.mod --
+module m
+
+go 1.16
-- deadline_test.go --
package testing_test
cd $GOPATH/src/empty/testxtest
go test -cover -coverpkg=. -race
+-- empty/go.mod --
+module empty
+
+go 1.16
-- empty/pkg/pkg.go --
package p
-- empty/pkgtest/pkg.go --
stdout '(?s)--- PASS.*--- FAIL.*'
stdout 'panic: test executed panic\(nil\) or runtime\.Goexit'
--- examplegoexit/example_test.go --
+-- go.mod --
+module examplegoexit
+
+go 1.16
+-- example_test.go --
package main
import (
+env GO111MODULE=off
! go test testdep/p1
stderr 'package testdep/p1 \(test\)\n\timports testdep/p2\n\timports testdep/p3: build constraints exclude all Go files ' # check for full import stack
+! go vet testdep/p1
+stderr 'package testdep/p1 \(test\)\n\timports testdep/p2\n\timports testdep/p3: build constraints exclude all Go files ' # check for full import stack
+env GO111MODULE=on
+cd testdep
+! go test testdep/p1
+stderr 'package testdep/p1 \(test\)\n\timports testdep/p2\n\timports testdep/p3: build constraints exclude all Go files ' # check for full import stack
! go vet testdep/p1
stderr 'package testdep/p1 \(test\)\n\timports testdep/p2\n\timports testdep/p3: build constraints exclude all Go files ' # check for full import stack
+-- testdep/go.mod --
+module testdep
+
+go 1.16
-- testdep/p1/p1.go --
package p1
-- testdep/p1/p1_test.go --
env GOCACHE=$WORK/tmp
-# Run go test -json on errors empty/pkg and skipper
+# Run go test -json on errors m/empty/pkg and m/skipper
# It would be nice to test that the output is interlaced
# but it seems to be impossible to do that in a short test
# that isn't also flaky. Just check that we get JSON output.
-go test -json -short -v errors empty/pkg skipper
+go test -json -short -v errors m/empty/pkg m/skipper
# Check errors for run action
stdout '"Package":"errors"'
stdout '"Action":"run","Package":"errors"'
-# Check empty/pkg for output and skip actions
-stdout '"Action":"output","Package":"empty/pkg","Output":".*no test files'
-stdout '"Action":"skip","Package":"empty/pkg"'
+# Check m/empty/pkg for output and skip actions
+stdout '"Action":"output","Package":"m/empty/pkg","Output":".*no test files'
+stdout '"Action":"skip","Package":"m/empty/pkg"'
# Check skipper for output and skip actions
-stdout '"Action":"output","Package":"skipper","Test":"Test","Output":"--- SKIP:'
-stdout '"Action":"skip","Package":"skipper","Test":"Test"'
+stdout '"Action":"output","Package":"m/skipper","Test":"Test","Output":"--- SKIP:'
+stdout '"Action":"skip","Package":"m/skipper","Test":"Test"'
# Run go test -json on errors and check it's cached
go test -json -short -v errors
stdout '"Action":"run"'
stdout '\{"Action":"pass","Package":"errors"\}'
+-- go.mod --
+module m
+
+go 1.16
-- skipper/skip_test.go --
package skipper
go test -v multimain
stdout -count=2 notwithstanding # check tests ran twice
--- multimain/multimain_test.go --
+-- go.mod --
+module multimain
+
+go 1.16
+-- multimain_test.go --
package multimain_test
import "testing"
! stderr '(?m)^ok.*\[no tests to run\]'
stdout 'FAIL'
--- syntaxerror/x.go --
+-- go.mod --
+module syntaxerror
+
+go 1.16
+-- x.go --
package p
--- syntaxerror/x_test.go --
+-- x_test.go --
package p
func f() (x.y, z int) {
go test -v norunexample
stdout 'File with non-runnable example was built.'
--- norunexample/example_test.go --
+-- go.mod --
+module norunexample
+
+go 1.16
+-- example_test.go --
package pkg_test
import "os"
func Example_test() {
// This test will not be run, it has no "Output:" comment.
}
--- norunexample/test_test.go --
+-- test_test.go --
package pkg
import (
go test testnorun
stdout 'testnorun\t\[no test files\]'
--- testnorun/p.go --
+-- go.mod --
+module testnorun
+
+go 1.16
+-- p.go --
package p
func init() {
! stdout 'PASS'
! stderr 'PASS'
--- testrace/race_test.go --
+-- go.mod --
+module testrace
+
+go 1.16
+-- race_test.go --
package testrace
import "testing"
! stdout PASS
! stderr PASS
--- testrace/race_test.go --
+-- go.mod --
+module testrace
+
+go 1.16
+-- race_test.go --
package testrace
import "testing"
go test -race -pkgdir=$WORKDIR/tmp/pkg -i -v empty/pkg
! stderr .
--- empty/pkg/pkg.go --
+-- go.mod --
+module empty
+
+go 1.16
+-- pkg/pkg.go --
package p
[!darwin] ! stale cmd/cgo # The darwin builders are spuriously stale; see #33598.
env GOBIN=$WORK/bin
-go install mtime sametime
+go install m/mtime m/sametime
go tool -n cgo
cp stdout cgopath.txt
cp stdout cgotime_after.txt
exec $GOBIN/sametime cgotime_before.txt cgotime_after.txt
+-- go.mod --
+module m
+
+go 1.16
-- mtime/mtime.go --
package main
# a large number, and the last iteration count prints right before the results.
stdout -count=2 '^ x_test.go:15: LOG: Y running N=[1-9]\d{4,}\nBenchmarkX/Y\s+\d+'
--- testregexp/x_test.go --
+-- go.mod --
+module testregexp
+
+go 1.16
+-- x_test.go --
package x
import "testing"
b.Logf("LOG: Y running N=%d", b.N)
})
}
--- testregexp/z_test.go --
+-- z_test.go --
package x
import "testing"
# Relative imports in go test
+env GO111MODULE=off # relative import not supported in module mode
# Run tests outside GOPATH.
env GOPATH=$WORK/tmp
if F() != p1.F() {
t.Fatal(F())
}
-}
\ No newline at end of file
+}
# Relative imports in go test -i
+env GO111MODULE=off # relative import not supported in module mode
# Run tests outside GOPATH.
env GOPATH=$WORK/tmp
if F() != p1.F() {
t.Fatal(F())
}
-}
\ No newline at end of file
+}
# Test that the error message for a syntax error in a test go file
# says FAIL.
+env GO111MODULE=off
! go test syntaxerror
stderr 'x_test.go:' # check that the error is diagnosed
stdout 'FAIL' # check that go test says FAIL
+env GO111MODULE=on
+cd syntaxerror
+! go test syntaxerror
+stderr 'x_test.go:' # check that the error is diagnosed
+stdout 'FAIL' # check that go test says FAIL
+
+-- syntaxerror/go.mod --
+module syntaxerror
+
+go 1.16
-- syntaxerror/x.go --
package p
-- syntaxerror/x_test.go --
-# Test
+# In GOPATH mode, vendored packages can replace std packages.
+env GO111MODULE=off
cd vend/hello
go test -v
stdout TestMsgInternal
stdout TestMsgExternal
+# In module mode, they cannot.
+env GO111MODULE=on
+! go test -mod=vendor
+stderr 'undefined: strings.Msg'
+
+-- vend/hello/go.mod --
+module vend/hello
+
+go 1.16
-- vend/hello/hello.go --
package main
stdout '\[no test files\]'
# Test issue #22890
-go test vetcycle
-stdout 'vetcycle.*\[no test files\]'
+go test m/vetcycle
+stdout 'm/vetcycle.*\[no test files\]'
# Test with ...
-! go test vetfail/...
+! go test ./vetfail/...
stderr 'Printf format %d'
-stdout 'ok\s+vetfail/p2'
+stdout 'ok\s+m/vetfail/p2'
# Check there's no diagnosis of a bad build constraint in vetxonly mode.
# Use -a so that we need to recompute the vet-specific export data for
# vetfail/p1.
-go test -a vetfail/p2
+go test -a m/vetfail/p2
! stderr 'invalid.*constraint'
+-- go.mod --
+module m
+
+go 1.16
-- p1_test.go --
package p
-- vetfail/p2/p2.go --
package p2
-import _ "vetfail/p1"
+import _ "m/vetfail/p1"
func F() {
}
[short] skip
-cd profiling
! go test -cpuprofile cpu.pprof -memprofile mem.pprof -timeout 1ms
grep . cpu.pprof
grep . mem.pprof
--- profiling/timeout_test.go --
+-- go.mod --
+module profiling
+
+go 1.16
+-- timeout_test.go --
package timeouttest_test
import "testing"
import "time"
-func TestSleep(t *testing.T) { time.Sleep(time.Second) }
\ No newline at end of file
+func TestSleep(t *testing.T) { time.Sleep(time.Second) }
! stdout '^ok.*\[no tests to run\]'
stdout '^ok'
--- xtestonly/f.go --
+-- go.mod --
+module xtestonly
+
+go 1.16
+-- f.go --
package xtestonly
func F() int { return 42 }
--- xtestonly/f_test.go --
+-- f_test.go --
package xtestonly_test
import (
go test -race testrace
--- testrace/race_test.go --
+-- go.mod --
+module testrace
+
+go 1.16
+-- race_test.go --
package testrace
import "testing"
[!windows] [short] stop 'this test only applies to Windows'
+env GO111MODULE=off
go build run_go.go
exec ./run_go$GOEXE $GOPATH $GOPATH/src/vend/hello
# Imports
+env GO111MODULE=off
go list -f '{{.ImportPath}} {{.Imports}}' 'vend/...' 'vend/vendor/...' 'vend/x/vendor/...'
cmp stdout want_vendor_imports.txt
# Wrong import path
+env GO111MODULE=off
! go build vend/x/invalid
stderr 'must be imported as foo'
+env GO111MODULE=
+cd vend/x/invalid
+! go build vend/x/invalid
+stderr 'must be imported as foo'
+
+-- vend/x/invalid/go.mod --
+module vend/x/invalid
+
+go 1.16
+
-- vend/x/invalid/invalid.go --
package invalid
# Tests issue #12156, a former index out of range panic.
+env GO111MODULE=off
env GOPATH=$WORK/gopath/src/testvendor2 # vendor/x is directly in $GOPATH, not in $GOPATH/src
cd $WORK/gopath/src/testvendor2/src/p
[!net] skip
[!exec:git] skip
+env GO111MODULE=off
go get github.com/rsc/go-get-issue-11864
stdout 'go-get-issue-11864/vendor/vendor.org/tx2'
go list -f '{{join .XTestImports "\n"}}' github.com/rsc/go-get-issue-11864/vendor/vendor.org/tx3
-stdout 'go-get-issue-11864/vendor/vendor.org/tx3'
\ No newline at end of file
+stdout 'go-get-issue-11864/vendor/vendor.org/tx3'
+env GO111MODULE=off
! go build p
stderr 'must be imported as x'
[!net] skip
[!exec:git] skip
+env GO111MODULE=off
go get github.com/rsc/go-get-issue-11864
go test github.com/rsc/go-get-issue-11864/t
# external tests should observe internal test exports (golang.org/issue/11977)
-go test github.com/rsc/go-get-issue-11864/vendor/vendor.org/tx2
\ No newline at end of file
+go test github.com/rsc/go-get-issue-11864/vendor/vendor.org/tx2
[!net] skip
[!exec:git] skip
+env GO111MODULE=off
cd $GOPATH
# Package with external tests
-! go vet vetpkg
+! go vet m/vetpkg
stderr 'Printf'
# With tags
-! go vet -tags tagtest vetpkg
+! go vet -tags tagtest m/vetpkg
stderr 'c\.go.*Printf'
# With flags on
-! go vet -printf vetpkg
+! go vet -printf m/vetpkg
stderr 'Printf'
# With flags off
-go vet -printf=false vetpkg
+go vet -printf=false m/vetpkg
! stderr .
# With only test files (tests issue #23395)
-go vet onlytest
+go vet m/onlytest
! stderr .
# With only cgo files (tests issue #24193)
[!cgo] skip
[short] skip
-go vet onlycgo
+go vet m/onlycgo
! stderr .
+-- go.mod --
+module m
+
+go 1.16
-- vetpkg/a_test.go --
package p_test
-- vetpkg/b.go --
import "C"
-func F() {}
\ No newline at end of file
+func F() {}