diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testlib.sh | 40 |
1 files changed, 40 insertions, 0 deletions
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} +} |