#!/bin/sh # Usage: testscript ARCHIVE_PATH [COUNT] # # Start Emacs and test ‘file-directory-p’ on ARCHIVE_PATH. # # Each time before using ‘file-directory-p’, add # # (cons (tramp-archive-autoload-file-name-handler) # #'tramp-archive-autoload-file-name-handler) # # to ‘file-name-handler-alist’. ‘file-directory-p’ is called twice. # # Do this for COUNT times or just once if COUNT is not provided # # ARCHIVE_PATH defaults to # ~/"src/emacs/test/lisp/net/tramp-archive-resources/foo.iso/". # Emacs -nw switch: do not create a GUI frame. nw=-nw archive_path=${1:-~/"src/emacs/test/lisp/net/tramp-archive-resources/foo.iso/"} if ! [ -e "$archive_path" ] then printf '"%s" does not exist' "$archive_path" >&2 exit 66 # EX_NOINPUT fi count=${2:-1} run_emacs () { emacs $nw -Q -l tramp \ --eval \ '(setq command-error-function ;; Catch an error in a process filter. (lambda () (kill-emacs 1)))' \ --eval \ "(add-to-list 'file-name-handler-alist (cons (tramp-archive-autoload-file-name-regexp) #'tramp-archive-autoload-file-name-handler))" \ --eval \ '(let ((ret 2)) (unwind-protect (setq ret (if (file-directory-p "'"$archive_path"'") ;; either result counts as success 0 0)) (kill-emacs ret)))' \ --eval \ "(add-to-list 'file-name-handler-alist (cons (tramp-archive-autoload-file-name-regexp) #'tramp-archive-autoload-file-name-handler))" \ --eval \ '(let ((ret 3)) (unwind-protect (setq ret (if (file-directory-p "'"$archive_path"'") ;; either result counts as success 0 0)) (kill-emacs ret)))' } i=0 while [ "$i" -lt "$count" ] do i=$(( i + 1 )) run_emacs ret=$? case $ret in 0) # All good, just continue ;; 1) echo "‘command-error-function’ killed emacs" >&2 exit $ret ;; 2) echo "1. ‘unwind-protect’ killed emacs" >&2 exit $ret ;; 3) echo "2. ‘unwind-protect’ killed emacs" >&2 exit $ret ;; *) echo "Unexpected return code: $ret" >&2 exit $ret ;; esac done