survexport: Replace --no-xxx options with --xxx
[survex.git] / tests / cavern.tst
blob85754c69bddc19a7e5b1bddf166acf7926c1d833
1 #!/bin/sh
3 # Survex test suite - cavern tests
4 # Copyright (C) 1999-2004,2005,2006,2010,2012,2013,2014,2015,2016,2017 Olly Betts
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.
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.
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
20 testdir=`echo $0 | sed 's!/[^/]*$!!' || echo '.'`
22 # allow us to run tests standalone more easily
23 : ${srcdir="$testdir"}
25 # force VERBOSE if we're run on a subset of tests
26 test -n "$*" && VERBOSE=1
28 test -x "$testdir"/../src/cavern || testdir=.
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)`
34 : ${CAVERN="$testdir"/../src/cavern}
35 : ${DIFFPOS="$testdir"/../src/diffpos}
36 : ${SURVEXPORT="$testdir"/../src/survexport}
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  cmd_begin_bad cmd_equate_bad cmd_export_bad\
46  singlefixerr singlereffixerr\
47  begin_no_end end_no_begin end_no_begin_nest require_fail\
48  exporterr1 exporterr2 exporterr3 exporterr4 exporterr5\
49  exporterr1b exporterr2b exporterr3b exporterr6 exporterr6b\
50  hanging_cpt badinc badinc2 badinc3 badinc4 nonexistent_file ONELEG\
51  stnsurvey1 stnsurvey2\
52  tapelessthandepth longname chinabug chinabug2\
53  multinormal multinormignall multidiving multicylpolar multicartesian\
54  multinosurv multinormalbad multibug\
55  cmd_title cmd_titlebad cmd_dummy cmd_infer cmd_date cmd_datebad cmd_datebad2\
56  cartes diving cylpolar normal normal_bad normignall nosurv cmd_flags\
57  bad_cmd_flags plumb unusedstation exportnakedbegin oldestyle bugdz\
58  baddatacylpolar badnewline badquantities imgoffbyone infereqtopofil 3sdfixbug\
59  omitclino back back2 bad_back\
60  notentranceorexport inferunknown inferexports bad_units_factor\
61  bad_units_qlist\
62  percent_gradient dotinsurvey leandroclino lowsd revdir gettokennullderef\
63  nosurveyhanging cmd_solve_nothing cmd_solve_nothing_implicit\
64  cmd_calibrate cmd_declination cmd_declination_auto cmd_declination_conv\
65  lech level 2fixbug dot17 3dcorner\
66  unconnected-bug\
67  declination.dat ignore.dat backread.dat nomeasure.dat noteam.dat\
68  surfequate passage hanging_lrud equatenosuchstn surveytypo\
69  skipafterbadomit passagebad badreadingdotplus badcalibrate calibrate_clino\
70  badunits badbegin anonstn anonstnbad anonstnrev doubleinc reenterlots\
71  cs csbad csbadsdfix csfeet cslonglat omitfixaroundsolve repeatreading\
72  mixedeols utf8bom nonewlineateof\
73 "}}
75 # Test file stnsurvey3.svx missing: pos=fail # We exit before the error count.
77 LC_ALL=C
78 export LC_ALL
79 SURVEXLANG=en
80 export SURVEXLANG
82 vg_error=123
83 vg_log=$testdir/vg.log
84 if [ -n "$VALGRIND" ] ; then
85   rm -f "$vg_log"
86   CAVERN="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $CAVERN"
87   DIFFPOS="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $DIFFPOS"
88   SURVEXPORT="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $SURVEXPORT"
91 for file in $TESTS ; do
92   case $file in
93     nonexistent_file*|ONELEG)
94       # ONELEG tests that we don't apply special handling to command line
95       # arguments, only those in *include.
96       realfile= ;;
97     *.*) realfile=$file ;;
98     *) realfile=$file.svx ;;
99   esac
101   if [ x"$file" = xONELEG ] && [ -f "ONELEG.SVX" ] ; then
102     echo "Case insensitive filing system - skipping ONELEG testcase"
103     continue
104   fi
106   if [ -n "$realfile" ] && [ ! -r "$realfile" ] ; then
107     echo "Warning: don't know how to run test '$file' - skipping it"
108     continue
109   fi
111   echo "$file"
113   # how many warnings to expect
114   warn=
115   # how many errors to expect
116   error=
118   case $file in
119     *.dat)
120       # .dat files can't start with a comment.  All the current .dat tests
121       # have the same settings.
122       pos=yes
123       warn=0
124       ;;
125     nonexistent_file*|ONELEG)
126       # We exit before the error count.
127       pos=fail
128       ;;
129     *)
130       read header < "$realfile"
131       set dummy $header
132       while shift && [ -n "$1" ] ; do
133         case $1 in
134           pos=*) pos=`expr "$1" : 'pos=\(.*\)'` ;;
135           warn=*) warn=`expr "$1" : 'warn=\(.*\)'` ;;
136           error=*) error=`expr "$1" : 'error=\(.*\)'` ;;
137         esac
138       done
139       ;;
140   esac
142   basefile=$srcdir/$file
143   case $file in
144   *.*)
145     input="./$file"
146     basefile=`echo "$basefile"|sed 's/\.[^.]*$//'` ;;
147   *)
148     input="./$file.svx" ;;
149   esac
150   outfile=$basefile.out
151   posfile=$basefile.pos
152   dxffile=$basefile.dxf
153   rm -f tmp.*
154   pwd=`pwd`
155   cd "$srcdir"
156   srcdir=. $CAVERN "$input" --output="$pwd/tmp" > "$pwd/tmp.out"
157   exitcode=$?
158   cd "$pwd"
159   test -n "$VERBOSE" && cat tmp.out
160   if [ -n "$VALGRIND" ] ; then
161     if [ $exitcode = "$vg_error" ] ; then
162       cat "$vg_log"
163       rm "$vg_log"
164       exit 1
165     fi
166     rm "$vg_log"
167   fi
168   if test fail = "$pos" ; then
169     # success gives 0, signal (128 + <signal number>)
170     test $exitcode = 1 || exit 1
171   else
172     test $exitcode = 0 || exit 1
173   fi
174   if test -n "$warn" ; then
175     w=`sed '$!d;s/^There were \([0-9]*\).*/\1/;s/^[^0-9].*$/0/' tmp.out`
176     if test x"$w" != x"$warn" ; then
177       test -n "$VERBOSE" && echo "Got $w warnings, expected $warn"
178       exit 1
179     fi
180   fi
181   if test -n "$error" ; then
182     e=`sed '$!d;s/^There were .* and \([0-9][0-9]*\).*/\1/;s/^[^0-9].*$/0/' tmp.out`
183     if test x"$e" != x"$error" ; then
184       test -n "$VERBOSE" && echo "Got $e errors, expected $error"
185       exit 1
186     fi
187   fi
188   # Fail if nan, NaN, etc in output (which might be followed by m for metres or
189   # s for seconds).
190   if egrep -q '(^|[^A-Za-z0-9])nan[ms]?($|[^A-Za-z0-9])' tmp.out ; then
191     echo "Not-a-number appears in output"
192     exit 1
193   fi
195   case $pos in
196   yes)
197     if test -n "$VERBOSE" ; then
198       $DIFFPOS "$posfile" tmp.3d
199       exitcode=$?
200     else
201       $DIFFPOS "$posfile" tmp.3d > /dev/null
202       exitcode=$?
203     fi
204     if [ -n "$VALGRIND" ] ; then
205       if [ $exitcode = "$vg_error" ] ; then
206         cat "$vg_log"
207         rm "$vg_log"
208         exit 1
209       fi
210       rm "$vg_log"
211     fi
212     [ "$exitcode" = 0 ] || exit 1
213     ;;
214   dxf)
215     if test -n "$VERBOSE" ; then
216       $SURVEXPORT --defaults --surface-legs tmp.3d tmp.dxf
217       exitcode=$?
218     else
219       $SURVEXPORT --defaults --surface-legs tmp.3d tmp.dxf > /dev/null
220       exitcode=$?
221     fi
222     if [ -n "$VALGRIND" ] ; then
223       if [ $exitcode = "$vg_error" ] ; then
224         cat "$vg_log"
225         rm "$vg_log"
226         exit 1
227       fi
228       rm "$vg_log"
229     fi
230     [ "$exitcode" = 0 ] || exit 1
231     if test -n "$VERBOSE" ; then
232       diff "$dxffile" tmp.dxf || exit 1
233     else
234       cmp -s "$dxffile" tmp.dxf || exit 1
235     fi ;;
236   no)
237     test -f tmp.3d || exit 1 ;;
238   fail)
239     test -f tmp.3d && exit 1
240     # Check that last line doesn't contains "Bug in program detected"
241     case `tail -n 1 tmp.out` in
242     *"Bug in program detected"*) exit 1 ;;
243     esac ;;
244   *)
245     echo "Bad value for pos: '$pos'" ; exit 1 ;;
246   esac
248   if test -f "$outfile" ; then
249     # Check output is as expected, working around Apple's stone-age sed.
250     if test -n "$VERBOSE" ; then
251       sed '1,/^Copyright/d;/^\(CPU \)*[Tt]ime used  *[0-9][0-9.]*s$/d;s!.*/src/\(cavern: \)!\1!' tmp.out|diff "$outfile" - || exit 1
252     else
253       sed '1,/^Copyright/d;/^\(CPU \)*[Tt]ime used  *[0-9][0-9.]*s$/d;s!.*/src/\(cavern: \)!\1!' tmp.out|cmp -s "$outfile" - || exit 1
254     fi
255   fi
256   rm -f tmp.*
257 done
258 test -n "$VERBOSE" && echo "Test passed"
259 exit 0