From d70a33a40bd2bab2f8cd6ab714c4664ce55dc499 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Thu, 1 Oct 2020 10:53:41 -0400 Subject: [PATCH] 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 Run-TryBot: Bryan C. Mills TryBot-Result: Go Bot Trust: Bryan C. Mills --- src/cmd/go/internal/work/exec.go | 2 +- src/cmd/go/testdata/script/mod_go_version.txt | 41 ++++++++++++++++++- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go index 157ac4cafc..6ce56dd6f4 100644 --- a/src/cmd/go/internal/work/exec.go +++ b/src/cmd/go/internal/work/exec.go @@ -766,7 +766,7 @@ OverlayLoop: } 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 37f173531b..97d9975e68 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 sub.1 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 @@ go 1.99999 -- 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) + } +} -- 2.48.1