summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsrc/lib/libreblacklist7
-rw-r--r--test/lib-blacklist-test.sh22
2 files changed, 28 insertions, 1 deletions
diff --git a/src/lib/libreblacklist b/src/lib/libreblacklist
index 6876a2b..1d73d2f 100755
--- a/src/lib/libreblacklist
+++ b/src/lib/libreblacklist
@@ -25,7 +25,7 @@ blacklist-normalize() {
}
# Usage: blacklist-cat
-# Prints the blacklist
+# Prints the blacklist.
# Uses the chache, but downloads it if it doesn't exist. Also normalizes the
# blacklist for easier parsing.
blacklist-cat() {
@@ -127,6 +127,11 @@ if [[ "${0##*/}" == libreblacklist ]]; then
done
fi
}
+
+ if [[ $# == 0 ]]; then
+ usage >/dev/stderr
+ exit 1
+ fi
_blacklist_cmd=$1
shift
if [[ $_blacklist_cmd == -h ]]; then
diff --git a/test/lib-blacklist-test.sh b/test/lib-blacklist-test.sh
index 3ac8e70..1432ff6 100644
--- a/test/lib-blacklist-test.sh
+++ b/test/lib-blacklist-test.sh
@@ -66,4 +66,26 @@ it_fails_cat_when_there_is_no_blacklist_or_network() {
[[ -n "$(cat $tmpdir/stderr)" ]]
}
+it_displays_help_and_fails_with_no_args() {
+ libreblacklist >$tmpdir/stdout 2>$tmpdir/stderr || stat=$?
+
+ [[ $stat != 0 ]]
+ [[ -z "$(cat $tmpdir/stdout)" ]]
+ [[ "$(sed 1q $tmpdir/stderr)" =~ 'Usage: libreblacklist ' ]]
+}
+
+it_displays_help_when_given_h() {
+ libreblacklist -h >$tmpdir/stdout 2>$tmpdir/stderr
+
+ [[ "$(sed 1q $tmpdir/stdout)" =~ 'Usage: libreblacklist ' ]]
+ [[ -z "$(cat $tmpdir/stderr)" ]]
+}
+
+it_displays_help_when_given_h_cat() {
+ libreblacklist -h cat >$tmpdir/stdout 2>$tmpdir/stderr
+
+ [[ "$(sed 1q $tmpdir/stdout)" =~ 'Usage: libreblacklist cat' ]]
+ [[ -z "$(cat $tmpdir/stderr)" ]]
+}
+
# TODO: test blacklist-update, but I don't want tests to use network