aboutsummaryrefslogtreecommitdiff
path: root/comp2041/tigger/test05.sh
diff options
context:
space:
mode:
Diffstat (limited to 'comp2041/tigger/test05.sh')
-rwxr-xr-xcomp2041/tigger/test05.sh46
1 files changed, 46 insertions, 0 deletions
diff --git a/comp2041/tigger/test05.sh b/comp2041/tigger/test05.sh
new file mode 100755
index 0000000..cc49cd1
--- /dev/null
+++ b/comp2041/tigger/test05.sh
@@ -0,0 +1,46 @@
+#!/bin/dash
+
+# Test startup, create a temporary directory and cd into it with files.
+tmp_dir=$(mktemp --directory --quiet --tmpdir=./)
+if [ "$(find tigger-* | wc -l)" -le 0 ]; then
+ printf "error: no tigger commands found, cannot run tests\n" >&2
+ exit 1
+fi
+cp tigger-* "$tmp_dir"/
+cd "$tmp_dir" || exit
+
+# Functions to test if the return value was 0 or non-zero.
+assert_good_exec () {
+ printf "%s: " "$1"
+ if $1; then
+ return
+ fi
+ printf "test failed, previous command expected zero output code\n" >&2
+ rm -rf ../"$tmp_dir"
+ exit 1
+}
+# Functions to test if the return value was 0 or non-zero.
+assert_bad_exec () {
+ printf "%s: " "$1"
+ if ! $1; then
+ return
+ fi
+ printf "test failed, previous command expected non-zero output code\n" >&2
+ rm -rf ../"$tmp_dir"
+ exit 1
+}
+printf "starting tests: output and order will be printed\n\n"
+# End of test startup
+
+# The purpose of this test is to ensure that adding a file with spacebars
+# results in an error. This is specified to not occur in the spec, but it should
+# still be handled correctly.
+
+assert_good_exec "./tigger-init"
+printf "placeholder contents" > "file name"
+assert_bad_exec "./tigger-add "file name""
+
+# Test teardown/cleanup
+printf "\ntest completed successfully\n"
+rm -rf ../"$tmp_dir"
+exit 0