test 1.4 KB
Newer Older
J
Jingwen Owen Ou 已提交
1
#!/usr/bin/env bash
2
# Usage: script/test [--coverage [<MIN>]] [<FEATURES>...]
J
Jingwen Owen Ou 已提交
3
#
4 5 6 7
# Run Go and Cucumber test suites for hub.

set -e

8 9 10 11
while [ $# -gt 0 ]; do
  case "$1" in
  --coverage )
    export HUB_COVERAGE="$PWD/tmp/cover.out"
12
    if [ "${2%.*}" -gt 0 ] 2>/dev/null; then
13 14 15 16 17 18 19 20 21 22 23 24
      min_coverage="$2"
      shift 2
    else
      min_coverage=1
      shift 1
    fi
    ;;
  -h | --help )
    sed -ne '/^#/!q;s/.\{1,2\}//;1d;p' < "$0"
    exit
    ;;
  * )
25 26
    break
    ;;
27 28
  esac
done
29 30 31 32 33

STATUS=0

trap "exit 1" INT

34
[ -z "$HUB_COVERAGE" ] || script/coverage prepare
35 36
script/build
script/build test || STATUS="$?"
37
script/ruby-test "$@" || STATUS="$?"
J
Jingwen Owen Ou 已提交
38

39 40 41
if [ -n "$HUB_COVERAGE" ]; then
  total_coverage="$(script/coverage generate)"
  echo "Code coverage: $total_coverage"
42 43
  result="$(bc <<<"${total_coverage%\%} < $min_coverage")"
  if [ "$result" -eq 1 ]; then
44 45 46 47 48 49 50 51 52 53
    echo "Error: coverage dropped below the minimum treshold of ${min_coverage}%!"
    if [ -n "$CI" ]; then
      html_result="${HUB_COVERAGE%.out}.html"
      html_result="${html_result#$PWD/}"
      printf 'Please run `script/test --coverage` locally and open `%s` to analyze the results.\n' "$html_result"
    fi
    STATUS=1
  fi
fi

54 55 56 57 58 59 60 61 62 63
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

64
exit "$STATUS"