aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-08-09 15:38:23 +1200
committerTom Ryder <tom@sanctum.geek.nz>2017-08-09 15:43:13 +1200
commitcdbb04af38341299cb04f744555d782b0ab33ae3 (patch)
tree4b9cdd6d9e5aca59ab3326611604c72c480d63ba
parentCategorise missing arg as usage error (diff)
downloadcheckem-cdbb04af38341299cb04f744555d782b0ab33ae3.tar.gz (sig)
checkem-cdbb04af38341299cb04f744555d782b0ab33ae3.zip
Add janky test suitev2.6
-rw-r--r--Makefile4
-rw-r--r--README.markdown4
-rwxr-xr-xcheckem2
-rw-r--r--test.sh201
4 files changed, 209 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index ffe5b39..4760795 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,11 @@
.POSIX:
.SUFFIXES:
-.PHONY: all install clean
+.PHONY: all install test clean
PREFIX = /usr/local
all:
install:
mkdir -p -- $(PREFIX)/bin
cp -- checkem $(PREFIX)/bin
+test:
+ sh test.sh
clean:
diff --git a/README.markdown b/README.markdown
index 28cb8e1..2448d39 100644
--- a/README.markdown
+++ b/README.markdown
@@ -20,6 +20,10 @@ You can define a `PREFIX` to install it elsewhere:
$ make install PREFIX="$HOME"/.local
+There's a (presently) very basic test suite:
+
+ $ make test
+
Q&A
---
diff --git a/checkem b/checkem
index 2181fca..eba215c 100755
--- a/checkem
+++ b/checkem
@@ -24,7 +24,7 @@ use Digest::SHA;
use 5.009003;
# Version number to make Perl::Critic happy
-our $VERSION = 2.5;
+our $VERSION = 2.6;
# If no arguments, work with the current working directory
if ( !@ARGV ) {
diff --git a/test.sh b/test.sh
new file mode 100644
index 0000000..950910c
--- /dev/null
+++ b/test.sh
@@ -0,0 +1,201 @@
+# Janky and presently very threadbare test suite for checkem
+
+# This won't pass on operating systems or filesystems that don't support
+# symbolic and hard links.
+
+# Create a temporary directory for the tests
+td=
+td=$(mktemp -d) || exit
+out=$td/out err=$td/err
+touch -- "$out" "$err" || exit
+
+# Create a subdir for test input files
+mkdir -- "$td"/t
+
+# Start counting failures
+f=0
+
+# 1: Errors out when run with no arguments
+./checkem >"$out" 2>"$err"
+ret=$?
+case $ret in
+ 2) ;;
+ *)
+ printf >&2 '1a: Expected exit value of 2, got %d\n' "$ret"
+ f=$((f+1))
+ ;;
+esac
+if [ -s "$out" ] ; then
+ printf >&2 '1b: Unexpected stdout (%u bytes):\n' "$(wc -c "$out")"
+ cat -- "$out"
+ f=$((f+1))
+fi
+if ! [ -s "$err" ] ; then
+ printf >&2 '1c: Expected message on stderr, got none\n'
+ f=$((f+1))
+fi
+
+# 2: Ignores two different files of different size
+printf 'foo\n' > "$td"/t/a
+printf 'barbar\n' > "$td"/t/b
+./checkem "$td"/t >"$out" 2>"$err"
+ret=$?
+case $ret in
+ 0) ;;
+ *)
+ printf >&2 '2a: Expected exit value of 0, got %d\n' "$ret"
+ f=$((f+1))
+ ;;
+esac
+if [ -s "$out" ] ; then
+ printf >&2 '2b: Unexpected stdout (%u bytes):\n' "$(wc -c "$out")"
+ cat -- "$out"
+ f=$((f+1))
+fi
+if [ -s "$err" ] ; then
+ printf >&2 '2c: Unexpected stderr (%u bytes):\n' "$(wc -c "$err")"
+ cat -- "$err"
+ f=$((f+1))
+fi
+rm -- "${td:?}"/t/*
+
+# 3: Detects two identical files
+printf 'foo\n' > "$td"/t/a
+printf 'foo\n' > "$td"/t/b
+./checkem "$td"/t >"$out" 2>"$err"
+ret=$?
+case $ret in
+ 0) ;;
+ *)
+ printf >&2 '3a: Expected exit value of 0, got %d\n' "$ret"
+ f=$((f+1))
+ ;;
+esac
+if ! [ -s "$out" ] ; then
+ printf >&2 '3b: Empty stdout where output expected'
+ f=$((f+1))
+fi
+outl=$(sed '$=;d' "$out")
+if [ "$outl" -ne 3 ] ; then
+ printf >&2 '3c: Expected 3 lines of output, got %u\n' "$outl"
+ f=$((f+1))
+fi
+if [ -s "$err" ] ; then
+ printf >&2 '3d: Unexpected stderr (%u bytes):\n' "$(wc -c "$err")"
+ cat -- "$err"
+ f=$((f+1))
+fi
+rm -- "${td:?}"/t/*
+
+# 4: Skips symbolic links
+printf 'foo\n' > "$td"/t/a
+ln -s -- "$td"/t/a "$td"/t/b
+./checkem "$td"/t >"$out" 2>"$err"
+ret=$?
+case $ret in
+ 0) ;;
+ *)
+ printf >&2 '4a: Expected exit value of 0, got %d\n' "$ret"
+ f=$((f+1))
+ ;;
+esac
+if [ -s "$out" ] ; then
+ printf >&2 '4b: Unexpected stdout (%u bytes):\n' "$(wc -c "$out")"
+ cat -- "$out"
+ f=$((f+1))
+fi
+if [ -s "$err" ] ; then
+ printf >&2 '4c: Unexpected stderr (%u bytes):\n' "$(wc -c "$err")"
+ cat -- "$err"
+ f=$((f+1))
+fi
+rm -- "${td:?}"/t/*
+
+# 5: Skips hard links
+printf 'foo\n' > "$td"/t/a
+ln -- "$td"/t/a "$td"/t/b
+./checkem "$td"/t >"$out" 2>"$err"
+ret=$?
+case $ret in
+ 0) ;;
+ *)
+ printf >&2 '5a: Expected exit value of 0, got %d\n' "$ret"
+ f=$((f+1))
+ ;;
+esac
+if [ -s "$out" ] ; then
+ printf >&2 '5b: Unexpected stdout (%u bytes):\n' "$(wc -c "$out")"
+ cat -- "$out"
+ f=$((f+1))
+fi
+if [ -s "$err" ] ; then
+ printf >&2 '5c: Unexpected stderr (%u bytes):\n' "$(wc -c "$err")"
+ cat -- "$err"
+ f=$((f+1))
+fi
+rm -- "${td:?}"/t/*
+
+# 6: Ignores two different files of the same size
+printf 'foo\n' > "$td"/t/a
+printf 'bar\n' > "$td"/t/b
+./checkem "$td"/t >"$out" 6>"$err"
+ret=$?
+case $ret in
+ 0) ;;
+ *)
+ printf >&2 '6a: Expected exit value of 0, got %d\n' "$ret"
+ f=$((f+1))
+ ;;
+esac
+if [ -s "$out" ] ; then
+ printf >&2 '6b: Unexpected stdout (%u bytes):\n' "$(wc -c "$out")"
+ cat -- "$out"
+ f=$((f+1))
+fi
+if [ -s "$err" ] ; then
+ printf >&2 '6c: Unexpected stderr (%u bytes):\n' "$(wc -c "$err")"
+ cat -- "$err"
+ f=$((f+1))
+fi
+rm -- "${td:?}"/t/*
+
+# 7: Detects two identical files in different specified directories
+mkdir -- "$td"/t/a "$td"/t/b
+printf 'foo\n' > "$td"/t/a/a
+printf 'foo\n' > "$td"/t/b/b
+./checkem "$td"/t/[ab] >"$out" 2>"$err"
+ret=$?
+case $ret in
+ 0) ;;
+ *)
+ printf >&2 '7a: Expected exit value of 0, got %d\n' "$ret"
+ f=$((f+1))
+ ;;
+esac
+if ! [ -s "$out" ] ; then
+ printf >&2 '7b: Empty stdout where output expected'
+ f=$((f+1))
+fi
+outl=$(sed '$=;d' "$out")
+if [ "$outl" -ne 3 ] ; then
+ printf >&2 '7c: Expected 3 lines of output, got %u\n' "$outl"
+ f=$((f+1))
+fi
+if [ -s "$err" ] ; then
+ printf >&2 '7d: Unexpected stderr (%u bytes):\n' "$(wc -c "$err")"
+ cat -- "$err"
+ f=$((f+1))
+fi
+rm -- "${td:?}"/t/[ab]/*
+rmdir -- "${td:?}"/t/[ab]
+
+# Clean up
+rmdir -- "${td:?}"/t
+rm -- "${td:?}"/*
+rmdir -- "$td"
+
+# Report
+if [ "$f" -gt 0 ] ; then
+ printf >&2 '%u tests failed\n' "$f"
+ exit 1
+fi