tg.wantExecutable("myerrors.test"+exeSuffix, "go test -mutexprofile -o myerrors.test did not create myerrors.test")
}
+func TestGoBuildNonMain(t *testing.T) {
+ tg := testgo(t)
+ defer tg.cleanup()
+ // TODO: tg.parallel()
+ tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
+ tg.runFail("build", "-buildmode=exe", "-o", "not_main"+exeSuffix, "not_main")
+ tg.grepStderr("-buildmode=exe requires exactly one main package", "go build with -o and -buildmode=exe should on a non-main package should throw an error")
+ tg.mustNotExist("not_main" + exeSuffix)
+}
+
func TestGoTestDashCDashOControlsBinaryLocation(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
depMode = ModeInstall
}
+ pkgs = pkgsFilter(load.Packages(args))
+
if cfg.BuildO != "" {
if len(pkgs) > 1 {
base.Fatalf("go build: cannot use -o with multiple packages")
return
}
- pkgs = pkgsFilter(load.Packages(args))
-
a := &Action{Mode: "go build"}
for _, p := range pkgs {
a.Deps = append(a.Deps, b.AutoAction(ModeBuild, depMode, p))
case "exe":
pkgsFilter = pkgsMain
ldBuildmode = "exe"
+ // Set the pkgsFilter to oneMainPkg if the user passed a specific binary output
+ // and is using buildmode=exe for a better error message.
+ // See issue #20017.
+ if cfg.BuildO != "" {
+ pkgsFilter = oneMainPkg
+ }
case "pie":
if cfg.BuildRace {
base.Fatalf("-buildmode=pie not supported when -race is enabled")