From 98cef5e9a772602d42acfcf233838c760424db9a Mon Sep 17 00:00:00 2001 From: Nicolas James Date: Thu, 13 Feb 2025 18:00:17 +1100 Subject: initial commit --- comp2041/tigger/test00.sh | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 comp2041/tigger/test00.sh (limited to 'comp2041/tigger/test00.sh') diff --git a/comp2041/tigger/test00.sh b/comp2041/tigger/test00.sh new file mode 100755 index 0000000..b76f4a3 --- /dev/null +++ b/comp2041/tigger/test00.sh @@ -0,0 +1,58 @@ +#!/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 removing the expected .tigger +# folder does reset the state of tigger. In addition, there should be NO extra +# files at the end of this operation, even if it fails. We are only allowed to +# edit/create .tigger and what is inside .tigger! + +num_files_before=$(find ./ | wc -l) +assert_good_exec "./tigger-init" +num_files_after=$(find ./ | wc -l) +assert_bad_exec "./tigger-init" # should make no more files +if [ "$(find ./ | wc -l)" -ne "$num_files_after" ]; then + printf "the amount of files should be equal to before when tigger-init was called previously!\n" >&2 + exit 1 +fi +rm -rf ./.tigger +if [ "$(find ./ | wc -l)" -ne "$num_files_before" ]; then + printf "there should be the same amount as files as before any commands were run!\n" >&2 + exit 1 +fi +assert_good_exec "./tigger-init" + +# Test teardown/cleanup +printf "\ntest completed successfully\n" +rm -rf ../"$tmp_dir" +exit 0 -- cgit v1.2.3