From 00c289b25035faa590fe44bd8ce0b748ccd2ba82 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Mon, 27 May 2013 05:59:52 -0400 Subject: Implement a proper unit testing framework. --- (limited to 'tests') 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} +} -- cgit v0.9.1