gitnu 0.1.4

gitnu indexes your git status so you can use numbers instead of filenames.
Documentation
#!/usr/bin/env bash
# vim:syntax=bash

source ./utils
setup # sets the current directory to this script's location
trap cleanup EXIT
HERE=$PWD

# parse arguments
for i in $@; do
  [ $i = '-v' ] && VERBOSE=true
  [[ "$i" =~ [0-9]+ ]] && [ -z $ONE_TEST ] && printf -v ONE_TEST "%02d" $i
done

N=0 # current test id
let PASSES=0
let TOTAL=0

# for use in ./tests/*.sh
# $1 is number of files to mock up
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
}

# for use in ./tests/*.sh
# evaluates command and sends to $REC_DIR
log() {
  eval "$@" >$REC_DIR/$N.txt
}

# return to original directory
reset_dir() {
  _popd
  assert $PWD $HERE
}

# $1 : aboslute path to ./tests/*.sh
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
  # either received/expected not found
  if [ $ok = 0 ]; then
    [ -f $rec ] && cat $rec
    reset_dir
    return
  fi

  # gather stats and diff
  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() {
  # build
  cargo build --quiet || exit 1

  # ensure correct binary is used
  if ! command -v gitnu >/dev/null; then
    echo 'gitnu not found. Aborting.'
  fi

  # run tests
  if [ $ONE_TEST ]; then
    # run one test
    test $HERE/tests/$ONE_TEST.sh
  else
    # run all tests
    for t in $HERE/tests/*; do
      test "$t"
    done
  fi

  # summarize
  printf "\n $PASSES/$TOTAL tests passed\n"
  [ $PASSES = $TOTAL ] && [ $TOTAL -gt 0 ] && exit 0 || exit 1
}

main