#!/usr/bin/env bash
set -u

usage() {
    cat <<EOF
Usage: ${0##*/} [--help] [TARGET ...]

Run Neovim integration tests in a single 'nvim --headless' instance.

With no targets, runs every test/**/*_test.lua. Each TARGET may be a
test file or a directory; directories expand to all _test.lua files
beneath them.

Exit status is 0 if all tests passed, non-zero otherwise.
EOF
}

if [[ ${1:-} == --help || ${1:-} == -h ]]; then
    usage
    exit 0
fi

cd "$(dirname "$0")/.." || exit 1

if [[ -t 1 ]]; then
    export TEST_COLOR=1
fi

exec nvim --headless --clean -l test/runner.lua "$@"
