]> git.lyx.org Git - features.git/blob - development/autotests/run-tests.sh
Added self-sanity-check for presence of pcregrep, otherwise many (almost all) tests...
[features.git] / development / autotests / run-tests.sh
1 #!/bin/bash
2
3 # This script runs all the test scripts it finds in the current folder
4 # Tests are identified as having a file name of *-in.txt
5 # For failed tests, the collected output is kept in the corresponding folder
6
7 export LYX_ROOT=../../..
8 export LYX_EXE=$LYX_ROOT/src/lyx
9
10 if [ "$XVKBD_HACKED" != "" ]; then
11     export XVKBD_EXE=${XVKBD:-./xvkbd/xvkbd};
12     if [ ! -x $XVKBD_EXE ]; then
13         echo "You need to build XVKBD first, try: cd xvkbd && xmkmf && make"
14         exit -1;
15     fi
16 fi
17
18 if [ "$(which wmctrl)" == "" ]; then
19     echo "You need to install wmctrl first, try:"
20     echo "  sudo apt-get install wmctrl"
21     exit -1;
22 fi
23
24 if [ "$(which pcregrep)" == "" ]; then
25     echo "You need to install pcregrep first, try:"
26     echo "  sudo apt-get install pcregrep"
27     exit -1;
28 fi
29
30 export XVKBD_EXE=../$XVKBD_EXE
31 export KEYTEST=../keytest.py
32 LYX_HOME=out-home
33 export LYX_USERDIR=$(pwd)/$LYX_HOME/.lyx
34 # Create locale links 
35 export LOCALE_DIR=../locale
36
37 if [ ! -d ../../locale ]; then
38     echo "Some tests may require the GUI showing up in a specified language."
39     echo "In order to make it work, I'm going to run this command:"
40     mkdir -p locale
41     cmd="ln -s `pwd`/locale ../../"
42     echo "  $cmd"
43     ans=""
44     while [ "$ans" != "y" -a "$ans" != "n" ]; do
45         echo "Should I proceed (y/n) ?"
46         read ans;
47     done
48     if [ "$ans" == "y" ]; then
49         $cmd;
50     fi;
51 fi
52
53 if [ "$#" -eq 0 ]; then
54     TESTS=$(ls *-in.txt *-in.sh | sed -e 's/hello-world-in.txt\|first-time-in.txt//')
55     rm -rf out-*;
56 else
57     TESTS=$*
58 fi
59
60 echo
61
62 if [ ! -d $LYX_HOME ]; then
63     mkdir -p $LYX_HOME
64 #    mkdir -p $LYX_USERDIR
65 #    cp preferences $LYX_USERDIR
66     cd $LYX_HOME
67     echo "Initializing testing environment . . ."
68     if ! ../single-test.sh "../first-time-in.txt" > test-log.txt 2>&1; then
69         echo "Some error occurred: check $(pwd)"
70         exit -1;
71     fi
72     cd ..
73 fi
74
75 # Launch the emergency STOP button
76 ./stop_autotests.tcl &
77 pid=$!
78
79 function stop_button() {
80     kill $pid
81     wait $pid > /dev/null 2>&1
82 }
83
84 echo "Running test cases . . ."
85 failed=0
86 for tf in $(echo "$TESTS"); do
87     t=$(echo $tf | sed -e 's/-in.txt//g' | sed -e 's/-in.sh//g')
88     printf "%40s: " $tf
89     if [ -f "$t-in.txt" ]; then
90         cmd="../single-test.sh ../$t-in.txt";
91     elif [ -f "$t-in.sh" ]; then
92         if [ ! -x "$t-in.sh" ]; then
93             echo "ERROR: $t-in.sh is not executable"
94             stop_button
95             exit -1;
96         fi
97         cmd="../$tf";
98     else
99         echo "ERROR: File not found: $t-in.txt or $t-in.sh"
100         stop_button
101         exit -1;
102     fi
103     rm -rf "out-$t"
104     mkdir "out-$t"
105     cd "out-$t"
106     if $cmd > test-log.txt 2>&1; then
107         echo Ok
108         cd ..
109         if [ "$V" != "" ]; then rm -rf "out-$t"; fi
110     else
111         echo FAILED
112         cd ..
113         failed=$[$failed+1];
114     fi;
115 done
116
117 stop_button
118
119 echo
120 if [ $failed -eq 0 ]; then
121     echo "All tests SUCCESSFUL"
122 else
123     echo "There were $failed FAILED tests";
124 fi
125
126 echo