streamly/bin/test.sh
Harendra Kumar 299bdffdd6 Add a script to run tests
This allows us to build and run individual tests or groups of tests. The
script is supposed to be extended to run hpc/coverage manually after
running the tests.

Note: cabal fails to run coverage if the test module is separated from
the library.
2020-12-28 23:56:18 +05:30

87 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
#------------------------------------------------------------------------------
# Script
#------------------------------------------------------------------------------
SCRIPT_DIR=$(dirname $0)
print_help () {
echo "Usage: $0 "
echo " [--targets <"target1 target2 ..." | help>]"
echo " [--slow]"
echo " [--quick]"
echo " [--cabal-build-options <option>]"
echo " -- <hspec options or test names>"
echo
echo "--targets: targets to run, use 'help' for list of targets"
echo "--slow: take longer but run more tests"
echo "--quick: faster but run fewer tests"
echo "--cabal-build-options: Pass any cabal build options to be used for build"
echo
echo "Any arguments after a '--' are passed directly to hspec"
exit
}
#-----------------------------------------------------------------------------
# Read command line
#-----------------------------------------------------------------------------
RUNNING_TESTS=y
source $SCRIPT_DIR/build-lib.sh
set_common_vars
# XXX add a bisect option
while test -n "$1"
do
case $1 in
-h|--help|help) print_help ;;
# options with arguments
--targets) shift; TARGETS=$1; shift ;;
--cabal-build-options) shift; CABAL_BUILD_OPTIONS=$1; shift ;;
--rtsopts) shift; RTS_OPTIONS=$1; shift ;;
# flags
--slow) SLOW=1; shift ;;
--quick) QUICK_MODE=1; shift ;;
--dev-build) RUNNING_DEVBUILD=1; shift ;;
--) shift; break ;;
-*|--*) echo "Unknown flags: $*"; echo; print_help ;;
*) break ;;
esac
done
TARGET_EXE_ARGS=$*
#-----------------------------------------------------------------------------
# Determine targets
#-----------------------------------------------------------------------------
# Requires RUNNING_DEVBUILD var
source $SCRIPT_DIR/targets.sh
if test "$(has_item "$TARGETS" help)" = "help"
then
list_target_groups
list_targets
exit
fi
DEFAULT_TARGETS="$(all_grp)"
TARGETS=$(set_targets)
echo "Using targets [$TARGETS]"
#-----------------------------------------------------------------------------
# Build targets
#-----------------------------------------------------------------------------
WHICH_COMMAND=cabal_which
BUILD_TEST="$CABAL_EXECUTABLE v2-build $CABAL_BUILD_OPTIONS --enable-tests"
run_build "$BUILD_TEST" streamly-tests test "$TARGETS"
#-----------------------------------------------------------------------------
# Run targets
#-----------------------------------------------------------------------------
run_targets streamly-tests "$TARGETS"