source ./utils
setup trap cleanup EXIT
HERE=$PWD
for i in $@; do
[ $i = '-v' ] && VERBOSE=true
[[ "$i" =~ [0-9]+ ]] && [ -z $ONE_TEST ] && printf -v ONE_TEST "%02d" $i
done
N=0 let PASSES=0
let TOTAL=0
init() {
local tmp_dir=$HERE/tmp/$N
mkdir -p $tmp_dir && _pushd $tmp_dir
_git init
let local i=1
while [ $i -le $1 ]; do
touch "file_$i"
let i++
done
}
log() {
eval "$@" >$REC_DIR/$N.txt
}
reset_dir() {
_popd
assert $PWD $HERE
}
test() {
[ ! -f $1 ] && echo "No such test file" && return
let TOTAL++
N=$(get_test_id $1)
source $1
local title=$(get_test_title $1) && local file=${1##$HERE/}
local rec=$HERE/received/$N.txt && local exp=$HERE/expected/$N.txt
local ok=1
[ ! -f $rec ] && not_found $file received/$N.txt && ok=0
[ ! -f $exp ] && not_found $file expected/$N.txt && ok=0
if [ $ok = 0 ]; then
[ -f $rec ] && cat $rec
reset_dir
return
fi
local DIFF=$(diff $rec $exp)
if [[ -z $DIFF ]]; then
pass $file "$title"
let PASSES++
else
fail $file "$title"
echo "<: received, >: expected"
echo "$DIFF"
fi
[ $VERBOSE ] && cat $rec
reset_dir
}
main() {
cargo build --quiet || exit 1
if ! command -v gitnu >/dev/null; then
echo 'gitnu not found. Aborting.'
fi
if [ $ONE_TEST ]; then
test $HERE/tests/$ONE_TEST.sh
else
for t in $HERE/tests/*; do
test "$t"
done
fi
printf "\n $PASSES/$TOTAL tests passed\n"
[ $PASSES = $TOTAL ] && [ $TOTAL -gt 0 ] && exit 0 || exit 1
}
main