summaryrefslogtreecommitdiff
path: root/test/test-common.sh
diff options
context:
space:
mode:
authorLuke Shumaker <LukeShu@sbcglobal.net>2013-06-04 22:02:21 -0600
committerLuke Shumaker <LukeShu@sbcglobal.net>2013-06-05 20:06:25 -0600
commita329839346a3c2c9591985b70841858dd575846f (patch)
treeb7cbde15e7e46d42726058b9e318ce6a8e85c29c /test/test-common.sh
parent695b9b8af8e2629d460d877abab4bdf216c71df2 (diff)
add a system to skip tests that require networking or sudo.
Diffstat (limited to 'test/test-common.sh')
-rw-r--r--test/test-common.sh29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/test-common.sh b/test/test-common.sh
new file mode 100644
index 0000000..e837498
--- /dev/null
+++ b/test/test-common.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+_before() {
+ tmpdir="$(mktemp -d --tmpdir "test-$1.XXXXXXXXXXXX")"
+ stat=0
+}
+
+_after() {
+ if [[ $SUDO ]]; then
+ sudo rm -rf -- "$tmpdir" "$XDG_CONFIG_HOME" "$XDG_CACHE_HOME"
+ else
+ rm -rf -- "$tmpdir" "$XDG_CONFIG_HOME" "$XDG_CACHE_HOME"
+ fi
+}
+
+require() {
+ local missing=()
+ if libremessages in_array "network" "$@" && ! [[ $NETWORK ]]; then
+ missing+=('networking')
+ fi
+ if libremessages in_array "sudo" "$@" && ! [[ $SUDO ]]; then
+ missing+=('sudo')
+ fi
+ if (( ${#missing[@]} )); then
+ libremessages warning "Next test requires %s; Skipping (passing)..." "$(echo "${missing[@]}"|sed 's/ /, /g')" &>/dev/tty
+ return 1
+ fi
+ return 0;
+}