cmd/go/internal/work: add missing newline to go version note
A missed newline was added for one case in CL 162957, but
the parallel no-output case was missed.
Add the missed newline for the second case and update the test to
cover the full line for both cases.
Updates #30263
Change-Id: I02aa523290295a6d409cd68066b45c6990e6fb6e
Reviewed-on: https://go-review.googlesource.com/c/go/+/258758
Reviewed-by: Jay Conrod <jayconrod@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Bryan C. Mills <bcmills@google.com>
diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go
index 157ac4c..6ce56dd 100644
--- a/src/cmd/go/internal/work/exec.go
+++ b/src/cmd/go/internal/work/exec.go
@@ -766,7 +766,7 @@
}
if err != nil {
if p.Module != nil && !allowedVersion(p.Module.GoVersion) {
- b.showOutput(a, a.Package.Dir, a.Package.Desc(), "note: module requires Go "+p.Module.GoVersion)
+ b.showOutput(a, a.Package.Dir, a.Package.Desc(), "note: module requires Go "+p.Module.GoVersion+"\n")
}
return err
}
diff --git a/src/cmd/go/testdata/script/mod_go_version.txt b/src/cmd/go/testdata/script/mod_go_version.txt
index 37f1735..97d9975 100644
--- a/src/cmd/go/testdata/script/mod_go_version.txt
+++ b/src/cmd/go/testdata/script/mod_go_version.txt
@@ -8,12 +8,19 @@
go build subver.1
! stderr 'module requires'
! go build badsub.1
-stderr 'module requires Go 1.11111'
+stderr '^note: module requires Go 1.11111$'
go build versioned.1
go mod edit -require versioned.1@v1.1.0
! go build versioned.1
-stderr 'module requires Go 1.99999'
+stderr '^note: module requires Go 1.99999$'
+
+[short] stop
+
+# The message should be printed even if the compiler emits no output.
+go build -o $WORK/nooutput.exe nooutput.go
+! go build -toolexec=$WORK/nooutput.exe versioned.1
+stderr '^# versioned.1\nnote: module requires Go 1.99999$'
-- go.mod --
module m
@@ -71,3 +78,33 @@
-- versioned2/x.go --
package x
invalid syntax
+
+-- nooutput.go --
+// +build ignore
+
+package main
+
+import (
+ "bytes"
+ "os"
+ "os/exec"
+ "strings"
+)
+
+func main() {
+ stderr := new(bytes.Buffer)
+ stdout := new(bytes.Buffer)
+
+ cmd := exec.Command(os.Args[1], os.Args[2:]...)
+ cmd.Stderr = stderr
+ cmd.Stdout = stdout
+
+ err := cmd.Run()
+ if strings.HasPrefix(os.Args[2], "-V") {
+ os.Stderr.Write(stderr.Bytes())
+ os.Stdout.Write(stdout.Bytes())
+ }
+ if err != nil {
+ os.Exit(1)
+ }
+}