cover: eliminate an unnecessary fsync in TestParseProfiles

CL 179377 added TestParseProfiles, and used a call to (*os.File).Sync
instead of closing the file to flush its pending writes.
Unfortunately, on some filesystems Sync is fabulously expensive — it
may flush all pending writes everywhere on the filesystem, instead of
just flushing the writes to the one file, and flushes all the way to
disk even though this test really only needs tho writes to be
observable in the same process.

Instead, we can simplify the test significantly by using os.WriteFile
to write and flush the file's contents.

Fixes golang/go#57481.

Change-Id: I7cda28fb6e9c8183dedadf79dbafe7e870ec0c42
Reviewed-on: https://go-review.googlesource.com/c/tools/+/495798
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
diff --git a/cover/profile_test.go b/cover/profile_test.go
index 3cecdac..925b397 100644
--- a/cover/profile_test.go
+++ b/cover/profile_test.go
@@ -6,8 +6,8 @@
 
 import (
 	"fmt"
-	"io/ioutil"
 	"os"
+	"path/filepath"
 	"reflect"
 	"testing"
 )
@@ -208,26 +208,12 @@
 
 	for _, tc := range tests {
 		t.Run(tc.name, func(t *testing.T) {
-			f, err := ioutil.TempFile("", "")
-			if err != nil {
-				t.Fatalf("Failed to create a temp file: %v.", err)
-			}
-			defer func() {
-				f.Close()
-				os.Remove(f.Name())
-			}()
-			n, err := f.WriteString(tc.input)
-			if err != nil {
-				t.Fatalf("Failed to write to temp file: %v", err)
-			}
-			if n < len(tc.input) {
-				t.Fatalf("Didn't write enough bytes to temp file (wrote %d, expected %d).", n, len(tc.input))
-			}
-			if err := f.Sync(); err != nil {
-				t.Fatalf("Failed to sync temp file: %v", err)
+			fname := filepath.Join(t.TempDir(), "test.cov")
+			if err := os.WriteFile(fname, []byte(tc.input), 0644); err != nil {
+				t.Fatal(err)
 			}
 
-			result, err := ParseProfiles(f.Name())
+			result, err := ParseProfiles(fname)
 			if err != nil {
 				if !tc.expectErr {
 					t.Errorf("Unexpected error: %v", err)