Files
coredesktop/tests/test_helper.bash
T
davidandClaude Opus 5.5 c6a6bac84a
shellcheck / shellcheck (push) Successful in 13s
Merge branch 'main' of https://gitea.federated.computer/Federated_Computer/coredesktop
Brings in the shellcheck lint and bats tests. Both sides fixed the same
shellcheck warnings; this keeps the remote's versions of 20-aur.sh,
80-gnome-extensions.sh and .shellcheckrc, which silence false positives
per line rather than for the whole repo.

The Gitea workflow now runs make lint, so it checks the same scripts as
the Makefile, and the README points contributors at make check. The test
helper's REPO, used only by the .bats files, is marked for shellcheck,
and the update test expects the pull to be fast-forward only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 07:25:07 -06:00

52 lines
1.3 KiB
Bash

#!/bin/bash
# Shared setup for the bats tests. Each test gets its own HOME and a bin dir at
# the front of PATH where it can put fake versions of pacman, yay, sudo, etc.
# Used by the .bats files that load this one
# shellcheck disable=SC2034
REPO="$(cd "$BATS_TEST_DIRNAME/.." && pwd)"
common_setup() {
export HOME="$BATS_TEST_TMPDIR/home"
export STUB_BIN="$BATS_TEST_TMPDIR/bin"
export STUB_LOG="$BATS_TEST_TMPDIR/stub.log"
mkdir -p "$HOME" "$STUB_BIN"
: > "$STUB_LOG"
export PATH="$STUB_BIN:$PATH"
unset COREDESKTOP
}
# A test file that needs more setup defines its own setup that calls this first
setup() {
common_setup
}
# stub NAME [BODY]: put a fake NAME on PATH that appends "NAME args..." to
# $STUB_LOG and then runs BODY, a bash snippet that sees the args as "$@"
stub() {
local name="$1" body="${2:-}"
cat > "$STUB_BIN/$name" << EOF
#!/bin/bash
echo "$name \$*" >> "\$STUB_LOG"
$body
EOF
chmod +x "$STUB_BIN/$name"
}
# called NAME ARGS...: true if the stub log has exactly the line "NAME ARGS..."
called() {
grep -qxF "$*" "$STUB_LOG"
}
# not_called NAME: true if the stub NAME never ran
not_called() {
! grep -q "^$1 " "$STUB_LOG"
}
# uncalled NAME ARGS...: the opposite of called. (A bare "! called ..." would
# not fail the test: bats, like set -e, ignores the status of a ! command.)
uncalled() {
! called "$@"
}