mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 16:49:41 +00:00
Merge branch 'dev' into dev
This commit is contained in:
122
tests/brew_uninstall.bats
Normal file
122
tests/brew_uninstall.bats
Normal file
@@ -0,0 +1,122 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
setup_file() {
|
||||
PROJECT_ROOT="$(cd "${BATS_TEST_DIRNAME}/.." && pwd)"
|
||||
export PROJECT_ROOT
|
||||
|
||||
ORIGINAL_HOME="${HOME:-}"
|
||||
export ORIGINAL_HOME
|
||||
|
||||
HOME="$(mktemp -d "${BATS_TEST_DIRNAME}/tmp-brew-uninstall-home.XXXXXX")"
|
||||
export HOME
|
||||
}
|
||||
|
||||
teardown_file() {
|
||||
rm -rf "$HOME"
|
||||
export HOME="$ORIGINAL_HOME"
|
||||
}
|
||||
|
||||
setup() {
|
||||
mkdir -p "$HOME/Applications"
|
||||
mkdir -p "$HOME/Library/Caches"
|
||||
# Create fake Caskroom
|
||||
mkdir -p "$HOME/Caskroom/test-app/1.2.3/TestApp.app"
|
||||
}
|
||||
|
||||
@test "get_brew_cask_name detects app in Caskroom (simulated)" {
|
||||
# Create fake Caskroom structure with symlink (modern Homebrew style)
|
||||
mkdir -p "$HOME/Caskroom/test-app/1.0.0"
|
||||
mkdir -p "$HOME/Applications/TestApp.app"
|
||||
ln -s "$HOME/Applications/TestApp.app" "$HOME/Caskroom/test-app/1.0.0/TestApp.app"
|
||||
|
||||
run bash <<EOF
|
||||
source "$PROJECT_ROOT/lib/core/common.sh"
|
||||
|
||||
# Override the function to use our test Caskroom
|
||||
get_brew_cask_name() {
|
||||
local app_path="\$1"
|
||||
[[ -z "\$app_path" || ! -d "\$app_path" ]] && return 1
|
||||
command -v brew > /dev/null 2>&1 || return 1
|
||||
|
||||
local app_bundle_name=\$(basename "\$app_path")
|
||||
local cask_match
|
||||
# Use test Caskroom
|
||||
cask_match=\$(find "$HOME/Caskroom" -maxdepth 3 -name "\$app_bundle_name" 2> /dev/null | head -1 || echo "")
|
||||
if [[ -n "\$cask_match" ]]; then
|
||||
local relative="\${cask_match#$HOME/Caskroom/}"
|
||||
echo "\${relative%%/*}"
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
get_brew_cask_name "$HOME/Applications/TestApp.app"
|
||||
EOF
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == "test-app" ]]
|
||||
}
|
||||
|
||||
@test "get_brew_cask_name handles non-brew apps" {
|
||||
mkdir -p "$HOME/Applications/ManualApp.app"
|
||||
|
||||
result=$(bash <<EOF
|
||||
source "$PROJECT_ROOT/lib/core/common.sh"
|
||||
# Mock brew to return nothing for this
|
||||
brew() { return 1; }
|
||||
export -f brew
|
||||
get_brew_cask_name "$HOME/Applications/ManualApp.app" || echo "not_found"
|
||||
EOF
|
||||
)
|
||||
|
||||
[[ "$result" == "not_found" ]]
|
||||
}
|
||||
|
||||
@test "batch_uninstall_applications uses brew uninstall for casks (mocked)" {
|
||||
# Setup fake app
|
||||
local app_bundle="$HOME/Applications/BrewApp.app"
|
||||
mkdir -p "$app_bundle"
|
||||
|
||||
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc << 'EOF'
|
||||
set -euo pipefail
|
||||
source "$PROJECT_ROOT/lib/core/common.sh"
|
||||
source "$PROJECT_ROOT/lib/uninstall/batch.sh"
|
||||
|
||||
# Mock dependencies
|
||||
request_sudo_access() { return 0; }
|
||||
start_inline_spinner() { :; }
|
||||
stop_inline_spinner() { :; }
|
||||
get_file_owner() { whoami; }
|
||||
get_path_size_kb() { echo "100"; }
|
||||
bytes_to_human() { echo "$1"; }
|
||||
drain_pending_input() { :; }
|
||||
print_summary_block() { :; }
|
||||
remove_apps_from_dock() { :; }
|
||||
force_kill_app() { return 0; }
|
||||
run_with_timeout() { shift; "$@"; }
|
||||
export -f run_with_timeout
|
||||
|
||||
# Mock brew to track calls
|
||||
brew() {
|
||||
echo "brew call: $*" >> "$HOME/brew_calls.log"
|
||||
return 0
|
||||
}
|
||||
export -f brew
|
||||
|
||||
# Mock get_brew_cask_name to return a name
|
||||
get_brew_cask_name() { echo "brew-app-cask"; return 0; }
|
||||
export -f get_brew_cask_name
|
||||
|
||||
selected_apps=("0|$HOME/Applications/BrewApp.app|BrewApp|com.example.brewapp|0|Never")
|
||||
files_cleaned=0
|
||||
total_items=0
|
||||
total_size_cleaned=0
|
||||
|
||||
# Simulate 'Enter' for confirmation
|
||||
printf '\n' | batch_uninstall_applications > /dev/null 2>&1
|
||||
|
||||
grep -q "uninstall --cask brew-app-cask" "$HOME/brew_calls.log"
|
||||
EOF
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
@@ -83,6 +83,8 @@ clean_project_caches() { :; }
|
||||
clean_dev_python() { :; }
|
||||
clean_dev_go() { :; }
|
||||
clean_dev_rust() { :; }
|
||||
check_rust_toolchains() { :; }
|
||||
check_android_ndk() { :; }
|
||||
clean_dev_docker() { :; }
|
||||
clean_dev_cloud() { :; }
|
||||
clean_dev_nix() { :; }
|
||||
@@ -96,6 +98,10 @@ clean_dev_database() { :; }
|
||||
clean_dev_api_tools() { :; }
|
||||
clean_dev_network() { :; }
|
||||
clean_dev_misc() { :; }
|
||||
clean_dev_elixir() { :; }
|
||||
clean_dev_haskell() { :; }
|
||||
clean_dev_ocaml() { :; }
|
||||
clean_dev_editors() { :; }
|
||||
safe_clean() { :; }
|
||||
debug_log() { :; }
|
||||
clean_developer_tools
|
||||
|
||||
@@ -20,7 +20,7 @@ teardown_file() {
|
||||
fi
|
||||
}
|
||||
|
||||
@test "clean_dev_elixir cleans mix and hex caches" {
|
||||
@test "clean_dev_elixir cleans hex cache" {
|
||||
mkdir -p "$HOME/.mix" "$HOME/.hex"
|
||||
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF'
|
||||
set -euo pipefail
|
||||
@@ -31,11 +31,25 @@ clean_dev_elixir
|
||||
EOF
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
[[ "$output" == *"Hex cache"* ]]
|
||||
}
|
||||
|
||||
@test "clean_dev_haskell cleans cabal install and stack caches" {
|
||||
@test "clean_dev_elixir does not clean mix archives" {
|
||||
mkdir -p "$HOME/.mix/archives"
|
||||
touch "$HOME/.mix/archives/test_tool.ez"
|
||||
|
||||
# Source and run the function
|
||||
source "$PROJECT_ROOT/lib/core/common.sh"
|
||||
source "$PROJECT_ROOT/lib/clean/dev.sh"
|
||||
# shellcheck disable=SC2329
|
||||
safe_clean() { :; }
|
||||
clean_dev_elixir > /dev/null 2>&1 || true
|
||||
|
||||
# Verify the file still exists
|
||||
[ -f "$HOME/.mix/archives/test_tool.ez" ]
|
||||
}
|
||||
|
||||
@test "clean_dev_haskell cleans cabal install cache" {
|
||||
mkdir -p "$HOME/.cabal" "$HOME/.stack"
|
||||
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc <<'EOF'
|
||||
set -euo pipefail
|
||||
@@ -47,7 +61,21 @@ EOF
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"Cabal install cache"* ]]
|
||||
}
|
||||
|
||||
@test "clean_dev_haskell does not clean stack programs" {
|
||||
mkdir -p "$HOME/.stack/programs/x86_64-osx"
|
||||
touch "$HOME/.stack/programs/x86_64-osx/ghc-9.2.8.tar.xz"
|
||||
|
||||
# Source and run the function
|
||||
source "$PROJECT_ROOT/lib/core/common.sh"
|
||||
source "$PROJECT_ROOT/lib/clean/dev.sh"
|
||||
# shellcheck disable=SC2329
|
||||
safe_clean() { :; }
|
||||
clean_dev_haskell > /dev/null 2>&1 || true
|
||||
|
||||
# Verify the file still exists
|
||||
[ -f "$HOME/.stack/programs/x86_64-osx/ghc-9.2.8.tar.xz" ]
|
||||
}
|
||||
|
||||
@test "clean_dev_ocaml cleans opam cache" {
|
||||
@@ -76,6 +104,48 @@ EOF
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"VS Code cached data"* ]]
|
||||
|
||||
[[ "$output" == *"Zed cache"* ]]
|
||||
}
|
||||
|
||||
@test "clean_dev_editors does not clean VS Code workspace storage" {
|
||||
mkdir -p "$HOME/Library/Application Support/Code/User/workspaceStorage/abc123"
|
||||
touch "$HOME/Library/Application Support/Code/User/workspaceStorage/abc123/workspace.json"
|
||||
|
||||
# Source and run the function
|
||||
source "$PROJECT_ROOT/lib/core/common.sh"
|
||||
source "$PROJECT_ROOT/lib/clean/dev.sh"
|
||||
# shellcheck disable=SC2329
|
||||
safe_clean() { :; }
|
||||
clean_dev_editors > /dev/null 2>&1 || true
|
||||
|
||||
# Verify the file still exists
|
||||
[ -f "$HOME/Library/Application Support/Code/User/workspaceStorage/abc123/workspace.json" ]
|
||||
}
|
||||
|
||||
@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"
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"Found 3 Android NDK versions"* ]]
|
||||
}
|
||||
|
||||
@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"
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" != *"Found"*"NDK"* ]]
|
||||
}
|
||||
|
||||
@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"
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"Found 3 Rust toolchains"* ]]
|
||||
}
|
||||
|
||||
@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"
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" != *"Found"*"Rust"* ]]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user