| 1 | #!/bin/sh |
|---|
| 2 | # |
|---|
| 3 | # Survex test suite - cavern tests |
|---|
| 4 | # Copyright (C) 1999-2004,2005 Olly Betts |
|---|
| 5 | # |
|---|
| 6 | # This program is free software; you can redistribute it and/or modify |
|---|
| 7 | # it under the terms of the GNU General Public License as published by |
|---|
| 8 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | # (at your option) any later version. |
|---|
| 10 | # |
|---|
| 11 | # This program is distributed in the hope that it will be useful, |
|---|
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | # GNU General Public License for more details. |
|---|
| 15 | # |
|---|
| 16 | # You should have received a copy of the GNU General Public License |
|---|
| 17 | # along with this program; if not, write to the Free Software |
|---|
| 18 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 19 | |
|---|
| 20 | testdir=`echo $0 | sed 's!/[^/]*$!!' || echo '.'` |
|---|
| 21 | |
|---|
| 22 | # allow us to run tests standalone more easily |
|---|
| 23 | : ${srcdir="$testdir"} |
|---|
| 24 | |
|---|
| 25 | # force VERBOSE if we're run on a subset of tests |
|---|
| 26 | test -n "$*" && VERBOSE=1 |
|---|
| 27 | |
|---|
| 28 | test -x "$testdir"/../src/cavern || testdir=. |
|---|
| 29 | |
|---|
| 30 | : ${CAVERN="$testdir"/../src/cavern} |
|---|
| 31 | : ${DIFFPOS="$testdir"/../src/diffpos} |
|---|
| 32 | : ${CAD3D="$testdir"/../src/cad3d} |
|---|
| 33 | |
|---|
| 34 | : ${TESTS=${*-"singlefix singlereffix oneleg midpoint noose cross firststn\ |
|---|
| 35 | deltastar deltastar2 bug3 calibrate_tape nosurvey2 cartesian cartesian2\ |
|---|
| 36 | lengthunits angleunits cmd_truncate cmd_case cmd_fix cmd_solve\ |
|---|
| 37 | cmd_entrance cmd_sd cmd_sd_bad cmd_fix_bad cmd_set cmd_set_bad\ |
|---|
| 38 | beginroot revcomplist break_replace_pfx bug0 bug1 bug2 bug4 bug5\ |
|---|
| 39 | expobug require export export2 includecomment\ |
|---|
| 40 | self_loop self_eq_loop reenterwarn cmd_default cmd_prefix\ |
|---|
| 41 | singlefixerr singlereffixerr\ |
|---|
| 42 | begin_no_end end_no_begin end_no_begin_nest require_fail\ |
|---|
| 43 | exporterr1 exporterr2 exporterr3 exporterr4 exporterr5\ |
|---|
| 44 | exporterr1b exporterr2b exporterr3b exporterr6 exporterr6b\ |
|---|
| 45 | hanging_cpt badinc badinc2 non_existant_file ONELEG\ |
|---|
| 46 | stnsurvey1 stnsurvey2 stnsurvey3\ |
|---|
| 47 | tapelessthandepth longname chinabug chinabug2\ |
|---|
| 48 | multinormal multinormignall multidiving multicylpolar multicartesian\ |
|---|
| 49 | multinosurv multinormalbad multibug\ |
|---|
| 50 | cmd_title cmd_titlebad cmd_dummy cmd_infer\ |
|---|
| 51 | cartes diving cylpolar normal normignall nosurv cmd_flags bad_cmd_flags\ |
|---|
| 52 | plumb unusedstation exportnakedbegin oldestyle bugdz baddatacylpolar\ |
|---|
| 53 | badnewline badquantities imgoffbyone infereqtopofil 3sdfixbug omitclino back\ |
|---|
| 54 | notentranceorexport inferunknown inferexports bad_units_factor\ |
|---|
| 55 | percent_gradient dotinsurvey leandroclino lowsd revdir gettokennullderef\ |
|---|
| 56 | nosurveyhanging cmd_solve_nothing cmd_solve_nothing_implicit\ |
|---|
| 57 | lech level 2fixbug declination.dat ignore.dat backread.dat dot17 3dcorner\ |
|---|
| 58 | surfequate passage"}} |
|---|
| 59 | |
|---|
| 60 | for file in $TESTS ; do |
|---|
| 61 | # how many warnings to expect |
|---|
| 62 | warn= |
|---|
| 63 | # how many errors to expect |
|---|
| 64 | error= |
|---|
| 65 | case $file in |
|---|
| 66 | singlefix) pos=yes ; warn=1;; |
|---|
| 67 | singlereffix) pos=yes ; warn=0 ;; |
|---|
| 68 | oneleg) pos=yes ; warn=0 ;; |
|---|
| 69 | midpoint) pos=yes ; warn=0 ;; |
|---|
| 70 | noose) pos=yes ; warn=0 ;; |
|---|
| 71 | cross) pos=yes ; warn=0 ;; |
|---|
| 72 | firststn) pos=yes ; warn=0 ;; |
|---|
| 73 | deltastar) pos=yes ; warn=0 ;; |
|---|
| 74 | deltastar2) pos=yes ; warn=0 ;; |
|---|
| 75 | bug3) pos=yes ; warn=0 ;; |
|---|
| 76 | calibrate_tape) pos=yes ; warn=0 ;; |
|---|
| 77 | nosurvey2) pos=yes ; warn=0 ;; |
|---|
| 78 | cartesian) pos=yes ; warn=0 ;; |
|---|
| 79 | cartesian2) pos=yes ; warn=0 ;; |
|---|
| 80 | lengthunits) pos=yes ; warn=0 ;; |
|---|
| 81 | angleunits) pos=yes ; warn=0 ;; |
|---|
| 82 | cmd_truncate) pos=yes ; warn=0 ;; |
|---|
| 83 | cmd_case) pos=yes ; warn=0 ;; |
|---|
| 84 | cmd_fix) pos=yes ; warn=1 ;; |
|---|
| 85 | cmd_fix_bad) pos=fail ; error=10 ;; |
|---|
| 86 | cmd_solve) pos=yes ; warn=0 ;; |
|---|
| 87 | cmd_entrance) pos=no ; warn=0 ;; |
|---|
| 88 | cmd_sd) pos=no ; warn=0 ;; |
|---|
| 89 | cmd_sd_bad) pos=fail ; error=7 ;; |
|---|
| 90 | cmd_set) pos=no ; warn=0 ;; |
|---|
| 91 | cmd_set_bad) pos=fail ; error=7 ;; |
|---|
| 92 | beginroot) pos=no ;; |
|---|
| 93 | revcomplist) pos=no ; warn=0 ;; |
|---|
| 94 | break_replace_pfx) pos=no ; warn=0 ;; |
|---|
| 95 | bug0) pos=no ; warn=0 ;; |
|---|
| 96 | bug1) pos=no ; warn=0 ;; |
|---|
| 97 | bug2) pos=no ; warn=0 ;; |
|---|
| 98 | bug4) pos=no ; warn=0 ;; |
|---|
| 99 | bug5) pos=no ; warn=0 ;; |
|---|
| 100 | expobug) pos=no ; warn=0 ;; |
|---|
| 101 | require) pos=no ; warn=0 ;; |
|---|
| 102 | export) pos=no ; warn=0 ;; |
|---|
| 103 | export2) pos=no ; warn=0 ;; |
|---|
| 104 | includecomment) pos=no ; warn=0 ;; |
|---|
| 105 | self_loop) pos=fail ; warn=0 ;; |
|---|
| 106 | self_eq_loop) pos=no ; warn=1 ;; |
|---|
| 107 | reenterwarn) pos=no ; warn=2 ;; |
|---|
| 108 | cmd_default) pos=no ; warn=3 ;; |
|---|
| 109 | singlereffixerr) pos=no ; warn=0 ;; |
|---|
| 110 | cmd_prefix) pos=no ; warn=1 ;; |
|---|
| 111 | singlefixerr) pos=no ; warn=1 ;; |
|---|
| 112 | tapelessthandepth) pos=no ; warn=1 ;; |
|---|
| 113 | chinabug2) pos=no ; warn=0 ;; |
|---|
| 114 | longname) pos=no ; warn=0 ;; |
|---|
| 115 | chinabug) pos=fail ;; |
|---|
| 116 | begin_no_end) pos=fail ;; |
|---|
| 117 | end_no_begin) pos=fail ;; |
|---|
| 118 | end_no_begin_nest) pos=fail ;; |
|---|
| 119 | require_fail) pos=fail ;; |
|---|
| 120 | exporterr1) pos=fail ;; |
|---|
| 121 | exporterr2) pos=fail ;; |
|---|
| 122 | exporterr3) pos=fail ;; |
|---|
| 123 | exporterr4) pos=fail ;; |
|---|
| 124 | exporterr5) pos=fail ;; |
|---|
| 125 | exporterr1b) pos=fail ;; |
|---|
| 126 | exporterr2b) pos=fail ;; |
|---|
| 127 | exporterr3b) pos=fail ;; |
|---|
| 128 | exporterr6) pos=fail ;; |
|---|
| 129 | exporterr6b) pos=fail ;; |
|---|
| 130 | hanging_cpt) pos=fail ;; |
|---|
| 131 | badinc) pos=fail ;; |
|---|
| 132 | badinc2) pos=fail ;; |
|---|
| 133 | non_existant_file) pos=fail ;; |
|---|
| 134 | ONELEG) pos=fail ;; |
|---|
| 135 | stnsurvey1) pos=fail ;; |
|---|
| 136 | stnsurvey2) pos=fail ;; |
|---|
| 137 | stnsurvey3) pos=fail ;; |
|---|
| 138 | multinormal) pos=yes ; warn=0 ;; |
|---|
| 139 | multinormignall) pos=yes ; warn=0 ;; |
|---|
| 140 | multidiving) pos=yes ; warn=0 ;; |
|---|
| 141 | multicylpolar) pos=yes ; warn=0 ;; |
|---|
| 142 | multicartesian) pos=yes ; warn=0 ;; |
|---|
| 143 | multinosurv) pos=yes ; warn=0 ;; |
|---|
| 144 | multinormalbad) pos=fail ;; |
|---|
| 145 | multibug) pos=no ; warn=0 ;; |
|---|
| 146 | cmd_title) pos=no ; warn=0 ;; |
|---|
| 147 | cmd_titlebad) pos=fail ; error=4 ;; |
|---|
| 148 | cmd_dummy) pos=no ; warn=0 ;; |
|---|
| 149 | cmd_infer) pos=yes ; warn=0 ;; |
|---|
| 150 | cartes) pos=yes ; warn=0 ;; |
|---|
| 151 | diving) pos=yes ; warn=0 ;; |
|---|
| 152 | cylpolar) pos=yes ; warn=0 ;; |
|---|
| 153 | normal) pos=yes ; warn=0 ;; |
|---|
| 154 | normignall) pos=yes ; warn=0 ;; |
|---|
| 155 | nosurv) pos=yes ; warn=0 ;; |
|---|
| 156 | cmd_flags) pos=no ; warn=0 ;; |
|---|
| 157 | bad_cmd_flags) pos=fail ; error=19 ;; |
|---|
| 158 | plumb) pos=yes ; warn=0 ;; |
|---|
| 159 | unusedstation) pos=no ; warn=2 ;; |
|---|
| 160 | oldestyle) pos=no ; warn=1 ;; |
|---|
| 161 | exportnakedbegin) pos=fail ;; |
|---|
| 162 | bugdz) pos=yes ; warn=0 ;; |
|---|
| 163 | baddatacylpolar) pos=fail ; error=1 ;; |
|---|
| 164 | badnewline) pos=fail ; error=2 ;; |
|---|
| 165 | badquantities) pos=fail ; error=11 ;; |
|---|
| 166 | imgoffbyone) pos=yes ;; # don't actually care about coords, just the names |
|---|
| 167 | infereqtopofil) pos=yes ; warn=0 ;; |
|---|
| 168 | 3sdfixbug) pos=yes ; warn=0 ;; |
|---|
| 169 | omitclino) pos=yes ; warn=0 ;; |
|---|
| 170 | back) pos=yes; warn=0 ;; |
|---|
| 171 | notentranceorexport) pos=fail; warn=0 ;; |
|---|
| 172 | inferunknown) pos=fail; error=1 ;; |
|---|
| 173 | inferexports) pos=no; warn=0 ;; |
|---|
| 174 | bad_units_factor) pos=fail; error=5 ;; |
|---|
| 175 | percent_gradient) pos=yes; warn=0 ;; |
|---|
| 176 | dotinsurvey) pos=no; warn=0 ;; |
|---|
| 177 | leandroclino) pos=yes; warn=0 ;; |
|---|
| 178 | lowsd) pos=no; warn=0 ;; |
|---|
| 179 | revdir) pos=yes; warn=0 ;; |
|---|
| 180 | gettokennullderef) pos=fail ;; |
|---|
| 181 | lech) pos=no; warn=0 ;; |
|---|
| 182 | level) pos=yes; warn=0 ;; |
|---|
| 183 | 2fixbug) pos=no; warn=0 ;; |
|---|
| 184 | declination.dat|ignore.dat|backread.dat) pos=yes; warn=0 ;; |
|---|
| 185 | dot17) pos=yes; warn=0 ;; |
|---|
| 186 | 3dcorner) pos=yes; warn=0 ;; |
|---|
| 187 | surfequate) pos=dxf; warn=0 ;; |
|---|
| 188 | nosurveyhanging) pos=fail ;; |
|---|
| 189 | cmd_solve_hanging) pos=fail ;; |
|---|
| 190 | cmd_solve_nothing*) pos=no; warn=0 ;; |
|---|
| 191 | passage) pos=no; warn=0 ;; |
|---|
| 192 | *) echo "Warning: don't know how to run test '$file' - skipping it" |
|---|
| 193 | file='' ;; |
|---|
| 194 | esac |
|---|
| 195 | |
|---|
| 196 | if test -n "$file" ; then |
|---|
| 197 | echo "$file" |
|---|
| 198 | case $file in |
|---|
| 199 | *.*) |
|---|
| 200 | input="$srcdir/$file" |
|---|
| 201 | posfile="$srcdir"/`echo "$file"|sed 's/\.[^.]*$/.pos/'` |
|---|
| 202 | dxffile="$srcdir"/`echo "$file"|sed 's/\.[^.]*$/.dxf/'` ;; |
|---|
| 203 | *) |
|---|
| 204 | input="$srcdir/$file.svx" |
|---|
| 205 | posfile="$srcdir/$file.pos" |
|---|
| 206 | dxffile="$srcdir/$file.dxf" ;; |
|---|
| 207 | esac |
|---|
| 208 | rm -f tmp.* |
|---|
| 209 | $CAVERN "$input" --output=tmp > tmp.out |
|---|
| 210 | exitcode=$? |
|---|
| 211 | test -n "$VERBOSE" && cat tmp.out |
|---|
| 212 | if test fail = "$pos" ; then |
|---|
| 213 | # success gives 0, signal (128 + <signal number>) |
|---|
| 214 | test $exitcode = 1 || exit 1 |
|---|
| 215 | else |
|---|
| 216 | test $exitcode = 0 || exit 1 |
|---|
| 217 | fi |
|---|
| 218 | if test -n "$warn" ; then |
|---|
| 219 | w=`sed '$!d;$s/^Done.*/0/;s/[^0-9]*\([0-9]*\).*/\1/' tmp.out` |
|---|
| 220 | test x"$w" = x"$warn" || exit 1 |
|---|
| 221 | fi |
|---|
| 222 | if test -n "$error" ; then |
|---|
| 223 | e=`sed '$!d;$s/^Done.*/0/;s/[^0-9]*[0-9][0-9]*[^0-9][^0-9]*\([0-9][0-9]*\).*/\1/;s/\(.*[^0-9].*\)/0/' tmp.out` |
|---|
| 224 | test x"$e" = x"$error" || exit 1 |
|---|
| 225 | fi |
|---|
| 226 | nan=`sed 's/.*\<[Nn]a[Nn]m\?\>.*/x/p;d' tmp.out` |
|---|
| 227 | if test -n "$nan" ; then |
|---|
| 228 | exit 1 |
|---|
| 229 | fi |
|---|
| 230 | |
|---|
| 231 | case $pos in |
|---|
| 232 | yes) |
|---|
| 233 | if test -n "$VERBOSE" ; then |
|---|
| 234 | $DIFFPOS tmp.3d "$posfile" || exit 1 |
|---|
| 235 | else |
|---|
| 236 | $DIFFPOS tmp.3d "$posfile" > /dev/null || exit 1 |
|---|
| 237 | fi ;; |
|---|
| 238 | dxf) |
|---|
| 239 | if test -n "$VERBOSE" ; then |
|---|
| 240 | $CAD3D tmp.3d tmp.dxf || exit 1 |
|---|
| 241 | diff tmp.dxf "$dxffile" || exit 1 |
|---|
| 242 | else |
|---|
| 243 | $CAD3D tmp.3d tmp.dxf > /dev/null || exit 1 |
|---|
| 244 | cmp -s tmp.dxf "$dxffile" || exit 1 |
|---|
| 245 | fi ;; |
|---|
| 246 | no) |
|---|
| 247 | test -f tmp.3d || exit 1 ;; |
|---|
| 248 | fail) |
|---|
| 249 | test -f tmp.3d && exit 1 |
|---|
| 250 | # Check that last line doesn't contains "Bug in program detected" |
|---|
| 251 | case `tail -n 1 tmp.out` in |
|---|
| 252 | *"Bug in program detected"*) exit 1 ;; |
|---|
| 253 | esac ;; |
|---|
| 254 | *) |
|---|
| 255 | echo "Bad value for pos: '$pos'" ; exit 1 ;; |
|---|
| 256 | esac |
|---|
| 257 | rm -f tmp.* |
|---|
| 258 | fi |
|---|
| 259 | done |
|---|
| 260 | test -n "$VERBOSE" && echo "Test passed" |
|---|
| 261 | exit 0 |
|---|