sparseutils

utilities for interacting with sparse files
Log | Files | Refs | README | LICENSE

commit 0d479abebe09253e8fbc24a5d16a57ee636a7e19
parent bf541343ecc270e0e24ce7f7807a8f67da83dad3
Author: Richard Ipsum <richardipsum@fastmail.co.uk>
Date:   Sun,  2 Apr 2017 13:34:28 +0100

Add some cli regression tests

Also move the tests from a directory named 'yarn' to a directory named 'test'.

Diffstat:
Mcheck | 7++++---
Atests/implementations.yarn | 28++++++++++++++++++++++++++++
Atests/mksparse.yarn | 17+++++++++++++++++
Atests/shell_lib | 9+++++++++
Atests/sparsemap.yarn | 75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Dyarns/implementations.yarn | 9---------
Dyarns/shell_lib | 5-----
Dyarns/sparsemap.yarn | 65-----------------------------------------------------------------
8 files changed, 133 insertions(+), 82 deletions(-)

diff --git a/check b/check @@ -3,10 +3,11 @@ set -e set -u +# psst: --snapshot is your friend if you're debugging the tests + run_yarn_suite() { - PATH="$(realpath $(dirname check)):$PATH" yarn yarns/sparsemap.yarn \ - yarns/implementations.yarn --stop-on-first-fail -s yarns/shell_lib \ - --snapshot --shell='/bin/bash' "$@" + PATH="$(realpath $(dirname check)):$PATH" yarn tests/*.yarn \ + --stop-on-first-fail -s tests/shell_lib --shell='/bin/bash' "$@" } run_yarn_suite "$@" diff --git a/tests/implementations.yarn b/tests/implementations.yarn @@ -0,0 +1,28 @@ + IMPLEMENTS GIVEN a sparse file (\S+) with a hole size (\d+) and data size (\d+) with spec ([a-zA-z,]+) + set -e -o pipefail + echo "$MATCH_4" | mksparse "$DATADIR/$MATCH_1" --hole-size "$MATCH_2" --data-size "$MATCH_3" + + IMPLEMENTS WHEN we run sparsemap on (\w+) + run_sparsemap "$DATADIR/$MATCH_1" + + IMPLEMENTS WHEN we attempt to run (\w+) without any arguments + set +e + eval run_$MATCH_1 + echo $? > "$DATADIR/EXITCODE" + set -e + + IMPLEMENTS WHEN we attempt to run (\w+) (?:on|with) (.+) + set +e + eval run_$MATCH_1 "$DATADIR/$MATCH_2" + echo $? > "$DATADIR/EXITCODE" + set -e + + IMPLEMENTS THEN the exit code is (\d+) + exit_code=$(cat "$DATADIR/EXITCODE") + [[ $exit_code -eq $MATCH_1 ]] + + IMPLEMENTS THEN stderr contains '(.+)' + grep -i "$MATCH_1" "$DATADIR/STDERR" + + IMPLEMENTS THEN stdout contains exactly (.+) + diff -u <(echo -e "$MATCH_1") "$DATADIR/STDOUT" diff --git a/tests/mksparse.yarn b/tests/mksparse.yarn @@ -0,0 +1,17 @@ +mksparse tests +============== + +mksparse is mostly tested by the sparsemap tests, but these yarns +will just make sure that basic command line handling is working. + + SCENARIO error if no output file + WHEN we attempt to run mksparse without any arguments + THEN the exit code is 2 + + SCENARIO error if more than one output file + WHEN we attempt to run mksparse with S T + THEN the exit code is 2 + + SCENARIO error if bad options + WHEN we attempt to run mksparse with --explode-kittens S + THEN the exit code is 2 diff --git a/tests/shell_lib b/tests/shell_lib @@ -0,0 +1,9 @@ +set -e -u -o pipefail + +run_sparsemap() { + sparsemap $@ > "$DATADIR/STDOUT" +} + +run_mksparse() { + mksparse $@ > "$DATADIR/STDOUT" +} diff --git a/tests/sparsemap.yarn b/tests/sparsemap.yarn @@ -0,0 +1,75 @@ +sparsemap tests +=============== + +Please note that these tests will depend very much on the file +system, it is up to the file system to decide how many zeroes +are required before it decides to represent the hole as an actual +hole rather than just a run of zeroes. + +At time of writing (2017) these tests pass on ext4, +where the default block size is 4096 bytes. + + SCENARIO sparsemap single data followed by single hole + GIVEN a sparse file S with a hole size 4096 and data size 8192 with spec data,hole + WHEN we run sparsemap on S + THEN stdout contains exactly DATA 8192\nHOLE 4096 + + SCENARIO sparsemap single hole followed by single data + GIVEN a sparse file S with a hole size 4096 and data size 8192 with spec hole,data + WHEN we run sparsemap on S + THEN stdout contains exactly HOLE 4096\nDATA 8192 + + SCENARIO sparsemap hole followed by data followed by hole + GIVEN a sparse file S with a hole size 8192 and data size 4096 with spec hole,data,hole + WHEN we run sparsemap on S + THEN stdout contains exactly HOLE 8192\nDATA 4096\nHOLE 8192 + + SCENARIO tiny hole can look like data + GIVEN a sparse file S with a hole size 6 and data size 4096 with spec hole,data,hole + WHEN we run sparsemap on S + THEN stdout contains exactly DATA 4108 + + SCENARIO sparsemap data followed by hole followed by data + GIVEN a sparse file S with a hole size 8192 and data size 4096 with spec data,hole,data + WHEN we run sparsemap on S + THEN stdout contains exactly DATA 4096\nHOLE 8192\nDATA 4096 + + SCENARIO sparsemap sequence of holes + GIVEN a sparse file S with a hole size 4096 and data size 8192 with spec data,hole,hole,data + WHEN we run sparsemap on S + THEN stdout contains exactly DATA 8192\nHOLE 8192\nDATA 8192 + + SCENARIO sparsemap sequence of holes (ending with hole) + GIVEN a sparse file S with a hole size 8192 and data size 4096 with spec data,hole,hole,hole + WHEN we run sparsemap on S + THEN stdout contains exactly DATA 4096\nHOLE 24576 + + SCENARIO sparsemap file with only data + GIVEN a sparse file S with a hole size 8192 and data size 4096 with spec data + WHEN we run sparsemap on S + THEN stdout contains exactly DATA 4096 + + SCENARIO sparsemap file with only hole + GIVEN a sparse file S with a hole size 8192 and data size 4096 with spec hole + WHEN we run sparsemap on S + THEN stdout contains exactly HOLE 8192 + + SCENARIO sparsemap file with data,hole,data,hole,data + GIVEN a sparse file S with a hole size 8192 and data size 4096 with spec data,hole,data,hole,data + WHEN we run sparsemap on S + THEN stdout contains exactly DATA 4096\nHOLE 8192\nDATA 4096\nHOLE 8192\nDATA 4096 + + SCENARIO sparsemap file with hole,data,hole,data,hole + GIVEN a sparse file S with a hole size 8192 and data size 4096 with spec hole,data,hole,data,hole + WHEN we run sparsemap on S + THEN stdout contains exactly HOLE 8192\nDATA 4096\nHOLE 8192\nDATA 4096\nHOLE 8192 + +Generic commandline handling stuff, + + SCENARIO sparsemap errs on no FILE arg + WHEN we attempt to run sparsemap without any arguments + THEN the exit code is 2 + + SCENARIO sparsemap errs if more than one arg + WHEN we attempt to run sparsemap on S T + THEN the exit code is 2 diff --git a/yarns/implementations.yarn b/yarns/implementations.yarn @@ -1,9 +0,0 @@ - IMPLEMENTS GIVEN a sparse file (\S+) with a hole size (\d+) and data size (\d+) with spec ([a-zA-z,]+) - set -e -o pipefail - echo "$MATCH_4" | mksparse "$DATADIR/$MATCH_1" --hole-size "$MATCH_2" --data-size "$MATCH_3" - - IMPLEMENTS WHEN we run sparsemap on (\w+) - run_sparsemap "$DATADIR/$MATCH_1" - - IMPLEMENTS THEN stdout contains exactly (.+) - diff -u <(echo -e "$MATCH_1") "$DATADIR/STDOUT" diff --git a/yarns/shell_lib b/yarns/shell_lib @@ -1,5 +0,0 @@ -set -e -u -o pipefail - -run_sparsemap() { - sparsemap $@ > "$DATADIR/STDOUT" -} diff --git a/yarns/sparsemap.yarn b/yarns/sparsemap.yarn @@ -1,65 +0,0 @@ -sparse map tests -================ - -Please note that these tests will depend very much on the file -system, it is up to the file system to decide how many zeroes -are required before it decides to represent the hole as an actual -hole rather than just a run of zeroes. - -At time of writing (2017) these tests pass on ext4, -where the default block size is 4096 bytes. - - SCENARIO sparsemap single data followed by single hole - GIVEN a sparse file S with a hole size 4096 and data size 8192 with spec data,hole - WHEN we run sparsemap on S - THEN stdout contains exactly DATA 8192\nHOLE 4096 - - SCENARIO sparsemap single hole followed by single data - GIVEN a sparse file S with a hole size 4096 and data size 8192 with spec hole,data - WHEN we run sparsemap on S - THEN stdout contains exactly HOLE 4096\nDATA 8192 - - SCENARIO sparsemap hole followed by data followed by hole - GIVEN a sparse file S with a hole size 8192 and data size 4096 with spec hole,data,hole - WHEN we run sparsemap on S - THEN stdout contains exactly HOLE 8192\nDATA 4096\nHOLE 8192 - - SCENARIO tiny hole can look like data - GIVEN a sparse file S with a hole size 6 and data size 4096 with spec hole,data,hole - WHEN we run sparsemap on S - THEN stdout contains exactly DATA 4108 - - SCENARIO sparsemap data followed by hole followed by data - GIVEN a sparse file S with a hole size 8192 and data size 4096 with spec data,hole,data - WHEN we run sparsemap on S - THEN stdout contains exactly DATA 4096\nHOLE 8192\nDATA 4096 - - SCENARIO sparsemap sequence of holes - GIVEN a sparse file S with a hole size 4096 and data size 8192 with spec data,hole,hole,data - WHEN we run sparsemap on S - THEN stdout contains exactly DATA 8192\nHOLE 8192\nDATA 8192 - - SCENARIO sparsemap sequence of holes (ending with hole) - GIVEN a sparse file S with a hole size 8192 and data size 4096 with spec data,hole,hole,hole - WHEN we run sparsemap on S - THEN stdout contains exactly DATA 4096\nHOLE 24576 - - SCENARIO sparsemap file with only data - GIVEN a sparse file S with a hole size 8192 and data size 4096 with spec data - WHEN we run sparsemap on S - THEN stdout contains exactly DATA 4096 - - SCENARIO sparsemap file with only hole - GIVEN a sparse file S with a hole size 8192 and data size 4096 with spec hole - WHEN we run sparsemap on S - THEN stdout contains exactly HOLE 8192 - - SCENARIO sparsemap file with data,hole,data,hole,data - GIVEN a sparse file S with a hole size 8192 and data size 4096 with spec data,hole,data,hole,data - WHEN we run sparsemap on S - THEN stdout contains exactly DATA 4096\nHOLE 8192\nDATA 4096\nHOLE 8192\nDATA 4096 - - SCENARIO sparsemap file with hole,data,hole,data,hole - GIVEN a sparse file S with a hole size 8192 and data size 4096 with spec hole,data,hole,data,hole - WHEN we run sparsemap on S - THEN stdout contains exactly HOLE 8192\nDATA 4096\nHOLE 8192\nDATA 4096\nHOLE 8192