#!/bin/sh

# Either test the specified or all files.
if [ $# -eq 0 ]
    then test_files=`find apps test -type f -name '*_test.erl' 2>/dev/null`;
    else test_files=$@;
fi

if [[ ! -z $WITH_COVERAGE ]]
then
    # Create Coverage Folder
    mkdir -p coverage
fi

# Map test files to modules names.
modules=""
for file in $test_files
do
  modulename=`basename "$file" .erl`
  modules="$modulename $modules"
done

# Invoke runner, assuming all files have been compiled to `ebin/`.
erl $ETEST_ARGS -noshell -noinput -pa _build/default/lib/*/ebin -s etest_runner init $modules
