1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-04 22:04:43 +00:00

Unify output format for multiple versions check

This commit is contained in:
Tw93
2026-01-20 14:44:11 +08:00
parent b4b9b0c474
commit acdf40dd2c
2 changed files with 18 additions and 19 deletions

View File

@@ -77,12 +77,12 @@ clean_dev_rust() {
}
# Helper: Check for multiple versions in a directory.
# Args: $1=directory, $2=tool_name, $3+=additional_lines
# Args: $1=directory, $2=tool_name, $3=list_command, $4=remove_command
check_multiple_versions() {
local dir="$1"
local tool_name="$2"
shift 2
local -a additional_lines=("$@")
local list_cmd="${3:-}"
local remove_cmd="${4:-}"
if [[ ! -d "$dir" ]]; then
return 0
@@ -93,10 +93,11 @@ check_multiple_versions() {
if [[ "$count" -gt 1 ]]; then
note_activity
echo -e " Found ${GREEN}${count}${NC} ${tool_name}"
for line in "${additional_lines[@]}"; do
echo -e " $line"
done
local hint=""
if [[ -n "$list_cmd" ]]; then
hint=" · ${GRAY}${list_cmd}${NC}"
fi
echo -e " ${YELLOW}${ICON_WARNING}${NC} ${tool_name}: ${count} found${hint}"
fi
}
@@ -107,8 +108,7 @@ check_rust_toolchains() {
check_multiple_versions \
"$HOME/.rustup/toolchains" \
"Rust toolchains" \
"You can list them with: ${GRAY}rustup toolchain list${NC}" \
"Remove unused with: ${GRAY}rustup toolchain uninstall <name>${NC}"
"rustup toolchain list"
}
# Docker caches (guarded by daemon check).
clean_dev_docker() {
@@ -170,8 +170,7 @@ check_android_ndk() {
check_multiple_versions \
"$HOME/Library/Android/sdk/ndk" \
"Android NDK versions" \
"Manage in: ${GRAY}Android Studio → SDK Manager${NC}" \
"Or manually at: ${GRAY}\$HOME/Library/Android/sdk/ndk${NC}"
"Android Studio → SDK Manager"
}
clean_dev_mobile() {

View File

@@ -123,29 +123,29 @@ EOF
}
@test "check_android_ndk reports multiple NDK versions" {
run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/Library/Android/sdk/ndk"/{21.0.1,22.0.0,20.0.0} && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && check_android_ndk' "$PROJECT_ROOT/lib/clean/dev.sh"
run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/Library/Android/sdk/ndk"/{21.0.1,22.0.0,20.0.0} && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && YELLOW="" && ICON_WARNING="●" && check_android_ndk' "$PROJECT_ROOT/lib/clean/dev.sh"
[ "$status" -eq 0 ]
[[ "$output" == *"Found 3 Android NDK versions"* ]]
[[ "$output" == *"Android NDK versions: 3 found"* ]]
}
@test "check_android_ndk silent when only one NDK" {
run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/Library/Android/sdk/ndk/22.0.0" && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && check_android_ndk' "$PROJECT_ROOT/lib/clean/dev.sh"
run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/Library/Android/sdk/ndk/22.0.0" && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && YELLOW="" && ICON_WARNING="●" && check_android_ndk' "$PROJECT_ROOT/lib/clean/dev.sh"
[ "$status" -eq 0 ]
[[ "$output" != *"Found"*"NDK"* ]]
[[ "$output" != *"NDK versions"* ]]
}
@test "check_rust_toolchains reports multiple toolchains" {
run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/.rustup/toolchains"/{stable,nightly,1.75.0}-aarch64-apple-darwin && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && rustup() { :; } && export -f rustup && check_rust_toolchains' "$PROJECT_ROOT/lib/clean/dev.sh"
run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/.rustup/toolchains"/{stable,nightly,1.75.0}-aarch64-apple-darwin && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && YELLOW="" && ICON_WARNING="●" && rustup() { :; } && export -f rustup && check_rust_toolchains' "$PROJECT_ROOT/lib/clean/dev.sh"
[ "$status" -eq 0 ]
[[ "$output" == *"Found 3 Rust toolchains"* ]]
[[ "$output" == *"Rust toolchains: 3 found"* ]]
}
@test "check_rust_toolchains silent when only one toolchain" {
run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/.rustup/toolchains/stable-aarch64-apple-darwin" && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && rustup() { :; } && export -f rustup && check_rust_toolchains' "$PROJECT_ROOT/lib/clean/dev.sh"
run bash -c 'HOME=$(mktemp -d) && mkdir -p "$HOME/.rustup/toolchains/stable-aarch64-apple-darwin" && source "$0" && note_activity() { :; } && NC="" && GREEN="" && GRAY="" && YELLOW="" && ICON_WARNING="●" && rustup() { :; } && export -f rustup && check_rust_toolchains' "$PROJECT_ROOT/lib/clean/dev.sh"
[ "$status" -eq 0 ]
[[ "$output" != *"Found"*"Rust"* ]]
[[ "$output" != *"Rust toolchains"* ]]
}