/src/wrappers/scripts/check-cluster.sh
Shell | 271 lines | 202 code | 38 blank | 31 comment | 15 complexity | da835a7f6c92e090a42efa1bd5d556da MD5 | raw file
1#!/bin/bash 2 3# An home-grown script to check all the classes 4# found in a wrapper library having a library and 5# example subdirectories. 6 7TIMESTAMP=.check_cluster_timestamp 8 9WRONG_CLASSES=classes-with-errors 10CORRECT_CLASSES=correct-classes 11 12WRONG_EXAMPLES=examples-with-errors 13CORRECT_EXAMPLES=correct-examples 14 15export WRONG_CLASSES CORRECT_CLASSES WRONG_EXAMPLES CORRECT_EXAMPLES 16 17check_position () { 18 if [ ! $eiffel_libraries ] 19 then 20 echo "\$eiffel_libraries enviromental variable not set. Quitting" 21 exit 5 22 fi 23 if [ ! -f loadpath.se ] ; then 24 echo "Couldn't find loadpath.se in current directory cluster." 25 exit 5 26 fi 27} 28 29run_tests () { 30 ## Run eiffeltest test 31 if [ ! -d tests ] ; then 32 echo "Couldn't find tests in current directory cluster" 33 exit 5 34 else 35 echo "Running tests" 36 eiffeltest tests 37 fi 38 39} 40 41wrong_and_correct_classes () { 42 # All the testable classes; the classes with known error are listed first 43 44 if [ -s $WRONG_CLASSES ] ; 45 then # Prepend wrong classes 46 cat $WRONG_CLASSES 47 # Find all classes in the library 48 find library -iname "*.e" | 49 # Remove stubs 50 grep -v stub | 51 sort --numeric-sort --reverse | 52 # Remove classes with errors (previously prepended) 53 grep -v -F -f $WRONG_CLASSES 54 else find library -iname "*.e" | grep -v stub 55 fi 56} 57 58changed_classes_first () { 59 # The files ordered from the latest to the oldest 60 61 ## Find in the directory "library" all Eiffel source code, print 62 ## its change time (in seconds from epoch) and its name 63 find library -name "*.e" -printf "%T@ %p\n" | 64 ## remove stubs 65 grep -v stub | 66 sort --numeric-sort --reverse | 67 ## Remove the first column (changetime) 68 cut -f 2 -d ' ' 69 70 # if [ -f $TIMESTAMP ] ; then 71 # find library -iname "*.e" -newer $TIMESTAMP | grep -v stub 72 # find library -iname "*.e" ! -newer $TIMESTAMP | grep -v stub 73 # else 74 # find library -iname "*.e" | grep -v stub 75 # fi 76 # touch $TIMESTAMP 77} 78 79check-class () { 80 RESULT=$(mktemp -t check-class-XXXXX) 81 CLASS=$1 82 83 echo -n "Checking $CLASS: " 84 if se class_check $CLASS >$RESULT 2>&1 85 then 86 echo correct. 87 echo >>$CORRECT_CLASSES $CLASS 88 else 89 echo contains errors. 90 cat $RESULT 91 echo >>$WRONG_CLASSES $CLASS 92 fi 93 rm --force $RESULT 94} 95 96export -f check-class # to satisfy parallel command; this command is bash specific. 97 98check_classes () { 99 # check all the library classes 100 if [ ! -d library ] ; then 101 echo "Couldn't find library in current directory cluster" 102 exit 5 103 else 104 echo "Testing library classes." 105 if [ -s $WRONG_CLASSES ] ; then rm $WRONG_CLASSES; fi 106 if [ -s $CORRECT_CLASSES ] ; then rm $CORRECT_CLASSES; fi 107 108 touch $WRONG_CLASSES $CORRECT_CLASSES 109 if which parallel >/dev/null 110 then 111 echo Using parallel command 112 changed_classes_first | 113 parallel --no-notice check-class {} 2>&1 114 else 115 for CLASS in $( changed_classes_first ) # $( wrong_and_correct_classes ) 116 do 117 class_check $CLASS 118 done 119 fi 120 121 if [ -s $CORRECT_CLASSES ] 122 then echo $(wc -l $CORRECT_CLASSES) correct classes. 123 fi 124 125 if [ -s $WRONG_CLASSES ] 126 then 127 echo $(wc -l $WRONG_CLASSES) classes with errors 128 exit 5 129 fi 130 131 fi ## library exits 132} 133 134compile_examples () { 135 # re-compile all the examples that needs to be recompiled and 136 # rechecked, run them and ask the developer to confirm the 137 # correctness of the output. 138 if [ ! -d examples ] ; then 139 echo "Couldn't find examples directory in current cluster" 140 exit 5 141 fi 142 143 echo "Testing examples." 144 145 ## Create a time mark. Examples more recent than it will be run. 146 TIME_MARK=$(mktemp -t) 147 if touch $TIME_MARK ; 148 then 149 rm $WRONG_EXAMPLES $CORRECT_EXAMPLES # We're testing them anew 150 151 for EXAMPLE in $(find examples -iname "*.ace") 152 do 153 EXAMPLE_DIR=$(dirname $EXAMPLE) 154 EXAMPLE_NAME=$(basename $EXAMPLE) 155 EXECUTABLE=$(se ace_check $EXAMPLE | 156 grep system | 157 cut --delimiter=" " --fields=2) 158 echo -n "Testing $EXAMPLE_NAME in $EXAMPLE_DIR. " 159 if ( cd $EXAMPLE_DIR; compile $EXAMPLE_NAME ) 160 then 161 TESTABLE="$TESTABLE $EXAMPLE_DIR/$EXECUTABLE" 162 echo "$EXECUTABLE successfully compiled." 163 echo >>$CORRECT_EXAMPLES $EXAMPLE 164 else 165 echo Contains errors. 166 echo >>$WRONG_EXAMPLES $EXAMPLE 167 fi 168 done 169 170 echo Testing $TESTABLE 171 for EXAMPLE in $TESTABLE 172 do 173 EXAMPLE_DIR=$(dirname $EXAMPLE) 174 EXAMPLE_NAME=$(basename $EXAMPLE) 175 echo Running $EXAMPLE_NAME in $EXAMPLE_DIR. 176 177 ## read -p "Does $EXAMPLE behave as expected?" OK 178 if ./$EXAMPLE 179 then echo $EXAMPLE_NAME successful 180 else echo $EXAMPLE_NAME NOT successful 181 fi 182 done 183 184 rm $TIME_MARK 185 fi 186} 187 188clear_temporary_files () { 189 for EXAMPLE in $(find examples -iname "*.ace") 190 do 191 EXAMPLE_DIR=$(dirname $EXAMPLE) 192 EXAMPLE_NAME=$(basename $EXAMPLE) 193 EXECUTABLE=$(se ace_check $EXAMPLE | 194 grep system | 195 cut --delimiter=" " --fields=2) 196 echo -n "Testing $EXAMPLE_NAME in $EXAMPLE_DIR. " 197 ( cd $EXAMPLE_DIR; se clean $EXAMPLE_NAME ) 198 done 199} 200print_usage () { 201 cat <<EOF 202 $(basename $0) ARGUMENTS 203 204 Arguments: 205 206 test 207 208 run eiffeltest using the "test" directory 209 210 library 211 212 check all the library classes, starting with those that have been 213 changed since the last time this were launched. Those with 214 errors are listed in "$WRONG_CLASSES", those without in 215 "$CORRECT_CLASSES". 216 217 examples 218 219 re-compiles all the examples that needs to be recompiled, run them 220 and ask the developer to confirm its correct behaviour. Those that 221 seems to behave correctly are added to $CORRECT_EXAMPLES, the 222 others to $WRONG_EXAMPLES. 223 224 clean 225 226 remove all the temporary files. 227 228 Usage: run it in a cluster of the Eiffel Wrapper Library Collection, 229 i.e. eiffel-gtk, eiffel-gda, eiffel-glib. 230 231 This script would like to be (become) a good "commit-filter", i.e.: if 232 it does not end successfully you should not commit your changes. 233 234EOF 235 236 ## library was: check all the library classes, starting with those 237 ## that had error the last time the check-cluster script were 238 ## launched. Those with errors are listed in "$WRONG_CLASSES", those 239 ## without in "$CORRECT_CLASSES". 240 241} 242 243until [ -z $1 ] # Until all parameters used up... 244do 245 case $1 in 246 test ) 247 # run tests 248 run_tests 249 ;; 250 library ) 251 # check library classes 252 check_classes 253 ;; 254 examples ) 255 # check library examples 256 compile_examples 257 ;; 258 clean ) 259 # Remove temporary files 260 clear_temporary_files 261 ;; 262 all ) 263 check_classes 264 compile_examples 265 ;; 266 * ) 267 print_usage 268 ;; 269 esac 270 shift 271done