diff options
Diffstat (limited to 'comp2041/tigger/test02.sh')
| -rwxr-xr-x | comp2041/tigger/test02.sh | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/comp2041/tigger/test02.sh b/comp2041/tigger/test02.sh new file mode 100755 index 0000000..461da82 --- /dev/null +++ b/comp2041/tigger/test02.sh @@ -0,0 +1,73 @@ +#!/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 there are no arbitrary limits on +# the amount of times a command may be performed, and that file +# creation/deletion and increment logic is handled correctly between commits. +# It's possible that this fails due to bad increment handling at the radix +# point (if a program is implemented incorrectly). This test might also expose +# complexity issues if they are present. + +# Specifically we might use sort as opposed to sort -n, which works until 10. +# ... i did :( + +assert_good_exec "./tigger-init" +printf "adding and committing large number of files...\n" +for _ in $(seq 25); do + echo "repeated\n" >> repeated + assert_good_exec "./tigger-add repeated" > /dev/null + assert_good_exec "./tigger-commit -m placeholder" > /dev/null +done + +# Commit count should be 50 here! +printf "testing commit count string result\n" +printf "repeated\n" >> repeated +assert_good_exec "./tigger-add repeated" > /dev/null +if [ "$(./tigger-commit -m placeholder)" != "Committed as commit 25" ]; then + printf "bad commit count string\n" >&2 + exit 0 +fi + +# New one added so 26 now. +printf "testing tigger-log line count\n" +assert_good_exec "./tigger-log" > /dev/null +if [ "$(./tigger-log | wc --line)" -ne 26 ]; then + printf "bad tigger log string length\n" >&2 + exit 0 +fi + +# Test teardown/cleanup +printf "\ntest completed successfully\n" +rm -rf ../"$tmp_dir" +exit 0 |
