diff options
author | P. J. McDermott <pjm@nac.net> | 2013-05-27 05:59:52 (EDT) |
---|---|---|
committer | P. J. McDermott <pjm@nac.net> | 2013-05-27 05:59:52 (EDT) |
commit | 00c289b25035faa590fe44bd8ce0b748ccd2ba82 (patch) | |
tree | 2801422748d0dd54cbb13c3c8963fe42176e8de2 | |
parent | 6478b3434097adb88120b213528e04510c583521 (diff) |
Implement a proper unit testing framework.
-rw-r--r-- | Makefile.in | 35 | ||||
-rw-r--r-- | tests/testlib.sh | 40 |
2 files changed, 75 insertions, 0 deletions
diff --git a/Makefile.in b/Makefile.in index 08e0476..a13e63b 100644 --- a/Makefile.in +++ b/Makefile.in @@ -229,6 +229,41 @@ uninstall-archtab: @rmdir '$(DESTDIR)/$(archtabdir)' @rmdir '$(DESTDIR)/$(pkgdatadir)' +test: + @set -e; \ + mkdir -p tests; \ + cd tests; \ + . ./testlib.sh; \ + PATH="$${PATH}:$(DESTDIR)/$(bindir)"; \ + t_all=0; t_failed=0; \ + for t_test in $(tests); do \ + t_fail='false'; \ + . "$(srcdir)/$${t_test}" >out 2>&1; \ + if "$${t_fail}"; then \ + printf 'FAIL: %s\n' "$${t_test#tests/}"; \ + cat out | sed 's/^/ /'; \ + t_failed=$$(($$t_failed + 1)); \ + else \ + printf 'PASS: %s\n' "$${t_test#tests/}"; \ + fi; \ + t_all=$$(($$t_all + 1)); \ + rm out; \ + done; \ + t_banner="$$(printf '%d out of %d tests failed' \ + $${t_failed} $${t_all})"; \ + t_l=$$(printf '%s\n' "$${t_banner}" | wc -c); \ + t_i=1; while [ "$${t_i}" -lt "$${t_l}" ]; do \ + printf '='; \ + t_i=$$(($$t_i + 1)); \ + done; \ + printf '\n%s\n' "$${t_banner}"; \ + t_i=1; while [ "$${t_i}" -lt "$${t_l}" ]; do \ + printf '='; \ + t_i=$$(($$t_i + 1)); \ + done; \ + printf '\n'; \ + [ $${t_failed} -eq 0 ] + $(distdir): @mkdir -p '$(distdir)' @set -e; for f in $(distfiles); do \ diff --git a/tests/testlib.sh b/tests/testlib.sh new file mode 100644 index 0000000..d3fe350 --- /dev/null +++ b/tests/testlib.sh @@ -0,0 +1,40 @@ +assert() +{ + if ! t_out=$(eval 2>&1 "${@}"); then + printf 'Assertion failed: %s\n' "${*}" + printf '%s\n' "${t_out}" | sed 's/^/ /' + t_fail='true' + fi +} + +test_nodes() +{ + t_dir="${1}" + shift 1 + if [ ${#} -gt 0 ]; then + printf "${t_dir}%s\n" "${@}" | sort >expected + else + >expected + fi + find "${t_dir}" -exec ls -dF '{}' ';' | sort >actual + diff -u expected actual + t_ret=${?} + rm -f expected actual + return ${t_ret} +} + +test_non_dir_nodes() +{ + t_dir="${1}" + shift 1 + if [ ${#} -gt 0 ]; then + printf "${t_dir}%s\n" "${@}" | sort >expected + else + >expected + fi + find "${t_dir}" ! -type d | sort >actual + diff -u expected actual + t_ret=${?} + rm -f expected actual + return ${t_ret} +} |