Skip benchmarks if /usr/share/dict/words isn't readable.
Fixes #1.
diff --git a/snappy_test.go b/snappy_test.go
index 0623385..7ec2373 100644
--- a/snappy_test.go
+++ b/snappy_test.go
@@ -222,7 +222,7 @@
func readFile(b testing.TB, filename string) []byte {
src, err := ioutil.ReadFile(filename)
if err != nil {
- b.Fatalf("failed reading %s: %s", filename, err)
+ b.Skipf("skipping benchmark: %v", err)
}
if len(src) == 0 {
b.Fatalf("%s has zero length", filename)
@@ -284,14 +284,14 @@
// The test data files are present at this canonical URL.
const baseURL = "https://raw.githubusercontent.com/google/snappy/master/testdata/"
-func downloadTestdata(basename string) (errRet error) {
+func downloadTestdata(b *testing.B, basename string) (errRet error) {
filename := filepath.Join(*testdata, basename)
if stat, err := os.Stat(filename); err == nil && stat.Size() != 0 {
return nil
}
if !*download {
- return fmt.Errorf("test data not found; skipping benchmark without the -download flag")
+ b.Skipf("test data not found; skipping benchmark without the -download flag")
}
// Download the official snappy C++ implementation reference test data
// files for benchmarking.
@@ -326,7 +326,7 @@
}
func benchFile(b *testing.B, n int, decode bool) {
- if err := downloadTestdata(testFiles[n].filename); err != nil {
+ if err := downloadTestdata(b, testFiles[n].filename); err != nil {
b.Fatalf("failed to download testdata: %s", err)
}
data := readFile(b, filepath.Join(*testdata, testFiles[n].filename))