mirror of
https://github.com/tw93/Mole.git
synced 2026-02-07 21:29:20 +00:00
Reconstruct clean lib code
This commit is contained in:
@@ -22,8 +22,8 @@ teardown_file() {
|
||||
}
|
||||
|
||||
setup() {
|
||||
source "$PROJECT_ROOT/lib/common.sh"
|
||||
source "$PROJECT_ROOT/lib/update_manager.sh"
|
||||
source "$PROJECT_ROOT/lib/core/common.sh"
|
||||
source "$PROJECT_ROOT/lib/manage/update.sh"
|
||||
}
|
||||
|
||||
# Test brew_has_outdated function
|
||||
@@ -33,7 +33,7 @@ setup() {
|
||||
}
|
||||
export -f brew
|
||||
|
||||
run bash -c "source '$PROJECT_ROOT/lib/common.sh'; source '$PROJECT_ROOT/lib/update_manager.sh'; brew_has_outdated"
|
||||
run bash -c "source '$PROJECT_ROOT/lib/core/common.sh'; source '$PROJECT_ROOT/lib/manage/update.sh'; brew_has_outdated"
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ setup() {
|
||||
}
|
||||
export -f brew
|
||||
|
||||
run bash -c "source '$PROJECT_ROOT/lib/common.sh'; source '$PROJECT_ROOT/lib/update_manager.sh'; brew_has_outdated"
|
||||
run bash -c "source '$PROJECT_ROOT/lib/core/common.sh'; source '$PROJECT_ROOT/lib/manage/update.sh'; brew_has_outdated"
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@@ -64,30 +64,30 @@ setup() {
|
||||
}
|
||||
export -f brew
|
||||
|
||||
run bash -c "source '$PROJECT_ROOT/lib/common.sh'; source '$PROJECT_ROOT/lib/update_manager.sh'; brew_has_outdated cask"
|
||||
run bash -c "source '$PROJECT_ROOT/lib/core/common.sh'; source '$PROJECT_ROOT/lib/manage/update.sh'; brew_has_outdated cask"
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
# Test format_brew_update_label function
|
||||
@test "format_brew_update_label returns empty when no updates" {
|
||||
result=$(BREW_OUTDATED_COUNT=0 bash -c "source '$PROJECT_ROOT/lib/common.sh'; source '$PROJECT_ROOT/lib/update_manager.sh'; format_brew_update_label")
|
||||
result=$(BREW_OUTDATED_COUNT=0 bash -c "source '$PROJECT_ROOT/lib/core/common.sh'; source '$PROJECT_ROOT/lib/manage/update.sh'; format_brew_update_label")
|
||||
[[ -z "$result" ]]
|
||||
}
|
||||
|
||||
@test "format_brew_update_label formats with formula and cask counts" {
|
||||
result=$(BREW_OUTDATED_COUNT=5 BREW_FORMULA_OUTDATED_COUNT=3 BREW_CASK_OUTDATED_COUNT=2 bash -c "source '$PROJECT_ROOT/lib/common.sh'; source '$PROJECT_ROOT/lib/update_manager.sh'; format_brew_update_label")
|
||||
result=$(BREW_OUTDATED_COUNT=5 BREW_FORMULA_OUTDATED_COUNT=3 BREW_CASK_OUTDATED_COUNT=2 bash -c "source '$PROJECT_ROOT/lib/core/common.sh'; source '$PROJECT_ROOT/lib/manage/update.sh'; format_brew_update_label")
|
||||
[[ "$result" =~ "3 formula" ]]
|
||||
[[ "$result" =~ "2 cask" ]]
|
||||
}
|
||||
|
||||
@test "format_brew_update_label shows total when breakdown unavailable" {
|
||||
result=$(BREW_OUTDATED_COUNT=5 bash -c "source '$PROJECT_ROOT/lib/common.sh'; source '$PROJECT_ROOT/lib/update_manager.sh'; format_brew_update_label")
|
||||
result=$(BREW_OUTDATED_COUNT=5 bash -c "source '$PROJECT_ROOT/lib/core/common.sh'; source '$PROJECT_ROOT/lib/manage/update.sh'; format_brew_update_label")
|
||||
[[ "$result" =~ "5 updates" ]]
|
||||
}
|
||||
|
||||
# Test ask_for_updates function
|
||||
@test "ask_for_updates returns 1 when no updates available" {
|
||||
run bash -c "source '$PROJECT_ROOT/lib/common.sh'; source '$PROJECT_ROOT/lib/update_manager.sh'; ask_for_updates < /dev/null"
|
||||
run bash -c "source '$PROJECT_ROOT/lib/core/common.sh'; source '$PROJECT_ROOT/lib/manage/update.sh'; ask_for_updates < /dev/null"
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ setup() {
|
||||
export BREW_CASK_OUTDATED_COUNT=2
|
||||
|
||||
# Use input redirection to simulate ESC (cancel)
|
||||
run bash -c "printf '\x1b' | source '$PROJECT_ROOT/lib/common.sh'; source '$PROJECT_ROOT/lib/update_manager.sh'; ask_for_updates"
|
||||
run bash -c "printf '\x1b' | source '$PROJECT_ROOT/lib/core/common.sh'; source '$PROJECT_ROOT/lib/manage/update.sh'; ask_for_updates"
|
||||
# Should show updates and ask for confirmation
|
||||
[ "$status" -eq 1 ] # ESC cancels
|
||||
}
|
||||
@@ -106,21 +106,21 @@ setup() {
|
||||
@test "ask_for_updates detects App Store updates" {
|
||||
export APPSTORE_UPDATE_COUNT=3
|
||||
|
||||
run bash -c "printf '\x1b' | source '$PROJECT_ROOT/lib/common.sh'; source '$PROJECT_ROOT/lib/update_manager.sh'; ask_for_updates"
|
||||
run bash -c "printf '\x1b' | source '$PROJECT_ROOT/lib/core/common.sh'; source '$PROJECT_ROOT/lib/manage/update.sh'; ask_for_updates"
|
||||
[ "$status" -eq 1 ] # ESC cancels
|
||||
}
|
||||
|
||||
@test "ask_for_updates detects macOS updates" {
|
||||
export MACOS_UPDATE_AVAILABLE=true
|
||||
|
||||
run bash -c "printf '\x1b' | source '$PROJECT_ROOT/lib/common.sh'; source '$PROJECT_ROOT/lib/update_manager.sh'; ask_for_updates"
|
||||
run bash -c "printf '\x1b' | source '$PROJECT_ROOT/lib/core/common.sh'; source '$PROJECT_ROOT/lib/manage/update.sh'; ask_for_updates"
|
||||
[ "$status" -eq 1 ] # ESC cancels
|
||||
}
|
||||
|
||||
@test "ask_for_updates detects Mole updates" {
|
||||
export MOLE_UPDATE_AVAILABLE=true
|
||||
|
||||
run bash -c "printf '\x1b' | source '$PROJECT_ROOT/lib/common.sh'; source '$PROJECT_ROOT/lib/update_manager.sh'; ask_for_updates"
|
||||
run bash -c "printf '\x1b' | source '$PROJECT_ROOT/lib/core/common.sh'; source '$PROJECT_ROOT/lib/manage/update.sh'; ask_for_updates"
|
||||
[ "$status" -eq 1 ] # ESC cancels
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user