X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/7c7ba2aaa02381088315d7ab1c9d9de6afbd5458..b317b99dd61e3a00721c8e29c911b6621a275bc6:/mdup-test.sh diff --git a/mdup-test.sh b/mdup-test.sh new file mode 100755 index 0000000..1b34916 --- /dev/null +++ b/mdup-test.sh @@ -0,0 +1,66 @@ +#! /bin/sh + +set -e +: ${test=./mdup.t} +cases= + +###-------------------------------------------------------------------------- +### Set up the test cases. +### +### The mdup-test program takes a command-line representation of an mdup_fd +### array, calls mdup, and checks the result. In particular, it ensures that +### the file descriptors returned are the ones asked for, and that the +### resulting file descriptors actually correspond to the requested files. +### (It does the latter by comparing inodes before and after.) + +## Very simple tests. +cases="$cases 3:4" +cases="$cases 4:3" + +## Overlapping sources and destinations. +cases="$cases 4:3,3:5,5:6" + +## Repeated sources. +cases="$cases 3:4,3:3,3:-1" +cases="$cases 5:8,3:4,3:5,4:6" + +## Cycles. +cases="$cases 5:7,3:4,3:5,4:6,5:3" +cases="$cases 5:8,3:4,3:5,4:6,5:3" + +###-------------------------------------------------------------------------- +### Actually run the tests. + +## Initialize counters. +win=0 +lose=0 +total=0 + +## Run the tests. +for case in $cases; do + total=$(expr $total + 1) + case=$(echo "$case" | sed 'y/,/ /') + printf "%d: %-60s " $total "$case" + if $test $case >mdup.$total.out 2>mdup.$total.err; then + echo "ok" + win=$(expr $win + 1) + rm mdup.$total.out mdup.$total.err + else + echo "FAIL" + lose=$(expr $lose + 1) + fi +done + +## Announce the outcome. +if [ $win = $total ]; then + echo "All $total tests successful." + rc=0 +else + echo "FAILED $lose of $total tests." + rc=1 +fi + +## And exit. +exit $rc + +###----- That's all, folks --------------------------------------------------