SPB Git

Repository Public

smoke.sh 7.0 KB 115 lines shellscript

1#!/bin/bash2# End-to-end smoke test of the real application, driven through System Events (XCUITest cannot3# enable automation mode on Xcode 27.2 / macOS 27.0). Every check is observed outside the app:4# files written by commands typed into panes, window counts, the saved layout file.5#   Scripts/smoke.sh [path/to/SP Term.app]6# Requires: Accessibility permission for the program running this script.7set -uo pipefail8cd "$(dirname "$0")/.."9APP="${1:-build/DerivedData/Build/Products/Debug/SP Term.app}"10W="/tmp/spterm-smoke"; DATA="$W/data"11pass=0; fail=012ok()   { echo "  PASS  $1"; pass=$((pass+1)); }13bad()  { echo "  FAIL  $1"; fail=$((fail+1)); }14check() { if eval "$2"; then ok "$1"; else bad "$1"; fi; }15waitfor() { local i=0; until eval "$1"; do sleep 0.2; i=$((i+1)); [ $i -gt ${2:-40} ] && return 1; done; }16windows() { osascript -e 'tell application "System Events" to count windows of process "SP Term"' 2>/dev/null || echo 0; }17d() { Scripts/drive.sh "$@"; }1819pkill -x "SP Term" 2>/dev/null20waitfor "! pgrep -x \"SP Term\" >/dev/null" 50; sleep 0.521rm -rf "$W"; mkdir -p "$W/dir with space"22# Helper run inside panes: records facts about the session without needing shell characters that23# System Events cannot type on every keyboard layout (| > ~ [ ]).24cat > "$W/rec" <<'H'25#!/bin/sh26{ echo "tty=$(tty)"; echo "pwd=$(pwd -P)"; echo "term=$TERM"; echo "colorterm=$COLORTERM"; echo "program=$TERM_PROGRAM"; echo "size=$(stty size)"; echo "shell=$SHELL"; echo "pgid_ok=$(ps -o tpgid= -p $$ | tr -d ' ')"; } > "/tmp/spterm-smoke/$1.txt"27H28chmod +x "$W/rec"29echo 'import sys; open("/tmp/spterm-smoke/py.txt", "w").write(str(sys.stdin.isatty() and sys.stdout.isatty()))' > "$W/tty.py"30val() { sed -n "s/^$2=//p" "$W/$1.txt" 2>/dev/null; }3132echo "== Launch"33open "$APP" --args -SPTermDataDir "$DATA" -SPTermFresh 134waitfor "[ \"\$(windows)\" -ge 1 ]" 5035check "application starts and shows one window (found $(windows))" '[ "$(windows)" = 1 ]'36sleep 1.53738echo "== Interactive shell on a real PTY"39d type "$W/rec a"40check "a command typed in the window runs in the shell" 'waitfor "[ -f $W/a.txt ]"'41check "stdin is a tty device" '[[ "$(val a tty)" == /dev/ttys* ]]'42check "TERM / COLORTERM / TERM_PROGRAM are set" '[ "$(val a term)" = xterm-256color ] && [ "$(val a colorterm)" = truecolor ] && [ "$(val a program)" = SPTerm ]'43check "the shell has job control on its terminal" '[ "$(val a pgid_ok)" -gt 0 ]'44check "the kernel TTY size is plausible ($(val a size))" '[ "$(val a size | cut -d" " -f2)" -gt 40 ]'4546echo "== Ctrl+C, Ctrl+D, full-screen programs"47d type "sleep 300"; d key c control; d type "$W/rec after-ctrl-c"48check "Ctrl+C interrupts the foreground command and the prompt returns" 'waitfor "[ -f $W/after-ctrl-c.txt ]"'49d type "cat"; d type "echo-line"; d key d control; d type "$W/rec after-ctrl-d"50check "Ctrl+D sends end-of-file to the foreground program" 'waitfor "[ -f $W/after-ctrl-d.txt ]"'51d type "vim -u NONE $W/vim.txt"; sleep 0.8; d text "iwritten by vim"; d code 53; d type ":wq"52check "vim edits and saves a file" 'waitfor "grep -q \"written by vim\" $W/vim.txt 2>/dev/null"'53# If a keystroke was lost, leave vim anyway so that the next checks are not affected.54d code 53; d type ":q!"55d type "top"; sleep 1.5; d text "q"; d type "$W/rec after-top"56check "top runs full screen and quits cleanly" 'waitfor "[ -f $W/after-top.txt ]"'57d text "q"; d key c control58d type "less /etc/shells"; sleep 0.6; d text "q"; d type "$W/rec after-less"59check "less (alternate screen) returns to the shell" 'waitfor "[ -f $W/after-less.txt ]"'60d text "q"; d key c control61d type "python3 $W/tty.py"62check "python sees an interactive terminal" 'waitfor "[ \"\$(cat $W/py.txt 2>/dev/null)\" = True ]"'6364echo "== Panes"65d key d command; d type "$W/rec b"66d key d command,shift; d type "$W/rec c"67check "split right and split down create two more sessions" 'waitfor "[ -f $W/b.txt ] && [ -f $W/c.txt ]"'68check "each pane has its own PTY" '[ "$(cat $W/a.txt $W/b.txt $W/c.txt | grep ^tty= | sort -u | wc -l | tr -d " ")" = 3 ]'69d code 123 command,option; d type "$W/rec back-in-a"70check "keyboard focus navigation returns to the first pane" 'waitfor "[ -f $W/back-in-a.txt ]" && [ "$(val back-in-a tty)" = "$(val a tty)" ]'71before="$(val back-in-a size)"72d code 36 command,shift; sleep 0.6; d type "$W/rec zoomed"73check "zoom gives the pane the whole tab (size $before → $(val zoomed size))" 'waitfor "[ -f $W/zoomed.txt ]" && [ "$(val zoomed size | cut -d" " -f2)" -gt "$(echo $before | cut -d" " -f2)" ]'74d code 36 command,shift7576echo "== Tabs and windows"77d key t command; d type "$W/rec tab2"78check "a new tab starts a new session" 'waitfor "[ -f $W/tab2.txt ]" && [ "$(val tab2 tty)" != "$(val a tty)" ]'79d key n command80check "a new window opens" 'waitfor "[ \"\$(windows)\" = 2 ]"'81d type "cd '$W/dir with space'"; d key d command; d type "$W/rec inherit"82check "a split inherits the working directory" 'waitfor "[ -f $W/inherit.txt ]" && [[ "$(val inherit pwd)" == *"dir with space" ]]'83open -a "$PWD/$APP" "$W/dir with space"; sleep 2; d type "$W/rec opened-folder"84check "opening a folder with the app starts a session there" 'waitfor "[ -f $W/opened-folder.txt ]" && [[ "$(val opened-folder pwd)" == *"dir with space" ]]'85check "three windows are open" '[ "$(windows)" = 3 ]'8687echo "== Full screen"88d key f command,control; sleep 2.5; d type "$W/rec fullscreen"89check "the session keeps working in native full screen ($(val fullscreen size))" 'waitfor "[ -f $W/fullscreen.txt ]"'90d key f command,control; sleep 2.59192echo "== Window resize"93osascript -e 'tell application "System Events" to tell process "SP Term" to set size of window 1 to {700, 420}' >/dev/null 2>&1; sleep 0.894d type "$W/rec small"95osascript -e 'tell application "System Events" to tell process "SP Term" to set size of window 1 to {1250, 760}' >/dev/null 2>&1; sleep 0.896d type "$W/rec large"97check "resizing the window resizes the TTY ($(val small size) → $(val large size))" 'waitfor "[ -f $W/large.txt ]" && [ "$(val large size | cut -d" " -f2)" -gt "$(val small size | cut -d" " -f2)" ]'9899echo "== Quit and restore"100osascript -e 'tell application "SP Term" to quit'101check "the application quits when its sessions are idle" 'waitfor "! pgrep -x \"SP Term\" >/dev/null" 30'102check "no shell of the app is left behind" '! ps -o tty= -ax | grep -q "$(basename "$(val a tty)")\$"'103check "the layout was saved with three windows" '[ "$(python3 -c "import json;print(len(json.load(open(\"$DATA/last-session.json\"))[\"payload\"][\"windows\"]))" 2>/dev/null)" = 3 ]'104check "data files are private (0600 in a 0700 folder)" '[ "$(stat -f %Lp "$DATA")" = 700 ] && [ "$(stat -f %Lp "$DATA/last-session.json")" = 600 ]'105open "$APP" --args -SPTermDataDir "$DATA"106waitfor "[ \"\$(windows)\" -ge 3 ]" 50107check "relaunch restores the three windows (found $(windows))" '[ "$(windows)" = 3 ]'108sleep 1.5; d type "$W/rec restored"109check "restored sessions are new processes in the saved directory" 'waitfor "[ -f $W/restored.txt ]" && [[ "$(val restored pwd)" == *"dir with space" ]]'110osascript -e 'tell application "SP Term" to quit'; sleep 1.5111112echo113echo "RESULT: $pass passed, $fail failed"114[ $fail -eq 0 ]115
Files main
Menu

Theme