#!/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 creating a new branch from an empty # branch branches with multiple files with multiple commits and then deleting # the branch results in the same status as an empty branch. # TODO CURRENTLY DOESNT FUNCTION BECAUSE CHECKOUT IS WRONG IN MY IMPLEMENTATION! printf "WARNING: DOESN'T FUNCTION DUE TO NON FULLY IMPLEMENTED CHECKOUT\n\n" assert_good_exec "./tigger-init" touch z assert_good_exec "./tigger-add z" assert_good_exec "./tigger-commit -m commitmessage" before_status=$(./tigger-status) assert_good_exec "./tigger-branch new" assert_good_exec "./tigger-checkout new" touch a touch b assert_good_exec "./tigger-add a b" assert_good_exec "./tigger-commit -m commitmessage" touch c touch d assert_good_exec "./tigger-add c d" assert_good_exec "./tigger-commit -m commitmessage" assert_good_exec "./tigger-checkout master" assert_good_exec "./tigger-branch -d new" printf "testing tigger status is the same as before the branch was created\n" if [ "$(./tigger-status)" != "$before_status" ]; then printf "tigger-status was not empty in an empty dir\n" >&2 exit 1 fi # Test teardown/cleanup printf "\ntest completed successfully\n" rm -rf ../"$tmp_dir" exit 0