Skip to content

Commit fd5bf03

Browse files
motemenianlancetaylor
authored andcommitted
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: 1493f38 GitHub-Pull-Request: #23985 Reviewed-on: https://go-review.googlesource.com/95755 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent a5c987f commit fd5bf03

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/cmd/go/go_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5921,3 +5921,11 @@ echo $* >>`+tg.path("pkg-config.out"))
59215921
t.Errorf("got %q want %q", out, want)
59225922
}
59235923
}
5924+
5925+
// Issue 23982
5926+
func TestFilepathUnderCwdFormat(t *testing.T) {
5927+
tg := testgo(t)
5928+
defer tg.cleanup()
5929+
tg.run("test", "-x", "-cover", "log")
5930+
tg.grepStderrNot(`\.log\.cover\.go`, "-x output should contain correctly formatted filepath under cwd")
5931+
}

src/cmd/go/internal/work/exec.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,11 @@ func mayberemovefile(s string) {
13641364
func (b *Builder) fmtcmd(dir string, format string, args ...interface{}) string {
13651365
cmd := fmt.Sprintf(format, args...)
13661366
if dir != "" && dir != "/" {
1367-
cmd = strings.Replace(" "+cmd, " "+dir, " .", -1)[1:]
1367+
dot := " ."
1368+
if dir[len(dir)-1] == filepath.Separator {
1369+
dot += string(filepath.Separator)
1370+
}
1371+
cmd = strings.Replace(" "+cmd, " "+dir, dot, -1)[1:]
13681372
if b.scriptDir != dir {
13691373
b.scriptDir = dir
13701374
cmd = "cd " + dir + "\n" + cmd

0 commit comments

Comments
 (0)