vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit baecbc4a5773150bc83abb33a460423c84e78cfe
parent d8f5e22657af8c16539d2be42cf4af3e7cb12c33
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Wed, 16 Nov 2016 22:22:49 +0100

test/vis: convert vis specific tests to use the Lua API

Instead of using the keys utility to convert the textual key representation
into something a terminal would send and then pipe it to vis' standard input
use the Lua API to directly feed the keys into vis' input queue.

This has a number of advantages:

 - it is less fragile: the keys utility is incomplete and only handles the
   most common keys

 - it is faster because there is no need to artificially delay input
   after an <Escape> key to give vis a chance to distinguish between
   a single <Escape> and the start of an escape sequence

Diffstat:
Mvis/Makefile | 5+----
Mvis/test.sh | 42++++++++++++++++++++++++------------------
Avis/visrc.lua | 17+++++++++++++++++
3 files changed, 42 insertions(+), 22 deletions(-)

diff --git a/vis/Makefile b/vis/Makefile @@ -1,13 +1,10 @@ -test: ../../vis ../util/keys +test: ../../vis clean @./test.sh ../../vis: ../../*.[ch] @echo Compiling vis @$(MAKE) -C ../.. -../util/keys: ../util/keys.c - @$(MAKE) -C ../util - clean: @echo cleaning @find . -name '*.out' -o -name '*.err' | xargs rm -f diff --git a/vis/test.sh b/vis/test.sh @@ -1,31 +1,37 @@ #!/bin/sh [ -z "$VIS" ] && VIS="../../vis" +$VIS -v -TESTS=$1 -[ -z "$TESTS" ] && TESTS=$(find . -name '*.keys' | sed 's/\.keys$//g') - -TESTS_RUN=0 TESTS_OK=0 +TESTS_RUN=0 -$VIS -v +if [ $# -gt 0 ]; then + test_files=$* +else + printf ':help\n:/ Lua paths/,$ w help\n:qall\n' | $VIS 2> /dev/null && cat help && rm -f help + test_files="$(find . -type f -name '*.in')" +fi + +export VIS_PATH=. + +for t in $test_files; do + TESTS_RUN=$((TESTS_RUN + 1)) + t=${t%.in} + t=${t#./} + $VIS "$t".in < /dev/null 2> /dev/null -for t in $TESTS; do - ERR="$t.err" - OUT="$t.out" - REF="$t.ref" - printf "Running test %s ... " "$t" - rm -f "$OUT" "$ERR" - { cat "$t.keys"; printf "<Escape>:wq! $OUT<Enter>"; } | cpp -P | ../util/keys | $VIS "$t.in" 2> /dev/null - if [ -e "$OUT" ]; then - if cmp -s "$REF" "$OUT"; then - printf "OK\n" - TESTS_OK=$((TESTS_OK+1)) + printf "%-50s" "$t" + if [ -e "$t".out ]; then + if cmp -s "$t".ref "$t".out 2> /dev/null; then + printf "PASS\n" + TESTS_OK=$((TESTS_OK + 1)) else printf "FAIL\n" - diff -u "$REF" "$OUT" > "$ERR" + diff -u "$t".ref "$t".out > "$t".err fi - TESTS_RUN=$((TESTS_RUN+1)) + else + printf "ERROR\n" fi done diff --git a/vis/visrc.lua b/vis/visrc.lua @@ -0,0 +1,17 @@ +vis.events = {} +vis.events.win_open = function(win) + -- test.in file passed to vis + local name = win.file.name + if name then + -- use the corresponding test.lua file + name = string.gsub(name, '%.in$', '') + local file = assert(io.popen(string.format("cpp -P '%s.keys'", name), 'r')) + local keys = file:read('*all') + keys = string.gsub(keys, '<Space>', ' ') + keys = string.gsub(keys, '\n', '') + file:close() + vis:feedkeys(keys..'<Escape>') + vis:command(string.format("w! '%s.out'", name)) + end + vis:command('q!') +end