From f3ed56cfb6d60a03aeef6914eb76911790b08a21 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Mon, 21 Aug 2017 20:19:18 +0200 Subject: add small test suite --- Makefile | 3 +++ tests | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 tests 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' <