summaryrefslogtreecommitdiff
path: root/test-common.sh
diff options
context:
space:
mode:
authorSilvan Jegen <s.jegen@gmail.com>2018-12-02 15:35:44 +0100
committerSilvan Jegen <s.jegen@gmail.com>2018-12-02 15:36:33 +0100
commit2a6c94abcb38a48f98c1393742a65232edc3c07f (patch)
treee3be321f2777ca5efe6b263ec31d264f957f2442 /test-common.sh
Initial commit
Diffstat (limited to 'test-common.sh')
-rw-r--r--test-common.sh42
1 files changed, 42 insertions, 0 deletions
diff --git a/test-common.sh b/test-common.sh
new file mode 100644
index 0000000..b1d7572
--- /dev/null
+++ b/test-common.sh
@@ -0,0 +1,42 @@
+check_output() {
+ testname=$1
+ cmdtorun=$2
+ expectedoutput=$3
+ usestdout=$4
+ expoutfile=$(mktemp)
+ actualoutfile=$(mktemp)
+ ret=0
+
+ printf "$expectedoutput" > $expoutfile
+ if [ $usestdout -eq 1 ]; then
+ eval $cmdtorun > $actualoutfile 2> /dev/null
+ else
+ eval $cmdtorun 2> $actualoutfile 1> /dev/null
+ fi
+
+ cmp $expoutfile $actualoutfile 2>&1 > /dev/null
+ if [ $? -eq 1 ]; then
+ printf "$testname:\n"
+ printf "\tWanted:\n"
+ cat $expoutfile
+ printf "\n\tGot:\n"
+ cat $actualoutfile
+ printf "\n\n"
+ ret=1
+ fi
+ if [ $? -eq 2 ]; then
+ printf "cmp error\n"
+ ret=1
+ fi
+
+ rm $expoutfile $actualoutfile
+ return $ret
+}
+
+check_stdout() {
+ check_output "$1" "$2" "$3" 1
+}
+
+check_stderr() {
+ check_output "$1" "$2" "$3" 0
+}