benchfmt: fix file-does-not-exist error check in tests
Currently, the benchfmt.Files test looks for a specific error message
when checking the handling of nonexistent files. Unfortunately, the
text varies between OSes, making this very hard to do in a robust way.
Change it to just use errors.Is.
This should fix the Plan 9 builder failures.
Change-Id: Ib501cf4c02198a298d6dd902f3593c1887f114c3
Reviewed-on: https://go-review.googlesource.com/c/perf/+/393636
Trust: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
diff --git a/benchfmt/files_test.go b/benchfmt/files_test.go
index eb46bfe..923c53a 100644
--- a/benchfmt/files_test.go
+++ b/benchfmt/files_test.go
@@ -5,9 +5,10 @@
package benchfmt
import (
+ "errors"
+ "io/fs"
"os"
"strings"
- "syscall"
"testing"
)
@@ -45,17 +46,17 @@
}
err := f.Err()
- wantErr := ""
- if len(want) == 1 && strings.HasPrefix(want[0], "err ") {
- wantErr = want[0][len("err "):]
+ noent := errors.Is(err, fs.ErrNotExist)
+ wantNoent := len(want) == 1 && strings.HasPrefix(want[0], "ErrNotExist")
+ if wantNoent {
want = want[1:]
}
- if err == nil && wantErr != "" {
- t.Errorf("got success, want error %s", wantErr)
- } else if err != nil && wantErr == "" {
- t.Errorf("got error %s", err)
- } else if err != nil && err.Error() != wantErr {
- t.Errorf("got error %s, want error %s", err, wantErr)
+ if err != nil && !noent {
+ t.Errorf("got unexpected error %s", err)
+ } else if noent && !wantNoent {
+ t.Errorf("got %s, want success", err)
+ } else if !noent && wantNoent {
+ t.Errorf("got success, want ErrNotExist")
}
if len(want) != 0 {
@@ -70,7 +71,7 @@
)
check(
&Files{Paths: []string{"a", "b", "c", "d"}},
- "a X", "a Y", "b Z", "err open c: "+syscall.ENOENT.Error(),
+ "a X", "a Y", "b Z", "ErrNotExist",
)
// Ambiguous paths.
@@ -82,7 +83,7 @@
// AllowStdin.
check(
&Files{Paths: []string{"-"}},
- "err open -: "+syscall.ENOENT.Error(),
+ "ErrNotExist",
)
fakeStdin("BenchmarkIn 1 1 ns/op\n", func() {
check(