blob: 733613c36f7d9cb44f927cc862436463b448edda (
plain) (
tree)
|
|
#!/bin/sh
TESTS_FAILED=0
ok() {
if ! test -t 1; then
printf 'ok - %s\n' "$*"
else
printf '\e[32mok\e[0m - %s\n' "$*"
fi
}
nok() {
TESTS_FAILED=$((TESTS_FAILED + 1))
if ! test -t 1; then
printf 'not ok - %s\n' "$*" >&2
else
printf '\e[31mnot ok\e[0m - %s\n' "$*" >&2
fi
}
header() {
printf '# %s\n' "$*"
}
info() {
printf '\n'
eval "$@"
printf '\n'
}
want() {
cat > want
}
assert_output_matches() {
msg=$1
if cmp have want >/dev/null 2>&1; then
ok "$msg"
return 0
else
nok "$msg"
info diff -u have want >&2
return 1
fi
}
assert() {
if test "$1" = "success"; then
assert_return=0
elif test "$1" = "failure"; then
assert_return=1
else
assert_return=$1
fi
shift
msg=$1
shift
eval "$@" > have 2>&1
if test "$?" -eq "$assert_return"; then
ok "$msg"
return 0
else
nok "$msg"
info cat have >&2
return 1
fi
}
end() {
test $TESTS_FAILED -gt 0 && exit $TESTS_FAILED
exit 0
}
have_dir() {
(cd "$BOSUN_DIR/.." && find . -printf '%y %p\n' | sed '/^..\.\/stow/d' | sort) > have
}
have_links() {
(cd "$BOSUN_DIR/.." && find . -type l -printf '%p -> %l\n' | sort) > have
}
|