run.sh 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env bash
  2. # Self-test for windows-ops — terminal-design adoption + (where pwsh exists)
  3. # runtime ASCII purity of the shared framing.
  4. #
  5. # Static checks run everywhere. The dynamic PowerShell checks need `pwsh`; on a
  6. # host without it (e.g. a Linux CI runner) they skip cleanly, like the mac-ops /
  7. # net-ops suites gate on their platform.
  8. #
  9. # Usage: bash tests/run.sh
  10. # Exit: 0 all pass (or dynamic checks skipped), 1 a failure
  11. set -uo pipefail
  12. HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  13. SKILL="$(dirname "$HERE")"
  14. SCRIPTS="$SKILL/scripts"
  15. COMMON="$SCRIPTS/_lib/common.ps1"
  16. TERMPS1="$SKILL/../_lib/term.ps1"
  17. PASS=0; FAIL=0
  18. ok(){ PASS=$((PASS+1)); printf ' PASS %s\n' "$1"; }
  19. no(){ FAIL=$((FAIL+1)); printf ' FAIL %s\n' "$1"; }
  20. echo "=== windows-ops self-test ==="
  21. # ── static: term.ps1 adoption (the lever for every script via common.ps1) ──
  22. echo "-- terminal design system --"
  23. grep -q 'term\.ps1' "$COMMON" && ok "common.ps1 sources shared term.ps1" || no "common.ps1 does not source term.ps1"
  24. [ -f "$TERMPS1" ] && ok "term.ps1 present" || no "term.ps1 missing at $TERMPS1"
  25. # Framing routes through term.ps1's Get-TermColor, not hand-rolled host coloring.
  26. grep -q 'Get-TermColor' "$COMMON" && ok "common.ps1 framing uses Get-TermColor" || no "common.ps1 does not use Get-TermColor"
  27. # ── dynamic: needs PowerShell; skip cleanly where absent ───────────────────
  28. PWSH=""
  29. for c in pwsh powershell; do command -v "$c" >/dev/null 2>&1 && { PWSH="$c"; break; }; done
  30. if [ -z "$PWSH" ]; then
  31. echo " (pwsh not found — skipping dynamic PowerShell checks)"
  32. echo "=== $PASS passed, $FAIL failed ==="
  33. [ "$FAIL" -eq 0 ] || exit 1
  34. exit 0
  35. fi
  36. # Resolve a path PowerShell can open (convert MSYS -> Windows when needed).
  37. winpath() { if command -v cygpath >/dev/null 2>&1; then cygpath -w "$1"; else printf '%s' "$1"; fi; }
  38. WCOMMON="$(winpath "$COMMON")"
  39. # common.ps1 framing is ASCII-pure under TERM_ASCII=1 FORCE_COLOR=1 (principle #3).
  40. out="$(TERM_ASCII=1 FORCE_COLOR=1 "$PWSH" -NoProfile -Command ". '$WCOMMON'; Write-Section 'DISK'; Write-Log PASS 'ok'; Write-Log FAIL 'bad'; Write-Log WARN 'hot'" 2>&1)"
  41. if printf '%s' "$out" | LC_ALL=C grep -q '[^[:print:][:cntrl:]]'; then
  42. no "common.ps1 framing emits non-ASCII under TERM_ASCII=1"
  43. else ok "common.ps1 framing pure ASCII under TERM_ASCII=1"; fi
  44. # Color is applied under FORCE_COLOR (ESC present).
  45. cout="$(FORCE_COLOR=1 "$PWSH" -NoProfile -Command ". '$WCOMMON'; Write-Log PASS 'ok'" 2>&1)"
  46. case "$cout" in *$'\033'*) ok "common.ps1 colorizes under FORCE_COLOR";; *) no "common.ps1 did not colorize under FORCE_COLOR";; esac
  47. # The [TAG] text stays literal/greppable (color is amplification, not the signal).
  48. case "$cout" in *'[PASS]'*) ok "common.ps1 keeps the [PASS] tag literal";; *) no "common.ps1 lost the [PASS] tag";; esac
  49. echo "=== $PASS passed, $FAIL failed ==="
  50. [ "$FAIL" -eq 0 ] || exit 1