#!/usr/bin/env bash

# Run busted and collect spec coverage using LuaCov.
# Output will be found at /luacov.report.out.
#
# Usage:
#
#   $ ./bin/coverage
#   $ cat luacov.report.out

which luacov &> /dev/null

if [ $? -ne 0 ]; then
  echo "You must have luacov installed."
  echo "Run 'luarocks install luacov' then try again".
  exit 1
fi

which busted &> /dev/null

if [ $? -ne 0 ]; then
  echo "You must have luacov installed."
  echo "Run 'luarocks install busted' then try again".
  exit 1
fi

busted -c
luacov src/
rm luacov.stats.out
grep -zPo "(?s)={10,}\nSummary\n={10,}.+" luacov.report.out