3 # This script handles management of testing.
4 # It supports the creation, verification, and updating
7 # Tests are run in the context of an edlib git tree
8 # with a given hash - currently the same hash for all tests.
9 # Each test provides a list of keystrokes and mouse actions
10 # together with occasions checksums of the current display.
11 # We run a test and record the output at the same time, then
12 # confirm that the recording matching the input test.
16 # Record a new test and store it with given name. Then re-run and confirm.
17 # ./tests run [name|failed]
18 # If a name is given, just that test is run. If no name is given, all tests
19 # are run. If any test fails, that failure is recorded.
20 # If the special name 'failed' is given, then only failed tests are run.
22 # Run all tests and replace the test with the new log - expecting it to be different.
24 # Ensure configuration (e.g. of aspell) in $HOME doesn't affect result
27 # ensure timestamps don't change
28 export EDLIB_TESTING=1
29 # Don't check for autosaves
30 export EDLIB_AUTOSAVE=/no/autosave/dir
32 export TEST_DIR=/tmp/edlib-tests
33 export TEST_COMMIT=5875a3514f4e753fa183a2e19000e803384fae77
35 export ASPELL_CONF="personal $TEST_DIR/DOC/extra/aspell.en.pws;repl $TEST_DIR/DOC/extra/aspell.en.prepl"
40 new ) EDLIB_RECORD=$2 \
41 screen -m sh -c 'stty rows 30 cols 80; ./edlib $TEST_DIR'
43 run ) EDLIB_RECORD=$2 EDLIB_REPLAY=$3 \
44 screen -D -m sh -c 'stty rows 30 cols 80; ./edlib $TEST_DIR'
46 view ) EDLIB_RECORD=/dev/null EDLIB_REPLAY=$2 \
47 screen -m sh -c 'stty rows 30 cols 80; ./edlib $TEST_DIR'
49 extend ) EDLIB_RECORD=$2 EDLIB_REPLAY=$3 \
50 screen -m sh -c 'stty rows 30 cols 80; ./edlib $TEST_DIR'
58 if [ -d $TEST_DIR -a -d $TEST_DIR/.git ]; then
59 rm -rf $TEST_DIR/DOC/extra
60 (cd $TEST_DIR ; git reset > /dev/null --hard $TEST_COMMIT ;
61 git clean -fxd; git config core.abbrev 12 )
65 (cd $TEST_DIR ; git reset --hard $TEST_COMMIT; git config core.abbrev 12 )
67 rm -rf $TEST_DIR/DOC/extra
68 mkdir -p $TEST_DIR/DOC/extra
69 cp -a tests.d/[A-Za-z]* $TEST_DIR/DOC/extra
74 echo >&2 "$0: please provide name for new test"
79 [0-9][0-9]-* ) : OK ;;
80 * ) echo >&2 "Please name the test NN-something"
85 echo >&2 "$0: $tt already exists, please choose another name"
88 if ! touch "$tt"; then
89 echo >&2 "$0: Cannot create $tt - strange"
94 runtest new tests.d/.tmp
95 if ! grep -s '^Close' tests.d/.tmp > /dev/null ; then
96 echo >&2 "$0: test file not Closed - probably crash"
100 runtest run $tt tests.d/.tmp
101 diff -u tests.d/.tmp $tt
107 if [ $# -ne 1 ]; then
108 echo >&2 "$0: please provide name for test to extend"
113 if [ ! -e "$tt" ]; then
114 echo >&2 "$0: test $t doesn't exist"
117 rm -f tests.d/.tmp tests.d/.tmp2
118 # find :C-X :C-C that closes the editor.
119 n=$(grep -n 'Key ":C-X"' $tt | tail -n 1| sed 's/:.*//')
121 echo >&2 "$0: cannot find tailing :C-X"
124 head -n $[n-1] $tt > tests.d/.tmp2
125 runtest extend tests.d/.tmp tests.d/.tmp2
126 if ! grep -s '^Close' tests.d/.tmp > /dev/null ; then
127 echo >&2 "$0: test file not Closed - probably crash"
131 runtest run $tt tests.d/.tmp
132 #diff -u tests.d/.tmp $tt
133 rm -f tests.d/.tmp tests.d/.tmp2
138 if [ ! -f "tests.d/$1" ]; then
139 echo "$cmd: test $1 doesn't exist"
145 runtest run tests.d/.out tests.d/$1
146 if diff -u "tests.d/$1" tests.d/.out;
147 then echo "succeeded."
150 line=`diff tests.d/$1 tests.d/.out | sed -n '1s/^\([0-9]*\).*/\1/p'`
151 echo "Use: ./tests view $1 $line"
157 if [ $# -gt 1 ]; then
158 echo >&2 "$0: please provide at most one test to run"
162 if [ $# -eq 0 ]; then
163 for f in tests.d/[0-9]*; do
166 if [ $exit_code -gt 0 ]; then
167 if [ "x$b" = "x02-grep" ]; then
168 echo "02-grep failure NOT fatal"
175 elif [ " $1" = " -a" ]; then
176 for f in tests.d/[0-9]*; do
189 if [ ! -f "$f" ]; then
190 echo >&2 "Cannot find test $f"
194 # ensure we see delayed updates
195 export EDLIB_REPLAY_DELAY=500
196 #grep -v '^Display' $f > tests.d/.in
198 runtest run tests.d/.out tests.d/.in
206 if [ ! -f "$f" ]; then
207 echo >&2 "Cannot find test $f"
211 runtest run tests.d/.out "tests.d/$1"
212 mv tests.d/.out tests.d/"$1"
217 1:-f:* ) tst=""; cmd=refresh_one_fast ;;
218 1:* ) tst=$1; cmd=refresh_one ;;
219 2:*:-f ) tst=$1; cmd=refresh_one_fast ;;
220 0: ) tst=""; cmd=refresh_one ;;
222 echo >&2 "$0: please provide at most one test to refresh"
225 if [ -z "$tst" ]; then
226 for f in tests.d/[0-9]*; do
235 if [ $# -lt 1 ]; then
236 echo >&2 "$0: please provide a test name to view"
240 if [ ! -f tests.d/$1 ]; then
241 echo >&2 "Test $1 doesn't exist."
244 if [ $# -ge 2 -a " $2" != " -" ]; then
245 head -n $2 tests.d/$t > tests.d/.in
247 cat tests.d/$t > tests.d/.in
250 if [ $# -ge 3 ]; then
253 export EDLIB_REPLAY_DELAY=$delay
254 runtest view tests.d/.in
262 new) new_test ${1+"$@"};;
263 run) setup_test_dir; run_tests ${1+"$@"};;
264 refresh) setup_test_dir; refresh_tests ${1+"$@"};;
265 view ) setup_test_dir; view_test ${1+"$@"};;
266 extend ) setup_test_dir; extend_test ${1+"$@"};;
268 echo >&2 "Usage: $0 new test-name"
269 echo >&2 " $0 run [test-name|-a]"
270 echo >&2 " $0 refresh [test-name]"
271 echo >&2 " $0 view test-name [lines [delay-ms]]"
272 echo >&2 " $0 extend test-name"