Switch to bats over pytest

This removes python entirely from the stack.
Yet to run the tests on macOS, but they're buildable by way of nix
wrapping. Worst case scenario, you cannot run them from the devshell
but `nix run .#test-runner-<latest||stable>` should work okay.
This commit is contained in:
Bryan Bennett 2025-08-09 08:47:06 -04:00
parent 445dc9ffc6
commit c59b60e747
23 changed files with 344 additions and 385 deletions

38
tests/util.bash Normal file
View file

@ -0,0 +1,38 @@
function _common_setup {
shopt -s globstar
bats_require_minimum_version 1.5.0
bats_load_library bats-support
bats_load_library bats-assert
TESTDIR=
TESTDIR=$(mktemp -d -t nix-direnv.XXXXXX)
export TESTDIR
export DIRENV_LOG_FORMAT="direnv: %s"
# Set up nix to be able to find your user's nix.conf if run locally
export NIX_USER_CONF_FILES="$HOME/.config/nix/nix.conf"
export HOME=$TESTDIR/home
unset XDG_DATA_HOME
unset XDG_CONFIG_HOME
cp "$BATS_TEST_DIRNAME"/testenv/* "$TESTDIR/"
}
function _common_teardown {
rm -rf "$TESTDIR"
}
function write_envrc {
echo "source $DIRENVRC" >"$TESTDIR/.envrc"
echo -e "\n$*" >>"$TESTDIR/.envrc"
direnv allow "$TESTDIR"
}
function run_in_direnv {
run --separate-stderr direnv exec "$TESTDIR" sh -c "$@"
assert_success
run direnv exec "$TESTDIR" sh -c "$@"
assert_success
assert_stderr -p "Renewed cache"
}