# GO111MODULE=auto should only trigger outside GOPATH/src
env GO111MODULE=auto

cd $GOPATH/src/x/y/z
go env GOMOD
! stdout . # no non-empty lines
! go list -m -f {{.GoMod}}
stderr 'not using modules'

cd $GOPATH/src/x/y/z/w
go env GOMOD
! stdout .

cd $GOPATH/src/x/y
go env GOMOD
! stdout .

cd $GOPATH/foo
go env GOMOD
stdout foo[/\\]go.mod
go list -m -f {{.GoMod}}
stdout foo[/\\]go.mod

cd $GOPATH/foo/bar/baz
go env GOMOD
stdout foo[/\\]go.mod

# GO111MODULE=on should trigger everywhere
env GO111MODULE=on

cd $GOPATH/src/x/y/z
go env GOMOD
stdout z[/\\]go.mod

cd $GOPATH/src/x/y/z/w
go env GOMOD
stdout z[/\\]go.mod

cd $GOPATH/src/x/y
go env GOMOD
! stdout .
! go list -m
stderr 'cannot find main module'

cd $GOPATH/foo
go env GOMOD
stdout foo[/\\]go.mod

cd $GOPATH/foo/bar/baz
go env GOMOD
stdout foo[/\\]go.mod

# GO111MODULE=off should trigger nowhere
env GO111MODULE=off

cd $GOPATH/src/x/y/z
go env GOMOD
! stdout .+

cd $GOPATH/foo
go env GOMOD
! stdout .+

cd $GOPATH/foo/bar/baz
go env GOMOD
! stdout .+

-- $GOPATH/src/x/y/z/go.mod --
module x/y/z
-- $GOPATH/src/x/y/z/w/w.txt --
-- $GOPATH/foo/go.mod --
module example.com/mod
-- $GOPATH/foo/bar/baz/quux.txt --
