From 8b0396a9ffda171d6f681f300e89a2ca02d0ed78 Mon Sep 17 00:00:00 2001 From: Tw93 Date: Wed, 19 Nov 2025 10:07:20 +0800 Subject: [PATCH] Automated test speed fix --- bin/analyze-go | Bin 7248322 -> 7248322 bytes mole | 4 +-- tests/cli.bats | 15 +++++---- tests/scripts.bats | 76 ++++++++++++++++++--------------------------- 4 files changed, 41 insertions(+), 54 deletions(-) diff --git a/bin/analyze-go b/bin/analyze-go index 2c472a74c6d4a9fb9d360e5dd99665d9ee94ab61..ee3b9a0cf05a19e8290467818c106129296aaeaa 100755 GIT binary patch delta 1165 zcmb`_NlX&~6b9g+B8c0dqKJSaDgs(N?R1$zi$#RCv_O|(s|ZXxZL!dnGF?XTP&L}P z#28J)gT}-y#)C_Yj!_a3Me$(N#KeP%9=y>QPndX6{EZh6o{Wd@@(wS5-v7q$JeWNW zx0pg=9~bvu3abakM~Is84`<@HRrhmFkwp7o$Dmo_hr}KerIYLdTTm5EC^aE-Q(WX) zt@?Js;&k_!1xZkblGb>n-yeaOD_*B%LQ}O4B_0b+b%L+8Z2p*nR3to!WdHu9XqxFw`+v_OJ z*0R+aYNUABu_;}iDS}l{3?)zstAT_yPzGyZ9ju3P*Z>t!301HWe(h4o<(bXCL;pW! zR8pp+5(O$y0}UF`f=-S~`VB2aOzO%Uwd)F}qRi-yiO-MaYtQw4xh`JS*JK?MEf!ik z5OKPA-a^Hcd-QQ@pt0FyjW|05!Q!e{n}f>!kkrgc4GGHL%GvD6CRdo_m8Pg-FCP@m z+nGdMYfXsypeB~~zSaW+EL6i5*a`-yfo))fTG$SCumkF$0Zd>93p9ciY|sSF&?0+Z z+rMA@%Ppg#qxYXGPor{hf(tlkg*Ir14(J3o?1V1Z1>MjCy}*M9ydcQM!@fxU|4jJ% zDaA=&TAcJl0Qz7z1fd@WWN|VS5sYPZM9gsIz}G9`1NYt}r|XVcma=b;X1(`5W_D68 zLwD5;diqhep=MR-SuXEH%J|kW`s3mLu5;Iyd`wRTf=}f#MVO??k{4GmyIP#wa)+m delta 1165 zcmb`_TS!v@7zc1tYi76U($uU@W?s^@?VO$MXr*oHGNc#kS_)yL^ldfq@Wm;_2Pm+BLF@$F zW>SUhO;bZ@0G7?{NeflUT0zS#)m3PDxBvUR66shUB!@+G0_5cZpk7nF+*? zi!7OTG)zRo#1e>sScrqAunYtc56d9|R=`SF1*>5V2q6)YKm=98I$U;}J~O+dhA$b>DB1zRB-av&G-U>oGauU%q3dv1H<@&6w) z5Rya!At}g!1PbIpgMtr)lsP)#V`Y2V%=40=m$9QS#^{KEAAX{2iZ^jKjghRe8oAC^ zRkdCp(3gkWBnD%Po2v9k)!nT75bd;)ZHGvS#~Z3KhcsPMeXY4l-(79;nORATxyIDi zrBhN`O;3|wRcQBjP!TSw1O^JB2zJ0u*agK<0=q#4YAA&=CKQ z@my5@edsT@3+3>yo6GA>y>?0_m!t-Hd*7HpC zy4j!iG^k>aC2t%2!h#Qf#WH UW8X>>^KTT&W*_k}r+nkWpFxeb$N&HU diff --git a/mole b/mole index b928289..5aa35ad 100755 --- a/mole +++ b/mole @@ -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 diff --git a/tests/cli.bats b/tests/cli.bats index 6a08a8d..997932f 100644 --- a/tests/cli.bats +++ b/tests/cli.bats @@ -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 diff --git a/tests/scripts.bats b/tests/scripts.bats index 395127a..95604cc 100644 --- a/tests/scripts.bats +++ b/tests/scripts.bats @@ -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" ]] }