comptestinit () { setopt extendedglob [[ -d $ZTST_testdir/Modules/zsh ]] && module_path=( $ZTST_testdir/Modules ) fpath=( $ZTST_srcdir/../Functions/*~*/CVS(/) $ZTST_srcdir/../Completion $ZTST_srcdir/../Completion/*/*~*/CVS(/) ) zmodload -i zsh/zpty || return $? comptest_zsh=${ZSH:-zsh} comptest_keymap=e while getopts vz: opt; do case $opt in z) comptest_zsh="$OPTARG";; v) comptest_keymap="v";; esac done (( OPTIND > 1 )) && shift $(( OPTIND - 1 )) export PS1="" zpty zsh "$comptest_zsh -f +Z" zpty -r zsh log1 "**" || { print "first prompt hasn't appeared." return 1 } comptesteval \ "export LC_ALL=C" \ "emulate -R zsh" \ "export ZDOTDIR=$ZTST_testdir" \ "module_path=( $module_path )" \ "fpath=( $fpath )" \ "bindkey -$comptest_keymap" \ 'LISTMAX=10000000 TERM=vt100 stty columns 80 rows 24 setopt zle autoload -U compinit compinit -u zstyle ":completion:*:default" list-colors "no=" "fi=" "di=" "ln=" "pi=" "so=" "bd=" "cd=" "ex=" "mi=" "tc=" "sp=" "lc=" "ec=\n" "rc=" zstyle ":completion:*" group-name "" zstyle ":completion:*:messages" format "%d " zstyle ":completion:*:descriptions" format "%d " zstyle ":completion:*:options" verbose yes zstyle ":completion:*:values" verbose yes setopt noalwayslastprompt listrowsfirst completeinword zmodload zsh/complist expand-or-complete-with-report () { print -lr "" zle expand-or-complete print -lr - "$LBUFFER" "$RBUFFER" zle clear-screen zle -R } list-choices-with-report () { print -lr "" zle list-choices zle clear-screen zle -R } comp-finish () { print "" zle kill-whole-line zle clear-screen zle -R } zle-finish () { print -lr "" "BUFFER: $BUFFER" "CURSOR: $CURSOR" (( region_active )) && print -lr "MARK: $MARK" zle -K main zle kill-whole-line zle clear-screen zle -R } zle -N expand-or-complete-with-report zle -N list-choices-with-report zle -N comp-finish zle -N zle-finish bindkey "^I" expand-or-complete-with-report bindkey "^D" list-choices-with-report bindkey "^Z" comp-finish bindkey "^M" zle-finish bindkey -a "^M" zle-finish ' } comptesteval () { local tmp=/tmp/comptest.$$ print -lr - "$@" > $tmp zpty -w zsh ". $tmp" zpty -r -m zsh log_eval "**" || { print "prompt hasn't appeared." return 1 } rm $tmp } comptest () { input="$*" zpty -n -w zsh "$input"$'\C-Z' zpty -r -m zsh log "***" || { print "failed to invoke finish widget." return 1 } logs=(${(s::)log}) shift logs for log in "$logs[@]"; do if [[ "$log" = (#b)*$''(*)$'\r\n'(*)$''* ]]; then print -lr "line: {$match[1]}{$match[2]}" fi while (( ${(N)log#*(#b)(<(??)>(*)|(*)|(*)|(*)|(*))} )); do log="${log[$mend[1]+1,-1]}" if (( 0 <= $mbegin[2] )); then if [[ $match[2] != TC && $match[3] != \ # ]]; then print -lr "$match[2]:{${match[3]%${(%):-%E}}}" fi elif (( 0 <= $mbegin[4] )); then print -lr "DESCRIPTION:{$match[4]}" elif (( 0 <= $mbegin[5] )); then print -lr "MESSAGE:{$match[5]}" elif (( 0 <= $mbegin[6] )); then print -lr "COMPADD:{${${match[6]}//[$'\r\n']/}}" elif (( 0 <= $mbegin[7] )); then print -lr "INSERT_POSITIONS:{${${match[7]}//[$'\r\n']/}}" fi done done } zletest () { input="$*" zpty -n -w zsh "$input"$'\C-M' zpty -r -m zsh log "***" || { print "failed to invoke finish widget." return 1 } print -lr "${(@)${(ps:\r\n:)log##*}[1,-2]}" }