#!/usr/bin/env bash
# Usage: script/test
#
# Run Go and Cucumber test suites for hub.

set -e

case "$1" in
"" )
  ;;
-h | --help )
  sed -ne '/^#/!q;s/.\{1,2\}//;1d;p' < "$0"
  exit
  ;;
* )
  "$0" --help >&2
  exit 1
esac

STATUS=0

trap "exit 1" INT

script/build
script/build test || STATUS="$?"
script/ruby-test || STATUS="$?"

if [ -n "$CI" ]; then
  make fmt >/dev/null
  if ! git diff -U1 --exit-code; then
    STATUS=1
    echo
    echo "Some go code was not formatted properly." >&2
    echo "Run \`make fmt' locally to fix these errors." >&2
  fi
fi

exit "$STATUS"
