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

Automated test speed fix

This commit is contained in:
Tw93
2025-11-19 10:07:20 +08:00
parent 1565d36981
commit 8b0396a9ff
4 changed files with 41 additions and 54 deletions

Binary file not shown.

4
mole
View File

@@ -285,7 +285,7 @@ remove_mole() {
# Find mole installations using which/command
local found_mole
found_mole=$(command -v mole 2>/dev/null || true)
found_mole=$(command -v mole 2> /dev/null || true)
if [[ -n "$found_mole" && -f "$found_mole" ]]; then
# Check if it's not a Homebrew symlink
if [[ ! -L "$found_mole" ]] || ! readlink "$found_mole" | grep -q "Cellar/mole"; then
@@ -311,7 +311,7 @@ remove_mole() {
# Find mo alias
local found_mo
found_mo=$(command -v mo 2>/dev/null || true)
found_mo=$(command -v mo 2> /dev/null || true)
if [[ -n "$found_mo" && -f "$found_mo" ]]; then
alias_installs+=("$found_mo")
fi

View File

@@ -51,16 +51,19 @@ setup() {
[[ "$output" == *"Touch ID"* ]]
}
@test "mo optimize shows available optimization categories" {
run env HOME="$HOME" "$PROJECT_ROOT/mole" optimize
@test "mo optimize command is recognized" {
# Test that optimize command exists without actually running it
# Running full optimize in tests is too slow (waits for sudo, runs health checks)
run bash -c "grep -q '\"optimize\")' '$PROJECT_ROOT/mole'"
[ "$status" -eq 0 ]
[[ "$output" == *"System"* ]] || [[ "$output" == *"optimization"* ]]
}
@test "mo analyze validates binary exists" {
@test "mo analyze binary is valid" {
if [[ -f "$PROJECT_ROOT/bin/analyze-go" ]]; then
run env HOME="$HOME" "$PROJECT_ROOT/mole" analyze --help
[ "$status" -eq 0 ]
# Verify binary is executable and valid Universal Binary
[ -x "$PROJECT_ROOT/bin/analyze-go" ]
run file "$PROJECT_ROOT/bin/analyze-go"
[[ "$output" == *"Mach-O"* ]] || [[ "$output" == *"executable"* ]]
else
skip "analyze-go binary not built"
fi

View File

@@ -42,11 +42,15 @@ setup() {
[[ "$output" == *"Usage"* ]]
}
@test "check.sh runs all quality checks" {
run "$PROJECT_ROOT/scripts/check.sh"
# May pass or fail, but should complete
[[ "$status" -eq 0 || "$status" -eq 1 ]]
[[ "$output" == *"Quality Checks"* ]]
@test "check.sh script exists and is valid" {
# Don't actually run check.sh in tests - it would recursively run all bats tests!
# Just verify the script is valid bash
[ -f "$PROJECT_ROOT/scripts/check.sh" ]
[ -x "$PROJECT_ROOT/scripts/check.sh" ]
# Verify it has the expected structure
run bash -c "grep -q 'Quality Checks' '$PROJECT_ROOT/scripts/check.sh'"
[ "$status" -eq 0 ]
}
@test "build-analyze.sh detects missing Go toolchain" {
@@ -59,47 +63,27 @@ setup() {
[[ "$output" == *"Go not installed"* ]]
}
@test "build-analyze.sh shows version and build time" {
if ! command -v go > /dev/null 2>&1; then
skip "Go not installed"
fi
run "$PROJECT_ROOT/scripts/build-analyze.sh"
[[ "$output" == *"Version:"* ]]
[[ "$output" == *"Build time:"* ]]
}
@test "setup-quick-launchers.sh detects mole binary" {
# Create a fake mole binary
mkdir -p "$HOME/.local/bin"
cat > "$HOME/.local/bin/mole" << 'EOF'
#!/bin/bash
echo "fake mole"
EOF
chmod +x "$HOME/.local/bin/mole"
run env HOME="$HOME" PATH="$HOME/.local/bin:$PATH" "$PROJECT_ROOT/scripts/setup-quick-launchers.sh"
@test "build-analyze.sh has version info support" {
# Don't actually build in tests - too slow (10-30 seconds)
# Just verify the script contains version info logic
run bash -c "grep -q 'VERSION=' '$PROJECT_ROOT/scripts/build-analyze.sh'"
[ "$status" -eq 0 ]
[[ "$output" == *"Detected Mole binary"* ]]
}
@test "setup-quick-launchers.sh creates Raycast scripts" {
if [[ ! -d "$HOME/Library/Application Support/Raycast" ]]; then
mkdir -p "$HOME/Library/Application Support/Raycast/script-commands"
fi
# Create a fake mole binary
mkdir -p "$HOME/.local/bin"
cat > "$HOME/.local/bin/mole" << 'EOF'
#!/bin/bash
echo "fake mole"
EOF
chmod +x "$HOME/.local/bin/mole"
run env HOME="$HOME" PATH="$HOME/.local/bin:$PATH" "$PROJECT_ROOT/scripts/setup-quick-launchers.sh"
run bash -c "grep -q 'BUILD_TIME=' '$PROJECT_ROOT/scripts/build-analyze.sh'"
[ "$status" -eq 0 ]
}
@test "setup-quick-launchers.sh has detect_mo function" {
# Don't actually run the script - it opens Raycast and creates files
# Just verify it contains the detection logic
run bash -c "grep -q 'detect_mo()' '$PROJECT_ROOT/scripts/setup-quick-launchers.sh'"
[ "$status" -eq 0 ]
}
@test "setup-quick-launchers.sh has Raycast script generation" {
# Don't actually run the script - it opens Raycast
# Just verify it contains Raycast workflow creation logic
run bash -c "grep -q 'create_raycast_commands' '$PROJECT_ROOT/scripts/setup-quick-launchers.sh'"
[ "$status" -eq 0 ]
run bash -c "grep -q 'write_raycast_script' '$PROJECT_ROOT/scripts/setup-quick-launchers.sh'"
[ "$status" -eq 0 ]
# Check if scripts were created
[[ -f "$HOME/Library/Application Support/Raycast/script-commands/mole-clean.sh" ]] || \
[[ -f "$HOME/Documents/Raycast/Scripts/mole-clean.sh" ]]
}