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
38 new ) EDLIB_RECORD=$2 \
39 screen -m sh -c 'stty rows 30 cols 80; ./edlib $TEST_DIR'
41 run ) EDLIB_RECORD=$2 EDLIB_REPLAY=$3 \
42 screen -D -m sh -c 'stty rows 30 cols 80; ./edlib $TEST_DIR'
44 view ) EDLIB_RECORD=/dev/null EDLIB_REPLAY=$2 \
45 screen -m sh -c 'stty rows 30 cols 80; ./edlib $TEST_DIR'
47 extend ) EDLIB_RECORD=$2 EDLIB_REPLAY=$3 \
48 screen -m sh -c 'stty rows 30 cols 80; ./edlib $TEST_DIR'
56 if [ -d $TEST_DIR -a -d $TEST_DIR/.git ]; then
57 rm -rf $TEST_DIR/DOC/extra
58 (cd $TEST_DIR ; git reset > /dev/null --hard $TEST_COMMIT ;
59 git clean -fxd; git config core.abbrev 12 )
63 (cd $TEST_DIR ; git reset --hard $TEST_COMMIT; git config core.abbrev 12 )
65 rm -rf $TEST_DIR/DOC/extra
66 mkdir -p $TEST_DIR/DOC/extra
67 cp -a tests.d/[A-Za-z]* $TEST_DIR/DOC/extra
72 echo >&2 "$0: please provide name for new test"
77 [0-9][0-9]-* ) : OK ;;
78 * ) echo >&2 "Please name the test NN-something"
83 echo >&2 "$0: $tt already exists, please choose another name"
86 if ! touch "$tt"; then
87 echo >&2 "$0: Cannot create $tt - strange"
92 runtest new tests.d/.tmp
93 if ! grep -s '^Close' tests.d/.tmp > /dev/null ; then
94 echo >&2 "$0: test file not Closed - probably crash"
98 runtest run $tt tests.d/.tmp
99 diff -u tests.d/.tmp $tt
105 if [ $# -ne 1 ]; then
106 echo >&2 "$0: please provide name for test to extend"
111 if [ ! -e "$tt" ]; then
112 echo >&2 "$0: test $t doesn't exist"
115 rm -f tests.d/.tmp tests.d/.tmp2
116 # find :C-X :C-C that closes the editor.
117 n=$(grep -n 'Key ":C-X"' $tt | tail -n 1| sed 's/:.*//')
119 echo >&2 "$0: cannot find tailing :C-X"
122 head -n $[n-1] $tt > tests.d/.tmp2
123 runtest extend tests.d/.tmp tests.d/.tmp2
124 if ! grep -s '^Close' tests.d/.tmp > /dev/null ; then
125 echo >&2 "$0: test file not Closed - probably crash"
129 runtest run $tt tests.d/.tmp
130 #diff -u tests.d/.tmp $tt
131 rm -f tests.d/.tmp tests.d/.tmp2
136 if [ ! -f "tests.d/$1" ]; then
137 echo "$cmd: test $1 doesn't exist"
143 runtest run tests.d/.out tests.d/$1
144 if diff -u "tests.d/$1" tests.d/.out;
145 then echo "succeeded."
148 line=`diff tests.d/$1 tests.d/.out | sed -n '1s/^\([0-9]*\).*/\1/p'`
149 echo "Use: ./tests view $1 $line"
155 if [ $# -gt 1 ]; then
156 echo >&2 "$0: please provide at most one test to run"
160 if [ $# -eq 0 ]; then
161 for f in tests.d/[0-9]*; do
164 if [ $exit_code -gt 0 ]; then
165 if [ "x$b" = "x02-grep" ]; then
166 echo "02-grep failure NOT fatal"
173 elif [ " $1" = " -a" ]; then
174 for f in tests.d/[0-9]*; do
187 if [ ! -f "$f" ]; then
188 echo >&2 "Cannot find test $f"
192 # ensure we see delayed updates
193 export EDLIB_REPLAY_DELAY=500
194 #grep -v '^Display' $f > tests.d/.in
196 runtest run tests.d/.out tests.d/.in
204 if [ ! -f "$f" ]; then
205 echo >&2 "Cannot find test $f"
209 runtest run tests.d/.out "tests.d/$1"
210 mv tests.d/.out tests.d/"$1"
215 1:-f:* ) tst=""; cmd=refresh_one_fast ;;
216 1:* ) tst=$1; cmd=refresh_one ;;
217 2:*:-f ) tst=$1; cmd=refresh_one_fast ;;
218 0: ) tst=""; cmd=refresh_one ;;
220 echo >&2 "$0: please provide at most one test to refresh"
223 if [ -z "$tst" ]; then
224 for f in tests.d/[0-9]*; do
233 if [ $# -lt 1 ]; then
234 echo >&2 "$0: please provide a test name to view"
238 if [ ! -f tests.d/$1 ]; then
239 echo >&2 "Test $1 doesn't exist."
242 if [ $# -ge 2 -a " $2" != " -" ]; then
243 head -n $2 tests.d/$t > tests.d/.in
245 cat tests.d/$t > tests.d/.in
248 if [ $# -ge 3 ]; then
251 export EDLIB_REPLAY_DELAY=$delay
252 runtest view tests.d/.in
260 new) new_test ${1+"$@"};;
261 run) setup_test_dir; run_tests ${1+"$@"};;
262 refresh) setup_test_dir; refresh_tests ${1+"$@"};;
263 view ) setup_test_dir; view_test ${1+"$@"};;
264 extend ) setup_test_dir; extend_test ${1+"$@"};;
266 echo >&2 "Usage: $0 new test-name"
267 echo >&2 " $0 run [test-name|-a]"
268 echo >&2 " $0 refresh [test-name]"
269 echo >&2 " $0 view test-name [lines [delay-ms]]"
270 echo >&2 " $0 extend test-name"