From 1493f38bafdf2c40f16392b794fd1a12eb12a151 Mon Sep 17 00:00:00 2001 From: motemen Date: Wed, 21 Feb 2018 17:37:37 +0900 Subject: [PATCH] add test, use filepath.Separator --- src/cmd/go/go_test.go | 8 ++++++++ src/cmd/go/internal/work/exec.go | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) 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 a9f622c793..e61d6d5cc4 100644 --- a/src/cmd/go/internal/work/exec.go +++ b/src/cmd/go/internal/work/exec.go @@ -1365,8 +1365,8 @@ func (b *Builder) fmtcmd(dir string, format string, args ...interface{}) string cmd := fmt.Sprintf(format, args...) if dir != "" && dir != "/" { dot := " ." - if dir[len(dir)-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 {