From: Shane Jaroch Date: Thu, 15 Jan 2026 06:29:53 +0000 (-0500) Subject: update test coverage X-Git-Url: https://git.nutra.tk/v2?a=commitdiff_plain;h=4eae4d7bc97afd0a765ade704b8c1c28b6b3df2f;p=gamesguru%2Fgit-remote-gcrypt.git update test coverage --- diff --git a/install.sh b/install.sh index 1eb0c58..6716265 100755 --- a/install.sh +++ b/install.sh @@ -20,9 +20,10 @@ install_v() { } # --- VERSION DETECTION --- -if [ -f /etc/os-release ]; then - # shellcheck disable=SC1091 - . /etc/os-release +: "${OS_RELEASE_FILE:=/etc/os-release}" +if [ -f "$OS_RELEASE_FILE" ]; then + # shellcheck disable=SC1091,SC1090 + . "$OS_RELEASE_FILE" OS_IDENTIFIER=$ID # Linux elif command -v uname >/dev/null; then # Fallback for macOS/BSD (darwin) diff --git a/tests/test-install-logic.sh b/tests/test-install-logic.sh index c160ae1..61b16e7 100755 --- a/tests/test-install-logic.sh +++ b/tests/test-install-logic.sh @@ -2,7 +2,12 @@ set -u # 1. Setup Sandbox -SANDBOX=$(mktemp -d) +# 1. Setup Sandbox in project root to help kcov tracking +REPO_ROOT=$(pwd) +mkdir -p .tmp +SANDBOX=$(mktemp -d -p "$REPO_ROOT/.tmp" sandbox.XXXXXX) +# Use realpath for the sandbox to avoid any confusion +SANDBOX=$(realpath "$SANDBOX") trap 'rm -rf "$SANDBOX"' EXIT # Helpers @@ -12,13 +17,16 @@ print_err() { printf "\033[1;31m[TEST] FAIL: %s\033[0m\n" "$1"; } print_info "Running install logic tests in $SANDBOX..." -# 2. Copy artifacts -cp git-remote-gcrypt "$SANDBOX" -cp README.rst "$SANDBOX" 2>/dev/null || touch "$SANDBOX/README.rst" -cp completions/templates/README.rst.in "$SANDBOX" -cp -r completions/ "$SANDBOX" -cp -r utils/ "$SANDBOX" -cp install.sh "$SANDBOX" +# 2. Symlink/Copy artifacts +# Symlink core logic to help kcov find the source +ln -s "$REPO_ROOT/install.sh" "$SANDBOX/install.sh" +ln -s "$REPO_ROOT/git-remote-gcrypt" "$SANDBOX/git-remote-gcrypt" +ln -s "$REPO_ROOT/utils" "$SANDBOX/utils" +ln -s "$REPO_ROOT/completions" "$SANDBOX/completions" +# Copy README as it might be edited/checked +cp "$REPO_ROOT/README.rst" "$SANDBOX/" +cp "$REPO_ROOT/completions/templates/README.rst.in" "$SANDBOX/" + cd "$SANDBOX" || exit 2 # Ensure source binary has the placeholder for sed to work on @@ -127,6 +135,72 @@ else exit 1 fi +# --- TEST 5: Permission Failure --- +echo "--- Test 5: Permission Failure ---" +RO_DIR="$SANDBOX/ro_dir" +mkdir -p "$RO_DIR" +# Make it non-writable +chmod 555 "$RO_DIR" +export prefix="$RO_DIR/usr" +unset DESTDIR + +if "bash" "$INSTALLER" >.install_log 2>&1; then + print_err "FAILED: Installer should have failed due to permissions" + rm -rf "$RO_DIR" + exit 1 +else + printf " ✓ %s\n" "Installer failed gracefully on permissions" +fi +rm -rf "$RO_DIR" + +# --- TEST 6: Missing rst2man --- +echo "--- Test 6: Missing rst2man ---" +# Shadow rst2man in PATH +SHADOW_BIN="$SANDBOX/shadow_bin" +mkdir -p "$SHADOW_BIN" +cat >"$SHADOW_BIN/rst2man" <.install_log 2>&1; then + printf " ✓ %s\n" "Installer handled missing rst2man" +else + print_err "Installer FAILED unexpectedly with missing rst2man. Output:" + cat .install_log + exit 1 +fi + +# --- TEST 7: OS Detection Fallbacks --- +echo "--- Test 7: OS Detection Fallbacks ---" +# 7a: Hit 'uname' path by mocking absence of /etc/os-release via OS_RELEASE_FILE +if prefix="$SANDBOX/usr" DESTDIR="" OS_RELEASE_FILE="$SANDBOX/nonexistent" bash "$INSTALLER" >.install_log 2>&1; then + printf " ✓ %s\n" "OS Detection: uname path hit" +else + print_err "Installer FAILED in OS fallback (uname) path" + exit 1 +fi + +# 7b: Hit 'unknown_OS' path by mocking absence of both +# We need to shadow 'uname' too +SHADOW_BIN_OS="$SANDBOX/shadow_bin_os" +mkdir -p "$SHADOW_BIN_OS" +cat >"$SHADOW_BIN_OS/uname" <.install_log 2>&1; then + printf " ✓ %s\n" "OS Detection: unknown_OS path hit" +else + print_err "Installer FAILED in unknown_OS fallback path" + exit 1 +fi +rm -rf "$SHADOW_BIN_OS" "$SHADOW_BIN" + print_success "All install logic tests passed." [ -n "${COV_DIR:-}" ] && print_success "OK. Report: file://${COV_DIR}/index.html"