diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-08-21 20:19:18 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-08-21 20:19:18 +0200 |
commit | f3ed56cfb6d60a03aeef6914eb76911790b08a21 (patch) | |
tree | 4b483073e80b397b35f2a0dcd617b461634586c2 | |
parent | e8269dc42cceedd2e82ebf860b1f3fa8a8b69ded (diff) | |
download | holes-f3ed56cfb6d60a03aeef6914eb76911790b08a21.tar.gz holes-f3ed56cfb6d60a03aeef6914eb76911790b08a21.tar.xz holes-f3ed56cfb6d60a03aeef6914eb76911790b08a21.zip |
add small test suite
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | tests | 68 |
2 files changed, 71 insertions, 0 deletions
diff --git a/Makefile b/Makefile index 7807575..a7414bd 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,9 @@ README: holes.1 clean: FRC rm -f $(ALL) +check: FRC all + prove -v ./tests + install: FRC all mkdir -p $(DESTDIR)$(BINDIR) $(DESTDIR)$(MANDIR)/man1 install -m0755 $(ALL) $(DESTDIR)$(BINDIR) diff --git a/tests b/tests new file mode 100644 index 0000000..4d8ae26 --- /dev/null +++ b/tests @@ -0,0 +1,68 @@ +#!/bin/sh +printf '1..10\n' + +set -e + +holes() { "${HOLES:-./holes}" "$@"; } + +zeroes() { dd if=/dev/zero bs=${2:-1} count=$1 2>/dev/null; } +nonzeroes() { zeroes $1 $2 | tr '\0' x; } + +check_output() { + msg=$1 + expected="$(cat)" + shift + if output="$(eval "$@" 2>&1)"; then + if [ "$output" = "$expected" ]; then + printf 'ok - %s\n' "$msg" + return + fi + fi + printf 'not ok - %s\n' "$msg" + if [ "$output" != "$expected" ]; then + printf 'Unexpected output:\n%s\n' "$output" | sed 's/^/# /' + fi +} + +check_output 'no hole' 'echo foobar | holes' <<EOF +EOF + +check_output 'big, no hole' 'nonzeroes 1 M | holes' <<EOF +EOF + +check_output 'empty file' 'true | holes' <<EOF +00000000 0 +EOF + +check_output 'small holes' '{ nonzeroes 17; zeroes 35; nonzeroes 67; zeroes 67; } | holes -n1' <<EOF +00000011 35 +00000077 67 +EOF + +check_output 'small, undetected holes' '{ nonzeroes 17; zeroes 35; nonzeroes 67; zeroes 63; } | holes' <<EOF +EOF + +check_output 'medium holes' '{ zeroes 4 1k; nonzeroes 60 1k; zeroes 300 1k; nonzeroes 7 1k; } | holes' <<EOF +00000000 4096 +00010000 307200 +EOF + +check_output 'medium, offsetted holes' '{ zeroes 4090; nonzeroes 60 1k; zeroes 307117; nonzeroes 7 1k; } | holes' <<EOF +00000000 4090 +0000fffa 307117 +EOF + +check_output 'huge holes' '{ zeroes 5 M; nonzeroes 7 M; zeroes 7 M; } | holes' <<EOF +00000000 5242880 +00c00000 7340032 +EOF + +check_output 'huge, offsetted holes' '{ nonzeroes 3636; zeroes 5 M; nonzeroes 7 M; zeroes 7 M; } | holes' <<EOF +00000e34 5242880 +00c00e34 7340032 +EOF + +check_output 'detect non-zeroes' '{ nonzeroes 3636; zeroes 5 M; nonzeroes 7 M; zeroes 7 M; } | tr "\\0" "\\377" | holes -b 0xff' <<EOF +00000e34 5242880 +00c00e34 7340032 +EOF |