Tests do custom flag processing so we must process the workfile flag
after that happens.
Also fix an issue where errors weren't handled properly when the
workfile wasn't absolute (the go command should just exit), and where a
parse error was just dropped.
Fixes #48576
Change-Id: I3a94d8d3a515114b2c4cc0e73f63447df2fc6bc9
Reviewed-on: https://go-review.googlesource.com/c/go/+/366174
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
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
}
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.
}
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
--- /dev/null
+! 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