diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | sam/.gitignore | 3 | ||||
| -rw-r--r-- | sam/Makefile | 12 | ||||
| -rw-r--r-- | sam/README.md | 41 | ||||
| -rwxr-xr-x | sam/test.sh | 72 |
6 files changed, 132 insertions, 1 deletions
@@ -1,12 +1,14 @@ test: @$(MAKE) -C core @$(MAKE) -C vim + @$(MAKE) -C sam @$(MAKE) -C vis @$(MAKE) -C lua clean: @$(MAKE) -C core clean @$(MAKE) -C vim clean + @$(MAKE) -C sam clean @$(MAKE) -C vis clean @$(MAKE) -C lua clean @@ -5,10 +5,11 @@ This repository contains testing infrastructure for the [vis editor](https://github.com/martanne/vis). It is expected to be cloned into a sub directory of the `vis` source tree. -There exist 4 different kinds of tests: +There exist 5 different kinds of tests: * `core` are C unit tests for core data structures used by vis * `vim` tests vim compatibility + * `sam` tests sam compatibility of the command language * `vis` contains tests for vis specific behavior/features * `lua` contains tests for the vis specific lua api diff --git a/sam/.gitignore b/sam/.gitignore new file mode 100644 index 0000000..589a89a --- /dev/null +++ b/sam/.gitignore @@ -0,0 +1,3 @@ +*.out +*.err +*.disabled
\ No newline at end of file diff --git a/sam/Makefile b/sam/Makefile new file mode 100644 index 0000000..3a91582 --- /dev/null +++ b/sam/Makefile @@ -0,0 +1,12 @@ +test: ../../vis + @./test.sh + +../../vis: ../../*.[ch] + @echo Compiling vis + @$(MAKE) -C ../.. + +clean: + @echo cleaning + @find . -name '*.out' -o -name '*.err' | xargs rm -f + +.PHONY: clean test diff --git a/sam/README.md b/sam/README.md new file mode 100644 index 0000000..935ed6e --- /dev/null +++ b/sam/README.md @@ -0,0 +1,41 @@ +Tests for vis - structural regular expression support +----------------------------------------------------- + +We test the structural regular expression implementation by supplying +the same command to both vis and [sam](http://sam.cat-v.org/). More +concretely we use `ssam(1)` the non-graphical streaming interface to +sam. These tests are intended to be run on a system with +[9base](http://tools.suckless.org/9base) or +[plan9port](https://swtch.com/plan9port/) installed. + +However, be aware that vis does deliberately not implement all commands +available in sam. Moreover, some language constructs have slightly +different semantics. Of particular relevance is the different grouping +implementation. In sam each command of a group is executed with +the same initial file state and all changes are later applied in parallel +(if no conflict occurred). Whereas vis applies the changes immediately +and subsequent commands will operate on the modified file content. +As a consequence the following snippet to swap two words does currently +not work in vis: + + ,x/[a-zA-Z]+/{ + g/Emacs/ v/....../ c/vi/ + g/vi/ v/.../ c/Emacs/ + } + +This is particularly relevant for the tests because they are all +executed in an implicit group. + +A test constitutes of 3 files, the first 2 of which are mandatory: + + * `test.in` the file/buffer content with which the editor is started + * `test.cmd` a file containing the structural regular expression + command as you would type it in vis at the `:`-prompt or pass to + `ssam(1)`. + * `test.ref` if omitted, the output from sam will be considered as + reference. + +The top level shell script `test.sh` looks for these files in sub +directories, executes both editors and compares the resulting output. + +Type `make` to run all tests. diff --git a/sam/test.sh b/sam/test.sh new file mode 100755 index 0000000..99d48cd --- /dev/null +++ b/sam/test.sh @@ -0,0 +1,72 @@ +#!/bin/sh + +NL=' +' +PLAN9="/usr/local/plan9/bin" + +[ -z "$VIS" ] && VIS="../../vis" +[ -z "$SSAM" ] && SSAM="$PLAN9/ssam" + +type "$SSAM" >/dev/null 2>&1 || { + echo "ssam(1) not found, skipping tests" + exit 0 +} + +TESTS=$1 +[ -z "$TESTS" ] && TESTS=$(find . -name '*.cmd' | sed 's/\.cmd$//g') + +TESTS_RUN=0 +TESTS_OK=0 + +$VIS -v + +for t in $TESTS; do + IN="$t.in" + CMD="$(cat $t.cmd)" + SAM_OUT="$t.sam.out" + SAM_ERR="$t.sam.err" + VIS_OUT="$t.vis.out" + VIS_ERR="$t.vis.err" + REF="$t.ref" + rm -f "$SAM_OUT" "$SAM_ERR" "$VIS_OUT" "$VIS_ERR" + printf "Running test %s with sam ... " "$t" + cat "$IN" | PATH="$PLAN9:$PATH" $SSAM "$CMD" > "$SAM_OUT" + if [ $? -ne 0 ]; then + printf "ERROR\n" + elif [ -e "$REF" ]; then + if cmp -s "$REF" "$SAM_OUT"; then + printf "OK\n" + else + printf "FAIL\n" + diff -u "$REF" "$SAM_OUT" > "$SAM_ERR" + fi + elif [ -e "$SAM_OUT" ]; then + REF="$SAM_OUT" + printf "OK\n" + fi + + if [ ! -e "$REF" ]; then + printf " No reference solution, skipping.\n" + continue + fi + + TESTS_RUN=$((TESTS_RUN+1)) + + printf "Running test %s with vis ... " "$t" + + cat "$IN" | $VIS "+{ $NL $CMD $NL wq! $NL }" - > "$VIS_OUT" + if [ $? -ne 0 ]; then + printf "ERROR\n" + elif cmp -s "$REF" "$VIS_OUT"; then + printf "OK\n" + TESTS_OK=$((TESTS_OK+1)) + else + printf "FAIL\n" + diff -u "$REF" "$VIS_OUT" > "$VIS_ERR" + fi +done + +printf "Tests ok %d/%d\n" $TESTS_OK $TESTS_RUN + +# set exit status +[ $TESTS_OK -eq $TESTS_RUN ] |
