From ac5c0e3c9d6ab2447168c475ce38293a4c3239d1 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Sat, 3 Jan 2026 12:30:53 +0800 Subject: [PATCH] fix: Add Library directory existence check to clean script and enhance test script for bats version compatibility. --- lib/clean/user.sh | 4 ++++ scripts/test.sh | 17 +++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/clean/user.sh b/lib/clean/user.sh index f5dac2e..f1e6a01 100644 --- a/lib/clean/user.sh +++ b/lib/clean/user.sh @@ -18,6 +18,10 @@ clean_user_essentials() { } clean_empty_library_items() { + if [[ ! -d "$HOME/Library" ]]; then + return 0 + fi + local -a empty_dirs=() while IFS= read -r -d '' dir; do [[ -d "$dir" ]] && empty_dirs+=("$dir") diff --git a/scripts/test.sh b/scripts/test.sh index 4f0ce40..c4434bb 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -49,11 +49,20 @@ if command -v bats > /dev/null 2>&1 && [ -d "tests" ]; then if [[ $# -eq 0 ]]; then set -- tests fi - if TERM="${TERM:-xterm-256color}" bats --formatter "${BATS_FORMATTER:-pretty}" "$@"; then - printf "${GREEN}${ICON_SUCCESS} Unit tests passed${NC}\n" + if bats --help 2>&1 | grep -q -- "--formatter"; then + if TERM="${TERM:-xterm-256color}" bats --formatter "${BATS_FORMATTER:-pretty}" "$@"; then + printf "${GREEN}${ICON_SUCCESS} Unit tests passed${NC}\n" + else + printf "${RED}${ICON_ERROR} Unit tests failed${NC}\n" + ((FAILED++)) + fi else - printf "${RED}${ICON_ERROR} Unit tests failed${NC}\n" - ((FAILED++)) + if TERM="${TERM:-xterm-256color}" bats --tap "$@" | sed -e 's/^ok /OK /' -e 's/^not ok /FAIL /'; then + printf "${GREEN}${ICON_SUCCESS} Unit tests passed${NC}\n" + else + printf "${RED}${ICON_ERROR} Unit tests failed${NC}\n" + ((FAILED++)) + fi fi else printf "${YELLOW}${ICON_WARNING} bats not installed or no tests found, skipping${NC}\n"