#!/usr/bin/env bash

set -euo pipefail

here=$(cd "$(dirname "$BASH_SOURCE")"; pwd)
source "$here/env.bash"

echo "[!!] Using Emacs binary from $(which $EMACS) version: $($EMACS --version)"
if [[ $* == "watch" ]]; then
    (
        cd "$PROJECT_ROOT"
        cargo watch -s bin/build -s bin/test
    )
else
    (
        cd "$PROJECT_ROOT"
        cask emacs --batch \
             --directory "$PROJECT_ROOT/core" \
             --directory "$PROJECT_ROOT/lisp" \
             --directory "$PROJECT_ROOT/langs" \
             -l ert \
             -l tree-sitter-tests.el \
             -f ert-run-tests-batch-and-exit
    )
fi
