#!/bin/bash

# stdlib development test runner
# $@: arguments to pass to the distributable test runner

set -eo pipefail

_t_runner_working_directory="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)"

# shellcheck disable=SC2154
_t_runner_custom_execution_context() {
  # shellcheck source=src/__lib__.sh
  source "${_t_runner_working_directory}/../src/__lib__.sh"
  # shellcheck source=src/testing/__lib__.sh
  source "${_t_runner_working_directory}/../src/testing/__lib__.sh"
  # shellcheck source=src/testing/mock/mock.snippet
  source "${_t_runner_working_directory}/../src/testing/mock/mock.snippet"

  _t_runner_execute "$@"
}

export -f _t_runner_custom_execution_context

if [[ "${#@}" -eq 0 ]]; then
  set -- "${@}" "src"
fi

"${_t_runner_working_directory}/../dist/t" "$@"
