diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-11-02 23:17:57 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-11-03 23:28:15 +0100 |
| commit | d5075cfdb093af473dea17f4d492da4afb105b13 (patch) | |
| tree | 3e8003ae74eee853a4f8fcf6036374e2da68423e /sam | |
| parent | 9d0ea4418257df19709d8984ced4c63b9b1a2bab (diff) | |
| download | vis-d5075cfdb093af473dea17f4d492da4afb105b13.tar.gz vis-d5075cfdb093af473dea17f4d492da4afb105b13.tar.xz | |
test/sam: add sam testing infrastructure
Compare structural regular expression implementation
with the one of sam(1).
Diffstat (limited to 'sam')
| -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 |
4 files changed, 128 insertions, 0 deletions
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 ] |
