#!/bin/bash # Test whether condition-wait is interruptible by C-g. # # This script requires two tools: xdotool and dotool. # # xdotool: is included in Debian # # dotool: I installed it manually from https://git.sr.ht/~geb/dotool. # As dotool requires permissions to access /dev/input, I use sudo to # run it. # # The script output follows TAP syntax (https://testanything.org/) and # could be parsed for example with prove(1). set -o errexit # Ask sudo password now and remember it for later sudo dotool --version >/dev/null TMPFILE=$(mktemp) TESTNR=0 function check { local PROG="$1" FUN="$2" READYMSG="$3" $PROG -Q -l wait.el --eval "($FUN \"$TMPFILE\")" & local EMACSPID=$! trap "rm -f $TMPFILE; kill $EMACSPID 2>/dev/null || :" EXIT # Wait until Emacs is ready until [ "$(cat $TMPFILE)" == "$READYMSG" ] ; do sleep 0.2 done # Set focus on Emacs xdotool search --sync --onlyvisible --all \ --pid $EMACSPID --name '' windowfocus # Send C-g to input device echo 'key ctrl+g' | sudo dotool wait $EMACSPID DESC="$TESTNR - $PROG $FUN" case "$(cat $TMPFILE)" in QUIT | QUIT1 | QUIT2) echo ok $DESC;; *) cat $TMPFILE >2 echo not ok $DESC ;; esac } declare -a PROGS PROGS=(emacs 'xterm -e emacs -nw') declare -A READYMSGS READYMSGS=( [wait-forever]=WAITING [spawn-child-then-wait]='WAITING1 TERMINATING2' [two-threads-waiting]='WAITING1 WAITING2' ) echo 1..$((${#PROGS[@]} * ${#READYMSGS[@]})) for prog in "${PROGS[@]}" ; do for fun in "${!READYMSGS[@]}" ; do TESTNR=$(($TESTNR + 1)) check "$prog" $fun "${READYMSGS[$fun]}" done done