Refactoring & tests

This commit is contained in:
Tim
2026-07-06 21:09:30 +02:00
parent 482b3b8d29
commit 9ed66dacbc
14 changed files with 948 additions and 108 deletions
+33
View File
@@ -0,0 +1,33 @@
#!/bin/bash
# Mock für pgrep - steuert Prozess-Erkennung
# pgrep -c: gibt Anzahl aus, Exit-Code 0 wenn >0, sonst 1
MOCK_DIR="/home/tim/Dokumente/Sourcen/Logseq-Installer/test/fixtures"
MOCK_STATE_FILE="${MOCK_DIR}/pgrep_state"
if [[ -f "${MOCK_STATE_FILE}" ]]; then
# shellcheck source=/dev/null
source "${MOCK_STATE_FILE}"
fi
# Default: kein Prozess läuft
PGREP_MATCH_COUNT="${PGREP_MATCH_COUNT:-0}"
# -c flag: count matches (prüft ob -c in den Flags enthalten ist)
if [[ "$*" == *"-c"* ]] || [[ "$*" == *"-ifcx"* ]] || [[ "$*" == *"-c "* ]]; then
echo "${PGREP_MATCH_COUNT}"
# Exit-Code wie echtes pgrep: 0 wenn Treffer, 1 wenn keine Treffer
[[ "${PGREP_MATCH_COUNT}" -gt 0 ]]
exit $?
fi
# Normaler Aufruf: PIDs zurückgeben
if [[ "${PGREP_MATCH_COUNT}" -gt 0 ]]; then
for i in $(seq 1 "${PGREP_MATCH_COUNT}"); do
echo $((1000 + i))
done
exit 0
fi
# Keine Treffer
exit 1