diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go index 30fe446e43..943547e71b 100644 --- a/src/cmd/go/internal/modload/init.go +++ b/src/cmd/go/internal/modload/init.go @@ -294,7 +294,7 @@ func InitWorkfile() { workFilePath = findWorkspaceFile(base.Cwd()) default: if !filepath.IsAbs(cfg.WorkFile) { - base.Errorf("the path provided to -workfile must be an absolute path") + base.Fatalf("the path provided to -workfile must be an absolute path") } workFilePath = cfg.WorkFile } @@ -590,9 +590,8 @@ func ReadWorkFile(path string) (*modfile.WorkFile, error) { if err != nil { return nil, err } - wf, err := modfile.ParseWork(path, workData, nil) - return wf, nil + return modfile.ParseWork(path, workData, nil) } // WriteWorkFile cleans and writes out the go.work file to the given path. diff --git a/src/cmd/go/internal/test/test.go b/src/cmd/go/internal/test/test.go index b7bbcb4513..7ea9d4f1f1 100644 --- a/src/cmd/go/internal/test/test.go +++ b/src/cmd/go/internal/test/test.go @@ -619,8 +619,8 @@ var defaultVetFlags = []string{ } func runTest(ctx context.Context, cmd *base.Command, args []string) { - modload.InitWorkfile() pkgArgs, testArgs = testFlags(args) + modload.InitWorkfile() // The test command does custom flag processing; initialize workspaces after that. if cfg.DebugTrace != "" { var close func() error diff --git a/src/cmd/go/testdata/script/work_workfile.txt b/src/cmd/go/testdata/script/work_workfile.txt new file mode 100644 index 0000000000..b62918147e --- /dev/null +++ b/src/cmd/go/testdata/script/work_workfile.txt @@ -0,0 +1,21 @@ +! go list -workfile=stop.work a # require absolute path +! stderr panic +! go list -workfile=doesnotexist a +! stderr panic + +go list -n -workfile=$GOPATH/src/stop.work a +go build -n -workfile=$GOPATH/src/stop.work a +go test -n -workfile=$GOPATH/src/stop.work a + +-- stop.work -- +go 1.18 + +use ./a +-- a/a.go -- +package a +-- a/a_test.go -- +package a +-- a/go.mod -- +module a + +go 1.18 \ No newline at end of file