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