mirror of
https://github.com/tw93/Mole.git
synced 2026-02-04 11:31:46 +00:00
Test case update
This commit is contained in:
21
bin/clean.sh
21
bin/clean.sh
@@ -15,7 +15,7 @@ source "$SCRIPT_DIR/../lib/common.sh"
|
||||
# Configuration
|
||||
SYSTEM_CLEAN=false
|
||||
DRY_RUN=false
|
||||
IS_M_SERIES=$([ "$(uname -m)" = "arm64" ] && echo "true" || echo "false")
|
||||
IS_M_SERIES=$([[ "$(uname -m)" == "arm64" ]] && echo "true" || echo "false")
|
||||
|
||||
# Constants
|
||||
readonly MAX_PARALLEL_JOBS=15 # Maximum parallel background jobs
|
||||
@@ -404,9 +404,9 @@ clean_ds_store_tree() {
|
||||
)
|
||||
|
||||
# Limit depth for HOME to avoid slow scans
|
||||
local max_depth=""
|
||||
local -a max_depth=()
|
||||
if [[ "$target" == "$HOME" ]]; then
|
||||
max_depth="-maxdepth 5"
|
||||
max_depth=(-maxdepth 5)
|
||||
fi
|
||||
|
||||
# Find .DS_Store files with exclusions and depth limit
|
||||
@@ -423,7 +423,7 @@ clean_ds_store_tree() {
|
||||
if [[ $file_count -ge 500 ]]; then
|
||||
break
|
||||
fi
|
||||
done < <(find "$target" $max_depth "${exclude_paths[@]}" -type f -name '.DS_Store' -print0 2> /dev/null)
|
||||
done < <(find "$target" "${max_depth[@]}" "${exclude_paths[@]}" -type f -name '.DS_Store' -print0 2> /dev/null)
|
||||
|
||||
if [[ "$spinner_active" == "true" ]]; then
|
||||
stop_inline_spinner
|
||||
@@ -1243,19 +1243,18 @@ perform_cleanup() {
|
||||
|
||||
# Define resource types to scan
|
||||
local -a resource_types=(
|
||||
"~/Library/Caches|Caches|com.*:org.*:net.*:io.*"
|
||||
"~/Library/Logs|Logs|com.*:org.*:net.*:io.*"
|
||||
"~/Library/Saved Application State|States|*.savedState"
|
||||
"~/Library/WebKit|WebKit|com.*:org.*:net.*:io.*"
|
||||
"~/Library/HTTPStorages|HTTP|com.*:org.*:net.*:io.*"
|
||||
"~/Library/Cookies|Cookies|*.binarycookies"
|
||||
"$HOME/Library/Caches|Caches|com.*:org.*:net.*:io.*"
|
||||
"$HOME/Library/Logs|Logs|com.*:org.*:net.*:io.*"
|
||||
"$HOME/Library/Saved Application State|States|*.savedState"
|
||||
"$HOME/Library/WebKit|WebKit|com.*:org.*:net.*:io.*"
|
||||
"$HOME/Library/HTTPStorages|HTTP|com.*:org.*:net.*:io.*"
|
||||
"$HOME/Library/Cookies|Cookies|*.binarycookies"
|
||||
)
|
||||
|
||||
orphaned_count=0
|
||||
|
||||
for resource_type in "${resource_types[@]}"; do
|
||||
IFS='|' read -r base_path label patterns <<< "$resource_type"
|
||||
base_path="${base_path/#\~/$HOME}"
|
||||
|
||||
[[ -d "$base_path" ]] || continue
|
||||
|
||||
|
||||
@@ -101,7 +101,11 @@ check_startup_items() {
|
||||
)
|
||||
|
||||
for dir in "${dirs[@]}"; do
|
||||
[[ -d "$dir" ]] && count=$((count + $(ls -1 "$dir" 2> /dev/null | wc -l)))
|
||||
if [[ -d "$dir" ]]; then
|
||||
local dir_count
|
||||
dir_count=$(find "$dir" -maxdepth 1 -type f -name "*.plist" 2> /dev/null | wc -l)
|
||||
count=$((count + dir_count))
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ $count -gt 5 ]]; then
|
||||
|
||||
2
mole
2
mole
@@ -22,7 +22,7 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR/lib/common.sh"
|
||||
|
||||
# Version info
|
||||
VERSION="1.8.3"
|
||||
VERSION="1.9.0"
|
||||
MOLE_TAGLINE="can dig deep to clean your Mac."
|
||||
|
||||
# Get latest version from remote repository
|
||||
|
||||
@@ -28,6 +28,8 @@ echo ""
|
||||
echo "✓ Build complete!"
|
||||
echo ""
|
||||
file bin/analyze-go
|
||||
ls -lh bin/analyze-go | awk '{print "Size:", $5}'
|
||||
size_bytes=$(stat -f%z bin/analyze-go 2> /dev/null || echo 0)
|
||||
size_mb=$((size_bytes / 1024 / 1024))
|
||||
printf "Size: %d MB (%d bytes)\n" "$size_mb" "$size_bytes"
|
||||
echo ""
|
||||
echo "Binary supports: arm64 (Apple Silicon) + x86_64 (Intel)"
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
#!/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-analyze-home.XXXXXX")"
|
||||
export HOME
|
||||
}
|
||||
|
||||
teardown_file() {
|
||||
rm -rf "$HOME"
|
||||
if [[ -n "${ORIGINAL_HOME:-}" ]]; then
|
||||
export HOME="$ORIGINAL_HOME"
|
||||
fi
|
||||
}
|
||||
|
||||
setup() {
|
||||
export TERM="dumb"
|
||||
rm -rf "${HOME:?}"/*
|
||||
mkdir -p "$HOME"
|
||||
}
|
||||
|
||||
@test "scan_directories lists largest folders first" {
|
||||
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc << 'EOF'
|
||||
set -euo pipefail
|
||||
source "$PROJECT_ROOT/bin/analyze.sh"
|
||||
|
||||
root="$HOME/analyze-root"
|
||||
mkdir -p "$root/Small" "$root/Large"
|
||||
printf 'tiny' > "$root/Small/file.txt"
|
||||
dd if=/dev/zero of="$root/Large/big.dat" bs=1024 count=200 >/dev/null 2>&1
|
||||
|
||||
output_file="$HOME/directories.txt"
|
||||
scan_directories "$root" "$output_file" 1
|
||||
|
||||
head -n1 "$output_file"
|
||||
EOF
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"Large"* ]]
|
||||
}
|
||||
|
||||
@test "aggregate_by_directory sums child sizes per parent" {
|
||||
run env HOME="$HOME" PROJECT_ROOT="$PROJECT_ROOT" bash --noprofile --norc << 'EOF'
|
||||
set -euo pipefail
|
||||
source "$PROJECT_ROOT/bin/analyze.sh"
|
||||
|
||||
root="$HOME/group"
|
||||
mkdir -p "$root/a" "$root/b"
|
||||
|
||||
input_file="$HOME/files.txt"
|
||||
cat > "$input_file" <<LIST
|
||||
1024|$root/a/file1
|
||||
2048|$root/a/file2
|
||||
512|$root/b/data.bin
|
||||
LIST
|
||||
|
||||
output_file="$HOME/aggregated.txt"
|
||||
aggregate_by_directory "$input_file" "$output_file"
|
||||
|
||||
cat "$output_file"
|
||||
EOF
|
||||
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" == *"3072|$HOME/group/a/"* ]]
|
||||
[[ "$output" == *"512|$HOME/group/b/"* ]]
|
||||
}
|
||||
@@ -95,8 +95,19 @@ teardown() {
|
||||
}
|
||||
|
||||
@test "drain_pending_input clears stdin buffer" {
|
||||
# Test that drain_pending_input doesn't hang
|
||||
result=$(echo -e "test\ninput" | HOME="$HOME" timeout 1 bash --noprofile --norc -c "source '$PROJECT_ROOT/lib/common.sh'; drain_pending_input; echo done")
|
||||
# Test that drain_pending_input doesn't hang (using background job with timeout)
|
||||
result=$(
|
||||
(echo -e "test\ninput" | HOME="$HOME" bash --noprofile --norc -c "source '$PROJECT_ROOT/lib/common.sh'; drain_pending_input; echo done") &
|
||||
pid=$!
|
||||
sleep 2
|
||||
if kill -0 "$pid" 2> /dev/null; then
|
||||
kill "$pid" 2> /dev/null || true
|
||||
wait "$pid" 2> /dev/null || true
|
||||
echo "timeout"
|
||||
else
|
||||
wait "$pid" 2> /dev/null || true
|
||||
fi
|
||||
)
|
||||
[[ "$result" == "done" ]]
|
||||
}
|
||||
|
||||
|
||||
@@ -97,49 +97,3 @@ setup() {
|
||||
fi
|
||||
[ "$status" -ne 0 ]
|
||||
}
|
||||
|
||||
@test "whitelist rejects paths with spaces" {
|
||||
# Paths with spaces should be rejected by the new stricter validation
|
||||
mkdir -p "$HOME/.config/mole"
|
||||
echo "$HOME/.cache/invalid path" > "$WHITELIST_PATH"
|
||||
|
||||
# Load whitelist - path with space should be rejected
|
||||
warnings=$(HOME="$HOME" bash --noprofile --norc -c "
|
||||
source '$PROJECT_ROOT/bin/clean.sh'
|
||||
load_whitelist_file 2>&1 | grep -c 'Invalid path format' || echo 0
|
||||
")
|
||||
[ "$warnings" -ge 1 ]
|
||||
}
|
||||
|
||||
@test "whitelist rejects paths with consecutive slashes" {
|
||||
mkdir -p "$HOME/.config/mole"
|
||||
echo "$HOME/.cache//invalid" > "$WHITELIST_PATH"
|
||||
|
||||
warnings=$(HOME="$HOME" bash --noprofile --norc -c "
|
||||
source '$PROJECT_ROOT/bin/clean.sh'
|
||||
load_whitelist_file 2>&1 | grep -c 'Consecutive slashes' || echo 0
|
||||
")
|
||||
[ "$warnings" -ge 1 ]
|
||||
}
|
||||
|
||||
@test "whitelist rejects system protected paths" {
|
||||
mkdir -p "$HOME/.config/mole"
|
||||
echo "/System/Library/test" > "$WHITELIST_PATH"
|
||||
|
||||
warnings=$(HOME="$HOME" bash --noprofile --norc -c "
|
||||
source '$PROJECT_ROOT/bin/clean.sh'
|
||||
load_whitelist_file 2>&1 | grep -c 'Protected system path' || echo 0
|
||||
")
|
||||
[ "$warnings" -ge 1 ]
|
||||
}
|
||||
|
||||
@test "whitelist accepts valid paths with wildcards at end" {
|
||||
mkdir -p "$HOME/.config/mole"
|
||||
echo "$HOME/.cache/test/*" > "$WHITELIST_PATH"
|
||||
|
||||
# Should be accepted without warnings
|
||||
HOME="$HOME" bash --noprofile --norc -c "
|
||||
source '$PROJECT_ROOT/bin/clean.sh'
|
||||
load_whitelist_file
|
||||
" 2>&1 | grep -q "Invalid path format" && exit 1 || exit 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user