diff --git a/samples/statfs/statfs_darwin_test.go b/samples/statfs/statfs_darwin_test.go index 8745432..bb7c2a9 100644 --- a/samples/statfs/statfs_darwin_test.go +++ b/samples/statfs/statfs_darwin_test.go @@ -16,6 +16,7 @@ package statfs_test import ( "fmt" + "regexp" "syscall" "github.com/jacobsa/fuse/fuseops" @@ -23,6 +24,13 @@ import ( . "github.com/jacobsa/ogletest" ) +// Sample output: +// +// Filesystem 1024-blocks Used Available Capacity iused ifree %iused Mounted on +// fake@bucket 32 16 16 50% 0 0 100% /Users/jacobsa/tmp/mp +// +var gDfOutputRegexp = regexp.MustCompile(`^\S+\s+(\d+)\s+(\d+)\s+(\d+)\s+\d+%\s+\d+\s+\d+\s+\d+%.*$`) + //////////////////////////////////////////////////////////////////////// // Helpers //////////////////////////////////////////////////////////////////////// diff --git a/samples/statfs/statfs_linux_test.go b/samples/statfs/statfs_linux_test.go index f7cb63d..40bae68 100644 --- a/samples/statfs/statfs_linux_test.go +++ b/samples/statfs/statfs_linux_test.go @@ -17,12 +17,20 @@ package statfs_test import ( "fmt" "math" + "regexp" "syscall" "github.com/jacobsa/fuse/fuseops" . "github.com/jacobsa/ogletest" ) +// Sample output: +// +// Filesystem 1K-blocks Used Available Use% Mounted on +// some_fuse_file_system 512 64 384 15% /tmp/sample_test001288095 +// +var gDfOutputRegexp = regexp.MustCompile(`^\S+\s+(\d+)\s+(\d+)\s+(\d+)\s+\d+%.*$`) + //////////////////////////////////////////////////////////////////////// // Tests //////////////////////////////////////////////////////////////////////// diff --git a/samples/statfs/statfs_test.go b/samples/statfs/statfs_test.go index 677b53d..458ef73 100644 --- a/samples/statfs/statfs_test.go +++ b/samples/statfs/statfs_test.go @@ -21,7 +21,6 @@ import ( "os/exec" "path" "path/filepath" - "regexp" "runtime" "strconv" "testing" @@ -44,13 +43,6 @@ func TestStatFS(t *testing.T) { RunTests(t) } // system's. The output is not guaranteed to have resolution greater than 2^10 // (1 KiB). func df(dir string) (capacity, used, available uint64, err error) { - // Sample output: - // - // Filesystem 1024-blocks Used Available Capacity iused ifree %iused Mounted on - // fake@bucket 32 16 16 50% 0 0 100% /Users/jacobsa/tmp/mp - // - re := regexp.MustCompile(`^\S+\s+(\d+)\s+(\d+)\s+(\d+)\s+\d+%\s+\d+\s+\d+\s+\d+%.*$`) - // Call df with a block size of 1024 and capture its output. cmd := exec.Command("df", dir) cmd.Env = []string{"BLOCKSIZE=1024"} @@ -67,7 +59,7 @@ func df(dir string) (capacity, used, available uint64, err error) { continue } - submatches := re.FindSubmatch(line) + submatches := gDfOutputRegexp.FindSubmatch(line) if submatches == nil { err = fmt.Errorf("Unable to parse line: %q", line) return