aboutsummaryrefslogtreecommitdiff
path: root/comp2041/tigger/test09.sh
diff options
context:
space:
mode:
authorNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-13 18:00:17 +1100
committerNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-13 18:00:17 +1100
commit98cef5e9a772602d42acfcf233838c760424db9a (patch)
tree5277fa1d7cc0a69a0f166fcbf10fd320f345f049 /comp2041/tigger/test09.sh
initial commit
Diffstat (limited to 'comp2041/tigger/test09.sh')
-rwxr-xr-xcomp2041/tigger/test09.sh61
1 files changed, 61 insertions, 0 deletions
diff --git a/comp2041/tigger/test09.sh b/comp2041/tigger/test09.sh
new file mode 100755
index 0000000..6931de6
--- /dev/null
+++ b/comp2041/tigger/test09.sh
@@ -0,0 +1,61 @@
+#!/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 tigger-rm'ing a file can still be
+# retrieved later (provided it was in a different commit).
+assert_good_exec "./tigger-init"
+printf "contents" > a
+assert_good_exec "./tigger-add a"
+assert_good_exec "./tigger-commit -m commitmessage"
+assert_good_exec "./tigger-rm a"
+assert_good_exec "./tigger-commit -m commitmessage"
+
+# Ensure it was deleted.
+if [ -e a ]; then
+ printf "error: file was not deleted after git rm\n" >&2
+ exit 1
+fi
+
+# Ensure it can be later retrieved.
+assert_good_exec "./tigger-show 0:a"
+if [ "$(./tigger-show 0:a)" = "" ]; then
+ printf "error: file was not retrievable after git rm\n" >&2
+ exit 1
+fi
+
+
+# Test teardown/cleanup
+printf "\ntest completed successfully\n"
+rm -rf ../"$tmp_dir"
+exit 0