#!/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 test whether tigger-add handles a large number # of filenames. Also tests tigger-status against a new, uncommitted repo. assert_good_exec "./tigger-init" filenames=$(seq 20) printf "adding large number of files...\n" for filename in $filenames; do touch "$filename" > /dev/null assert_good_exec "./tigger-add $filename" > /dev/null done # Test the length of tigger-status. printf "testing tigger-status line count\n" if [ "$(./tigger-status | wc --line)" -ge 100 ]; then printf "bad tigger status line count\n" >&2 exit 1 fi # Test teardown/cleanup printf "\ntest completed successfully\n" rm -rf ../"$tmp_dir" exit 0