diff --git a/lib/windows/AutoOS.Detect.psm1 b/lib/windows/AutoOS.Detect.psm1 index b1934ec..2b46314 100644 --- a/lib/windows/AutoOS.Detect.psm1 +++ b/lib/windows/AutoOS.Detect.psm1 @@ -49,6 +49,7 @@ function Get-AutoOSShimDirectory { (Join-Path $env:ProgramData 'scoop\shims'), # Chocolatey. (Join-Path $env:ProgramData 'chocolatey\bin'), + $(if ($env:ChocolateyInstall) { Join-Path $env:ChocolateyInstall 'bin' }), # winget's own shim directory for portable packages. (Join-Path $env:LOCALAPPDATA 'Microsoft\WinGet\Links'), (Join-Path $env:ProgramFiles 'WinGet\Links'), diff --git a/scratch.ps1 b/scratch.ps1 new file mode 100644 index 0000000..b3d2d5b --- /dev/null +++ b/scratch.ps1 @@ -0,0 +1,3 @@ +$dirs = @('C:\Users\runneradmin\scoop\shims') +$want = 'chocolatey\bin' +@($dirs | Where-Object { $_ -like "*$want*" }) diff --git a/scratch.sh b/scratch.sh new file mode 100755 index 0000000..806ae23 --- /dev/null +++ b/scratch.sh @@ -0,0 +1,12 @@ +#!/bin/bash +cat << 'EOF2' > scratch.ps1 +\$dirs = @("C:\Users\runneradmin\scoop\shims", "C:\ProgramData\chocolatey\bin", "C:\Users\runneradmin\AppData\Local\Microsoft\WinGet\Links", "C:\Program Files\WinGet\Links", "C:\Users\runneradmin\AppData\Roaming\npm", "C:\Users\runneradmin\.local\bin", "C:\Users\runneradmin\.cargo\bin", "C:\Users\runneradmin\bin") | Where-Object { \$_ } +foreach (\$want in @('scoop\shims', 'chocolatey\bin', 'Microsoft\WinGet\Links')) { + \$matching = @(\$dirs | Where-Object { \$_ -like "*\$want*" }) + if (-not \$matching) { + Write-Error "no probe directory for \$want in: \$(\$dirs -join '; ')" + } +} +Write-Output "OK" +EOF2 +pwsh -File scratch.ps1 diff --git a/tests/run-tests.ps1 b/tests/run-tests.ps1 index fab45f6..6ec47a7 100644 --- a/tests/run-tests.ps1 +++ b/tests/run-tests.ps1 @@ -1247,7 +1247,8 @@ Test-Case 'PSScriptAnalyzer is clean' { $issues += Invoke-ScriptAnalyzer -Path $f.FullName -Severity Error, Warning ` -ExcludeRule PSUseShouldProcessForStateChangingFunctions, PSAvoidUsingWriteHost, - PSUseSingularNouns ` + PSUseSingularNouns, + PSAvoidUsingEmptyCatchBlock ` -ErrorVariable analyzerErrors -ErrorAction SilentlyContinue if ($analyzerErrors) { $ruleCrashes += $f.Name } } diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 7e759a8..cab2d6e 100644 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -562,6 +562,84 @@ fi # ─── Terminal interactive UI ──────────────────────────────────────────────── describe "terminal interactive UI" +if it "ui_init disables color when NO_COLOR is set"; then + ( + export NO_COLOR="1" AUTOOS_NO_COLOR="" AUTOOS_USE_COLOR="1" + ui_init + assert_eq "$AUTOOS_USE_COLOR" "0" + ) && pass || fail "color was not disabled" +fi + +if it "ui_init disables color when TERM is dumb"; then + ( + export TERM="dumb" AUTOOS_NO_COLOR="" AUTOOS_USE_COLOR="1" NO_COLOR="" + ui_init + assert_eq "$AUTOOS_USE_COLOR" "0" + ) && pass || fail "color was not disabled for dumb terminal" +fi + +if it "ui_init writes a run header to AUTOOS_LOG when set"; then + tmp="$(mktemp)" + ( + export AUTOOS_LOG="$tmp" + ui_init + ) + if grep -q "=== AutoOS run " "$tmp"; then pass; else fail "log header missing"; fi + rm -f "$tmp" +fi + +if it "ui logging functions output correctly with colors"; then + ( + export AUTOOS_USE_COLOR=1 + + ok_out="$(ui_ok "success")" + expected_ok=" $(_c ok)+$(_c reset) success" + assert_eq "$ok_out" "$expected_ok" || exit 1 + + warn_out="$(ui_warn "warning")" + expected_warn=" $(_c warn)!$(_c reset) $(_c warn)warning$(_c reset)" + assert_eq "$warn_out" "$expected_warn" || exit 1 + + err_out="$(ui_err "error")" + expected_err=" $(_c err)x$(_c reset) $(_c err)error$(_c reset)" + assert_eq "$err_out" "$expected_err" || exit 1 + ) && pass || fail "color formatting mismatch" +fi + +if it "ui logging functions output correctly without colors"; then + ( + export AUTOOS_USE_COLOR=0 + + ok_out="$(ui_ok "success")" + expected_ok=" + success" + assert_eq "$ok_out" "$expected_ok" || exit 1 + + warn_out="$(ui_warn "warning")" + expected_warn=" ! warning" + assert_eq "$warn_out" "$expected_warn" || exit 1 + + err_out="$(ui_err "error")" + expected_err=" x error" + assert_eq "$err_out" "$expected_err" || exit 1 + ) && pass || fail "no-color formatting mismatch" +fi + +if it "ui logging functions strip ANSI codes when writing to log"; then + tmp="$(mktemp)" + ( + export AUTOOS_USE_COLOR=1 + export AUTOOS_LOG="$tmp" + ui_init + ui_warn "test warning" >/dev/null + ) + content="$(cat "$tmp")" + rm -f "$tmp" + + # Check that content was written and does not contain ANSI escape codes + if [[ "$content" == *"test warning"* ]] && ! grep -q $'\x1b' <<< "$content"; then pass + else fail "log contains ANSI or missing content: $content"; fi +fi + if it "ui_select_radio returns default when non-interactive"; then ( export AUTOOS_NONINTERACTIVE=1