summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2013-05-27 01:52:03 -0400
committerLuke Shumaker <LukeShu@sbcglobal.net>2013-05-27 01:52:03 -0400
commit4e36277689f92772e474c0829cb7f517aa06d58d (patch)
treea56e6d6c8185a5bd0a1626782b502f98060090db
parentb0b29df10764cecee365815476d83641e668b408 (diff)
add (some) unit tests for librelib and libremessages
-rw-r--r--test/librelib-test.sh72
-rw-r--r--test/libremessages-test.sh45
2 files changed, 117 insertions, 0 deletions
diff --git a/test/librelib-test.sh b/test/librelib-test.sh
new file mode 100644
index 0000000..36ba947
--- /dev/null
+++ b/test/librelib-test.sh
@@ -0,0 +1,72 @@
+#!/usr/bin/env roundup
+
+describe librelib
+
+before() {
+ tmpdir=$(mktemp -d --tmpdir test-librelib.XXXXXXXXXXXX)
+}
+
+after() {
+ rm -rf -- "$tmpdir"
+}
+
+
+it_fails_with_0_args() {
+ ret=0
+ librelib >$tmpdir/stdout 2>$tmpdir/stderr || ret=$?
+
+ [[ -z "$(cat $tmpdir/stdout)" ]]
+ [[ -n "$(cat $tmpdir/stderr)" ]]
+ [[ $ret != 0 ]]
+}
+
+it_fails_with_2_args() {
+ ret=0
+ librelib a b >$tmpdir/stdout 2>$tmpdir/stderr || ret=$?
+
+ [[ -z "$(cat $tmpdir/stdout)" ]]
+ [[ -n "$(cat $tmpdir/stderr)" ]]
+ [[ $ret != 0 ]]
+}
+
+it_displays_usage_text() {
+ librelib -h >$tmpdir/stdout 2>$tmpdir/stderr
+
+ [[ "$(sed 1q $tmpdir/stdout)" =~ Usage:.* ]]
+ [[ -z "$(cat $tmpdir/stderr)" ]]
+}
+
+# libremessages is executable
+it_finds_messages() {
+ v1=$(librelib messages)
+ v2=$(librelib libremessages)
+ v3=$(librelib messages.sh)
+ v4=$(librelib libremessages.sh)
+
+ [[ -x "$v1" ]]
+ [[ "$v1" == "$v2" ]]
+ [[ "$v1" == "$v3" ]]
+ [[ "$v1" == "$v4" ]]
+}
+
+# conf.sh is non-executable
+it_finds_conf() {
+ v1=$(librelib conf)
+ v2=$(librelib libreconf)
+ v3=$(librelib conf.sh)
+ v4=$(librelib libreconf.sh)
+
+ [[ -r "$v1" && ! -x "$v1" ]]
+ [[ "$v1" == "$v2" ]]
+ [[ "$v1" == "$v3" ]]
+ [[ "$v1" == "$v4" ]]
+}
+
+it_fails_to_find_phony() {
+ ret=0
+ librelib phony >$tmpdir/stdout 2>$tmpdir/stderr || ret=$?
+
+ [[ -z "$(cat $tmpdir/stdout)" ]]
+ [[ -z "$(cat $tmpdir/stderr)" ]]
+ [[ $ret != 0 ]]
+}
diff --git a/test/libremessages-test.sh b/test/libremessages-test.sh
new file mode 100644
index 0000000..6da53d1
--- /dev/null
+++ b/test/libremessages-test.sh
@@ -0,0 +1,45 @@
+#!/usr/bin/env roundup
+
+describe libremessages
+
+before() {
+ tmpdir=$(mktemp -d --tmpdir test-libremessages.XXXXXXXXXXXX)
+}
+
+after() {
+ rm -rf -- "$tmpdir"
+}
+
+it_can_be_included_twice() (
+ . libremessages
+ . libremessages
+)
+
+it_can_be_included_with_set_euE() (
+ set -euE
+ . libremessages
+)
+
+it_works_with_no_color_and_set_euE() (
+ unset TERM
+ set -euE
+ . libremessages
+
+ msg Foo >$tmpdir/stdout 2>$tmpdir/stderr
+
+ [[ -z "$(cat $tmpdir/stdout)" ]]
+ [[ -n "$(cat $tmpdir/stderr)" ]]
+)
+
+it_can_be_called_without_including() {
+ libremessages msg Foo >$tmpdir/stdout 2>$tmpdir/stderr
+
+ [[ -z "$(cat $tmpdir/stdout)" ]]
+ [[ -n "$(cat $tmpdir/stderr)" ]]
+}
+
+it_fails_with_msg_and_no_args() {
+ ret=0
+ libremessages msg || ret=$?
+ [[ $ret != 0 ]]
+}