aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/cover/cover_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/cover/cover_test.go')
-rw-r--r--src/cmd/cover/cover_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/cmd/cover/cover_test.go b/src/cmd/cover/cover_test.go
index 28be231121..8a68911bd3 100644
--- a/src/cmd/cover/cover_test.go
+++ b/src/cmd/cover/cover_test.go
@@ -570,3 +570,34 @@ func run(c *exec.Cmd, t *testing.T) {
t.Fatal(err)
}
}
+
+func TestSrcPathWithNewline(t *testing.T) {
+ t.Parallel()
+ buildCover(t)
+
+ // srcPath is intentionally not clean so that the path passed to testcover
+ // will not normalize the trailing / to a \ on Windows.
+ srcPath := t.TempDir() + string(filepath.Separator) + "\npackage main\nfunc main() { panic(string([]rune{'u', 'h', '-', 'o', 'h'}))\n/*/main.go"
+ mainSrc := ` package main
+
+func main() {
+ /* nothing here */
+ println("ok")
+}
+`
+ if err := os.MkdirAll(filepath.Dir(srcPath), 0777); err != nil {
+ t.Skipf("creating directory with bogus path: %v", err)
+ }
+ if err := os.WriteFile(srcPath, []byte(mainSrc), 0666); err != nil {
+ t.Skipf("writing file with bogus directory: %v", err)
+ }
+
+ cmd := exec.Command(testcover, "-mode=atomic", srcPath)
+ cmd.Stderr = new(bytes.Buffer)
+ out, err := cmd.Output()
+ t.Logf("%v:\n%s", cmd, out)
+ t.Logf("stderr:\n%s", cmd.Stderr)
+ if err == nil {
+ t.Errorf("unexpected success; want failure due to newline in file path")
+ }
+}