Skip to content

cmd/go: tests fail when GOROOT is stale #48698

@mvdan

Description

@mvdan

I was running go test inside cmd/go, just like one does, and was surprised to see a failure:

$ go test -run=TestScript/mod_outside
go test proxy running at GOPROXY=http://127.0.0.1:39569/mod
--- FAIL: TestScript (0.00s)
    --- FAIL: TestScript/mod_outside (0.96s)
        script_test.go:257: 
            # This script tests commands in module mode outside of any module.
            #
            # First, ensure that we really are in module mode, and that we really don't have
            # a go.mod file. (0.003s)
            # 'go list' without arguments implicitly operates on the current directory,
            # which is not in a module. (0.006s)
            # 'go list' in the working directory should fail even if there is a a 'package
            # main' present: without a main module, we do not know its package path. (0.004s)
            # 'go list all' lists the transitive import graph of the main module,
            # which is empty if there is no main module. (0.003s)
            # 'go list' on standard-library packages should work, since they do not depend
            # on the contents of any module. (0.166s)
            # 'go list' should work with file arguments. (0.032s)
            # 'go list' on a package from a module should fail. (0.003s)
            # 'go list -m' with an explicit version should resolve that version. (0.006s)
            # 'go list -m -versions' should succeed even without an explicit version. (0.005s)
            # 'go list -m all' should fail. "all" is not meaningful outside of a module. (0.003s)
            # 'go list -m <mods> all' should also fail. (0.003s)
            # 'go list -m <mods>' should fail if any of the mods lacks an explicit version. (0.003s)
            # 'go list -m' with wildcards should fail. Wildcards match modules in the
            # build list, so they aren't meaningful outside a module. (0.006s)
            # 'go clean' should skip the current directory if it isn't in a module. (0.003s)
            # 'go mod graph' should fail, since there's no module graph. (0.003s)
            # 'go mod why' should fail, since there is no main module to depend on anything. (0.002s)
            # 'go mod edit', 'go mod tidy', and 'go mod fmt' should fail:
            # there is no go.mod file to edit. (0.008s)
            # 'go mod download' without arguments should report an error. (0.003s)
            # 'go mod download' should download exactly the requested module without dependencies. (0.007s)
            # 'go mod download all' should fail. "all" is not meaningful outside of a module. (0.003s)
            # 'go mod vendor' should fail: it starts by clearing the existing vendor
            # directory, and we don't know where that is. (0.003s)
            # 'go mod verify' should fail: we have no modules to verify. (0.003s)
            # 'go get' has no go.mod file to update outside a module and should fail. (0.014s)
            # 'go get' should not download anything. (0.006s)
            # 'go build' without arguments implicitly operates on the current directory, and should fail. (0.003s)
            # 'go build' of a non-module directory should fail too. (0.003s)
            # 'go build' of source files should fail if they import anything outside std. (0.036s)
            # 'go build' of source files should succeed if they do not import anything outside std. (0.053s)
            # 'go build' should succeed for standard-library packages. (0.042s)
            # 'go build' should use the latest version of the Go language. (0.040s)
            # 'go doc' without arguments implicitly operates on the current directory, and should fail.
            # TODO(golang.org/issue/32027): currently, it succeeds. (0.006s)
            # 'go doc' of a non-module directory should also succeed. (0.006s)
            # 'go doc' should succeed for standard-library packages. (0.010s)
            # 'go doc' should fail for a package path outside a module. (0.023s)
            # 'go install' with a version should succeed if all constraints are met.
            # See mod_install_pkg_version. (0.175s)
            # 'go install' should fail if a package argument must be resolved to a module. (0.004s)
            # 'go install' should fail if a source file imports a package that must be
            # resolved to a module. (0.031s)
            # 'go install' should succeed with a package in GOROOT. (0.219s)
            > go install cmd/addr2line
            [stderr]
            go install cmd/addr2line: cmd/go/internal/work/exec.go:1648: testgo must not write to GOROOT (installing to GOROOT/pkg/tool/linux_amd64/addr2line)
            [exit status 1]
            FAIL: testdata/script/mod_outside.txt:207: unexpected command failure
FAIL

There isn't anything special about my GOROOT; it's just built from source.

$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mvdan/.cache/go-build"
GOENV="/home/mvdan/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/mvdan/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/mvdan/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/mvdan/tip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/mvdan/tip/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.18-6656269288 Thu Sep 30 01:32:54 2021 +0000"
GCCGO="gccgo"
GOAMD64="v3"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/mvdan/tip/src/cmd/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1046648373=/tmp/go-build -gno-record-gcc-switches"

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeGoCommandcmd/goNeedsFixThe path to resolution is known, but the work has not been done.TestingAn issue that has been verified to require only test changes, not just a test failure.Unfortunate

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions