From fd5bf0393eb7b3a21b55adf2c0f1e293b24cf308 Mon Sep 17 00:00:00 2001 From: motemen Date: Mon, 26 Feb 2018 18:22:46 +0000 Subject: [PATCH] cmd/go: fix formatting of file paths under cwd The output of go with -x flag is formatted in a manner that file paths under current directory are modified to start with a dot (.), but when the directory path ends with a slash (/), the formatting goes wrong. Fixes #23982 Change-Id: I8f8d15dd52bee882a9c6357eb9eabdc3eaa887c3 GitHub-Last-Rev: 1493f38bafdf2c40f16392b794fd1a12eb12a151 GitHub-Pull-Request: golang/go#23985 Reviewed-on: https://go-review.googlesource.com/95755 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/cmd/go/go_test.go | 8 ++++++++ src/cmd/go/internal/work/exec.go | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index 773b8240d2..8f5a1f6c71 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -5921,3 +5921,11 @@ echo $* >>`+tg.path("pkg-config.out")) t.Errorf("got %q want %q", out, want) } } + +// Issue 23982 +func TestFilepathUnderCwdFormat(t *testing.T) { + tg := testgo(t) + defer tg.cleanup() + tg.run("test", "-x", "-cover", "log") + tg.grepStderrNot(`\.log\.cover\.go`, "-x output should contain correctly formatted filepath under cwd") +} diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go index ab216e748f..e61d6d5cc4 100644 --- a/src/cmd/go/internal/work/exec.go +++ b/src/cmd/go/internal/work/exec.go @@ -1364,7 +1364,11 @@ func mayberemovefile(s string) { func (b *Builder) fmtcmd(dir string, format string, args ...interface{}) string { cmd := fmt.Sprintf(format, args...) if dir != "" && dir != "/" { - cmd = strings.Replace(" "+cmd, " "+dir, " .", -1)[1:] + dot := " ." + if dir[len(dir)-1] == filepath.Separator { + dot += string(filepath.Separator) + } + cmd = strings.Replace(" "+cmd, " "+dir, dot, -1)[1:] if b.scriptDir != dir { b.scriptDir = dir cmd = "cd " + dir + "\n" + cmd -- 2.48.1