1 | #!/bin/sh |
---|
2 | # |
---|
3 | # Survex test suite - cavern tests |
---|
4 | # Copyright (C) 1999-2004,2005,2006,2010,2012,2013,2014,2015 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 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 | # Make testdir absolute, so we can cd before running cavern to get a consistent |
---|
31 | # path in diagnostic messages. |
---|
32 | testdir=`(cd "$testdir" && pwd)` |
---|
33 | |
---|
34 | : ${CAVERN="$testdir"/../src/cavern} |
---|
35 | : ${DIFFPOS="$testdir"/../src/diffpos} |
---|
36 | : ${CAD3D="$testdir"/../src/cad3d} |
---|
37 | |
---|
38 | : ${TESTS=${*:-"singlefix singlereffix oneleg midpoint noose cross firststn\ |
---|
39 | deltastar deltastar2 bug3 calibrate_tape nosurvey2 cartesian cartesian2\ |
---|
40 | lengthunits angleunits cmd_alias cmd_truncate cmd_case cmd_fix cmd_solve\ |
---|
41 | cmd_entrance cmd_entrance_bad cmd_sd cmd_sd_bad cmd_fix_bad cmd_set\ |
---|
42 | cmd_set_bad beginroot revcomplist break_replace_pfx bug0 bug1 bug2 bug4 bug5\ |
---|
43 | expobug require export export2 includecomment\ |
---|
44 | self_loop self_eq_loop reenterwarn cmd_default cmd_prefix cmd_prefix_bad\ |
---|
45 | singlefixerr singlereffixerr\ |
---|
46 | begin_no_end end_no_begin end_no_begin_nest require_fail\ |
---|
47 | exporterr1 exporterr2 exporterr3 exporterr4 exporterr5\ |
---|
48 | exporterr1b exporterr2b exporterr3b exporterr6 exporterr6b\ |
---|
49 | hanging_cpt badinc badinc2 badinc3 badinc4 nonexistent_file ONELEG\ |
---|
50 | stnsurvey1 stnsurvey2\ |
---|
51 | tapelessthandepth longname chinabug chinabug2\ |
---|
52 | multinormal multinormignall multidiving multicylpolar multicartesian\ |
---|
53 | multinosurv multinormalbad multibug\ |
---|
54 | cmd_title cmd_titlebad cmd_dummy cmd_infer cmd_date cmd_datebad cmd_datebad2\ |
---|
55 | cartes diving cylpolar normal normal_bad normignall nosurv cmd_flags\ |
---|
56 | bad_cmd_flags plumb unusedstation exportnakedbegin oldestyle bugdz\ |
---|
57 | baddatacylpolar badnewline badquantities imgoffbyone infereqtopofil 3sdfixbug\ |
---|
58 | omitclino back back2\ |
---|
59 | notentranceorexport inferunknown inferexports bad_units_factor\ |
---|
60 | bad_units_qlist\ |
---|
61 | percent_gradient dotinsurvey leandroclino lowsd revdir gettokennullderef\ |
---|
62 | nosurveyhanging cmd_solve_nothing cmd_solve_nothing_implicit\ |
---|
63 | lech level 2fixbug dot17 3dcorner\ |
---|
64 | declination.dat ignore.dat backread.dat nomeasure.dat\ |
---|
65 | surfequate passage hanging_lrud equatenosuchstn surveytypo\ |
---|
66 | skipafterbadomit passagebad badreadingdotplus badcalibrate calibrate_clino\ |
---|
67 | badunits badbegin anonstn anonstnbad anonstnrev doubleinc reenterlots\ |
---|
68 | cs csbad omitfixaroundsolve repeatreading\ |
---|
69 | "}} |
---|
70 | |
---|
71 | # Test file stnsurvey3.svx missing: pos=fail # We exit before the error count. |
---|
72 | |
---|
73 | LC_ALL=C |
---|
74 | export LC_ALL |
---|
75 | SURVEXLANG=en |
---|
76 | export SURVEXLANG |
---|
77 | |
---|
78 | vg_error=123 |
---|
79 | vg_log=$testdir/vg.log |
---|
80 | if [ -n "$VALGRIND" ] ; then |
---|
81 | rm -f "$vg_log" |
---|
82 | CAVERN="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $CAVERN" |
---|
83 | DIFFPOS="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $DIFFPOS" |
---|
84 | CAD3D="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $CAD3D" |
---|
85 | fi |
---|
86 | |
---|
87 | for file in $TESTS ; do |
---|
88 | case $file in |
---|
89 | nonexistent_file*|ONELEG) |
---|
90 | # ONELEG tests that we don't apply special handling to command line |
---|
91 | # arguments, only those in *include. |
---|
92 | realfile= ;; |
---|
93 | *.*) realfile=$file ;; |
---|
94 | *) realfile=$file.svx ;; |
---|
95 | esac |
---|
96 | |
---|
97 | if [ -n "$realfile" ] && [ ! -r "$realfile" ] ; then |
---|
98 | echo "Warning: don't know how to run test '$file' - skipping it" |
---|
99 | continue |
---|
100 | fi |
---|
101 | |
---|
102 | echo "$file" |
---|
103 | |
---|
104 | # how many warnings to expect |
---|
105 | warn= |
---|
106 | # how many errors to expect |
---|
107 | error= |
---|
108 | |
---|
109 | case $file in |
---|
110 | *.dat) |
---|
111 | # .dat files can't start with a comment. All the current .dat tests |
---|
112 | # have the same settings. |
---|
113 | pos=yes |
---|
114 | warn=0 |
---|
115 | ;; |
---|
116 | nonexistent_file*|ONELEG) |
---|
117 | # We exit before the error count. |
---|
118 | pos=fail |
---|
119 | ;; |
---|
120 | *) |
---|
121 | read header < "$realfile" |
---|
122 | set dummy $header |
---|
123 | while shift && [ -n "$1" ]: ; do |
---|
124 | case $1 in |
---|
125 | pos=*) pos=`expr "$1" : 'pos=\(.*\)'` ;; |
---|
126 | warn=*) warn=`expr "$1" : 'warn=\(.*\)'` ;; |
---|
127 | error=*) error=`expr "$1" : 'error=\(.*\)'` ;; |
---|
128 | esac |
---|
129 | done |
---|
130 | ;; |
---|
131 | esac |
---|
132 | |
---|
133 | case $file in |
---|
134 | *.*) |
---|
135 | input="./$file" |
---|
136 | posfile="$srcdir"/`echo "$file"|sed 's/\.[^.]*$/.pos/'` |
---|
137 | dxffile="$srcdir"/`echo "$file"|sed 's/\.[^.]*$/.dxf/'` ;; |
---|
138 | *) |
---|
139 | input="./$file.svx" |
---|
140 | posfile="$srcdir/$file.pos" |
---|
141 | dxffile="$srcdir/$file.dxf" ;; |
---|
142 | esac |
---|
143 | rm -f tmp.* |
---|
144 | pwd=`pwd` |
---|
145 | cd "$srcdir" |
---|
146 | srcdir=. $CAVERN "$input" --output="$pwd/tmp" > "$pwd/tmp.out" |
---|
147 | exitcode=$? |
---|
148 | cd "$pwd" |
---|
149 | test -n "$VERBOSE" && cat tmp.out |
---|
150 | if [ -n "$VALGRIND" ] ; then |
---|
151 | if [ $exitcode = "$vg_error" ] ; then |
---|
152 | cat "$vg_log" |
---|
153 | rm "$vg_log" |
---|
154 | exit 1 |
---|
155 | fi |
---|
156 | rm "$vg_log" |
---|
157 | fi |
---|
158 | if test fail = "$pos" ; then |
---|
159 | # success gives 0, signal (128 + <signal number>) |
---|
160 | test $exitcode = 1 || exit 1 |
---|
161 | else |
---|
162 | test $exitcode = 0 || exit 1 |
---|
163 | fi |
---|
164 | if test -n "$warn" ; then |
---|
165 | w=`sed '$!d;s/^There were \([0-9]*\).*/\1/;s/^[^0-9].*$/0/' tmp.out` |
---|
166 | if test x"$w" != x"$warn" ; then |
---|
167 | test -n "$VERBOSE" && echo "Got $w warnings, expected $warn" |
---|
168 | exit 1 |
---|
169 | fi |
---|
170 | fi |
---|
171 | if test -n "$error" ; then |
---|
172 | e=`sed '$!d;s/^There were .* and \([0-9][0-9]*\).*/\1/;s/^[^0-9].*$/0/' tmp.out` |
---|
173 | if test x"$e" != x"$error" ; then |
---|
174 | test -n "$VERBOSE" && echo "Got $e errors, expected $error" |
---|
175 | exit 1 |
---|
176 | fi |
---|
177 | fi |
---|
178 | nan=`sed 's/.*\<[Nn]a[Nn]m\?\>.*/x/p;d' tmp.out` |
---|
179 | if test -n "$nan" ; then |
---|
180 | exit 1 |
---|
181 | fi |
---|
182 | |
---|
183 | case $pos in |
---|
184 | yes) |
---|
185 | if test -n "$VERBOSE" ; then |
---|
186 | $DIFFPOS "$posfile" tmp.3d |
---|
187 | exitcode=$? |
---|
188 | else |
---|
189 | $DIFFPOS "$posfile" tmp.3d > /dev/null |
---|
190 | exitcode=$? |
---|
191 | fi |
---|
192 | if [ -n "$VALGRIND" ] ; then |
---|
193 | if [ $exitcode = "$vg_error" ] ; then |
---|
194 | cat "$vg_log" |
---|
195 | rm "$vg_log" |
---|
196 | exit 1 |
---|
197 | fi |
---|
198 | rm "$vg_log" |
---|
199 | fi |
---|
200 | [ "$exitcode" = 0 ] || exit 1 |
---|
201 | ;; |
---|
202 | dxf) |
---|
203 | if test -n "$VERBOSE" ; then |
---|
204 | $CAD3D tmp.3d tmp.dxf |
---|
205 | exitcode=$? |
---|
206 | else |
---|
207 | $CAD3D tmp.3d tmp.dxf > /dev/null |
---|
208 | exitcode=$? |
---|
209 | fi |
---|
210 | if [ -n "$VALGRIND" ] ; then |
---|
211 | if [ $exitcode = "$vg_error" ] ; then |
---|
212 | cat "$vg_log" |
---|
213 | rm "$vg_log" |
---|
214 | exit 1 |
---|
215 | fi |
---|
216 | rm "$vg_log" |
---|
217 | fi |
---|
218 | [ "$exitcode" = 0 ] || exit 1 |
---|
219 | if test -n "$VERBOSE" ; then |
---|
220 | diff "$dxffile" tmp.dxf || exit 1 |
---|
221 | else |
---|
222 | cmp -s "$dxffile" tmp.dxf || exit 1 |
---|
223 | fi ;; |
---|
224 | no) |
---|
225 | test -f tmp.3d || exit 1 ;; |
---|
226 | fail) |
---|
227 | test -f tmp.3d && exit 1 |
---|
228 | # Check that last line doesn't contains "Bug in program detected" |
---|
229 | case `tail -n 1 tmp.out` in |
---|
230 | *"Bug in program detected"*) exit 1 ;; |
---|
231 | esac ;; |
---|
232 | *) |
---|
233 | echo "Bad value for pos: '$pos'" ; exit 1 ;; |
---|
234 | esac |
---|
235 | |
---|
236 | out=$srcdir/$file.out |
---|
237 | if test -f "$out" ; then |
---|
238 | # Check output is as expected. |
---|
239 | if test -n "$VERBOSE" ; then |
---|
240 | sed '1,/^Copyright/d;/^\(CPU t\|T\)ime used *[0-9][0-9.]*s$/d;s!.*/src/\(cavern: \)!\1!' tmp.out|diff "$out" - || exit 1 |
---|
241 | else |
---|
242 | sed '1,/^Copyright/d;/^\(CPU t\|T\)ime used *[0-9][0-9.]*s$/d;s!.*/src/\(cavern: \)!\1!' tmp.out|cmp -s "$out" - || exit 1 |
---|
243 | fi |
---|
244 | fi |
---|
245 | rm -f tmp.* |
---|
246 | done |
---|
247 | test -n "$VERBOSE" && echo "Test passed" |
---|
248 | exit 0 |
---|