Files
miaur/tests/run.sh
T
Cursor AgentandFrank Vitrano bba71040d6 Improve safety and CLI fidelity for everyday use
Drop default --noconfirm (opt-in via --noconfirm), fix --noremovemake,
forward pacman argv intact for -R/-D/-F/-T/-U, deepen PKGBUILD review,
show an install plan before building, and add shellcheck CI plus unit tests.

Co-authored-by: Frank Vitrano <WHC2006@users.noreply.github.com>
2026-07-23 14:39:03 +00:00

125 lines
3.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Lightweight self-tests for miaur (no Arch/pacman required)
set -euo pipefail
ROOT=$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/.." && pwd)
# shellcheck source=lib/common.sh
source "$ROOT/lib/common.sh"
# shellcheck source=lib/cli.sh
source "$ROOT/lib/cli.sh"
fail() { echo "FAIL: $*" >&2; exit 1; }
pass() { echo "ok - $*"; }
# --- strip_miaur_opts ---
{
mapfile -t out < <(strip_miaur_opts -Rns --nosudoloop --ignore linux foo)
[[ ${#out[@]} -eq 4 ]] || fail "strip count=${#out[@]} contents=${out[*]}"
[[ ${out[0]} == -Rns && ${out[1]} == --ignore && ${out[2]} == linux && ${out[3]} == foo ]] \
|| fail "strip values: ${out[*]}"
pass "strip_miaur_opts keeps pacman argv"
}
{
mapfile -t out < <(strip_miaur_opts -S --noconfirm --aur pkg)
[[ ${#out[@]} -eq 2 && ${out[0]} == -S && ${out[1]} == pkg ]] \
|| fail "strip noconfirm/aur: ${out[*]}"
pass "strip_miaur_opts drops miaur-only flags"
}
# --- parse_args: --noremovemake ---
{
OP=
MIAUR_REMOVEMAKE=1
MIAUR_NOCONFIRM=0
DO_PASSTHRU=0
OP_REFRESH=0
OP_UPGRADE=0
TARGETS=()
PACMAN_EXTRA=()
parse_args --noremovemake -S
[[ $MIAUR_REMOVEMAKE -eq 0 ]] || fail "noremovemake not applied"
[[ $OP == S ]] || fail "OP after noremovermake+S"
pass "parse_args --noremovemake"
}
{
OP=
MIAUR_REMOVEMAKE=1
TARGETS=()
PACMAN_EXTRA=()
parse_args --noremovermake
[[ $MIAUR_REMOVEMAKE -eq 0 ]] || fail "typo alias noremovermake not applied"
pass "parse_args typo alias --noremovermake"
}
{
OP=
MIAUR_NOCONFIRM=0
OP_REFRESH=0
OP_UPGRADE=0
TARGETS=()
PACMAN_EXTRA=()
parse_args --noconfirm -Syu
[[ $MIAUR_NOCONFIRM -eq 1 ]] || fail "noconfirm not set"
[[ $OP == S && $OP_REFRESH -eq 1 && $OP_UPGRADE -eq 1 ]] || fail "Syu parse"
pass "parse_args --noconfirm -Syu"
}
{
OP=
DO_PASSTHRU=0
TARGETS=()
PACMAN_EXTRA=()
parse_args -R --ignore linux foo
[[ $OP == R && $DO_PASSTHRU -eq 1 ]] || fail "R passthrough flags"
found=0
for x in "${PACMAN_EXTRA[@]}"; do
[[ $x == --ignore ]] && found=1
done
[[ $found -eq 1 ]] || fail "PACMAN_EXTRA missing --ignore: ${PACMAN_EXTRA[*]}"
[[ ${TARGETS[0]} == linux && ${TARGETS[1]} == foo ]] || fail "targets: ${TARGETS[*]}"
pass "parse_args -R --ignore passthrough tokens"
}
# --- pac_noconfirm_args / confirm_ask ---
{
MIAUR_NOCONFIRM=0
mapfile -t c < <(pac_noconfirm_args)
[[ ${#c[@]} -eq 0 ]] || fail "expected no noconfirm by default"
MIAUR_NOCONFIRM=1
mapfile -t c < <(pac_noconfirm_args)
[[ ${#c[@]} -eq 1 && ${c[0]} == --noconfirm ]] || fail "noconfirm args: ${c[*]}"
pass "pac_noconfirm_args"
}
{
MIAUR_NOCONFIRM=1
confirm_ask "should skip" || fail "confirm_ask should succeed with noconfirm"
pass "confirm_ask respects noconfirm"
}
# --- install.sh resolve_src: process substitution must not cd-fail ---
{
rs_out=$(
bash <(
# shellcheck disable=SC2016
sed -n '/^resolve_src()/,/^}/p' "$ROOT/install.sh"
cat <<'INNER'
REPO_URL=https://example.invalid/miaur.git
BRANCH=main
die() { echo "die:$*" >&2; exit 1; }
git() { echo "git-called"; exit 0; }
resolve_src
echo "SRC=${SRC:-}"
INNER
) 2>&1
) || true
[[ $rs_out != *'No such file or directory'* ]] || fail "process substitution still cd-fails: $rs_out"
[[ $rs_out == *'Cloning'* || $rs_out == *'git-called'* || $rs_out == *'die:'* ]] \
|| fail "unexpected resolve_src output: $rs_out"
pass "resolve_src survives process substitution"
}
echo "All tests passed."