source: git/tests/cavern.tst @ 05f2640

stereo-2025
Last change on this file since 05f2640 was 52f46ed, checked in by Olly Betts <olly@…>, 9 months ago

Make from==to only a warning for Compass DAT

Compass itself seems to quietly ignore such legs.

  • Property mode set to 100755
File size: 12.8 KB
Line 
1#!/bin/sh
2#
3# Survex test suite - cavern tests
4# Copyright (C) 1999-2024 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
20testdir=`echo $0 | sed 's!/[^/]*$!!' || echo '.'`
21
22test -x "$testdir"/../src/cavern || testdir=.
23
24# Make testdir absolute, so we can cd before running cavern to get a consistent
25# path in diagnostic messages.
26testdir=`cd "$testdir" && pwd`
27
28# allow us to run tests standalone more easily
29: ${srcdir="$testdir"}
30if [ -z "$SURVEXLIB" ] ; then
31  SURVEXLIB=`cd "$srcdir/../lib" && pwd`
32  export SURVEXLIB
33fi
34
35# force VERBOSE if we're run on a subset of tests
36test -n "$*" && VERBOSE=1
37
38case `uname -a` in
39  MINGW*)
40    DIFF='diff --strip-trailing-cr'
41    QUIET_DIFF='diff -q --strip-trailing-cr'
42    ;;
43  *)
44    DIFF=diff
45    # Use cmp when we can as a small optimisation.
46    QUIET_DIFF='cmp -s'
47    ;;
48esac
49
50: ${CAVERN="$testdir"/../src/cavern}
51: ${DIFFPOS="$testdir"/../src/diffpos}
52: ${DUMP3D="$testdir"/../src/dump3d}
53: ${SURVEXPORT="$testdir"/../src/survexport}
54
55: ${TESTS=${*:-"singlefix singlereffix oneleg midpoint noose cross firststn\
56 deltastar deltastar2 bug3 calibrate_tape nosurvey2 cartesian cartesian2\
57 lengthunits angleunits cmd_alias cmd_alias_bad cmd_truncate cmd_truncate_bad\
58 cmd_case cmd_case_bad cmd_fix\
59 cmd_solve cmd_entrance cmd_entrance_bad cmd_sd cmd_sd_bad cmd_fix_bad cmd_set\
60 cmd_set_bad cmd_set_dot_in_name\
61 beginroot revcomplist break_replace_pfx bug0 bug1 bug2 bug4 bug5\
62 expobug require export export2 includecomment\
63 self_loop self_eq_loop reenterwarn cmd_default cmd_default_bad\
64 cmd_prefix cmd_prefix_bad\
65 cmd_begin_bad cmd_equate_bad cmd_export_bad\
66 singlefixerr singlereffixerr\
67 begin_no_end end_no_begin end_no_begin_nest require_fail\
68 exporterr1 exporterr2 exporterr3 exporterr4 exporterr5\
69 exporterr1b exporterr2b exporterr3b exporterr6 exporterr6b\
70 hanging_cpt badinc badinc2 badinc3 badinc4 badinc5.mak nonexistent_file ONELEG\
71 stnsurvey1 stnsurvey2\
72 tapelessthandepth longname chinabug chinabug2\
73 multinormal multinormignall multidiving multicylpolar multicartesian\
74 multinosurv multinormalbad multibug\
75 cmd_title cmd_titlebad cmd_dummy cmd_infer cmd_date cmd_datebad cmd_datebad2\
76 cartes diving cylpolar normal normal_bad normignall nosurv cmd_flags\
77 bad_cmd_flags plumb unusedstation exportnakedbegin oldestyle bugdz\
78 baddatacylpolar badnewline badquantities imgoffbyone infereqtopofil 3sdfixbug\
79 omitclino back back2 bad_back\
80 notentranceorexport inferunknown inferexports bad_units_factor\
81 bad_units_qlist\
82 percent_gradient dotinsurvey leandroclino lowsd revdir gettokennullderef\
83 nosurveyhanging cmd_solve_nothing cmd_solve_nothing_implicit\
84 cmd_cartesian cmd_cartesian_bad\
85 cmd_calibrate cmd_declination cmd_declination_auto cmd_declination_auto_bad\
86 cmd_declination_conv cmd_declination_conv_proj_bug\
87 lech level 2fixbug dot17 3dcorner\
88 unconnected-bug\
89 backread.dat corrections.dat depthguage.dat flags.dat karstcompat.dat\
90 lrud.dat nomeasure.dat noteam.dat\
91 badmak.mak\
92 fixfeet.mak utm.mak\
93 clptest.dat clptest.clp\
94 walls.srv\
95 badopts.srv\
96 wallsbaddatum.wpj\
97 wallsdecl.wpj\
98 passage hanging_lrud equatenosuchstn surveytypo\
99 skipafterbadomit passagebad badreadingdotplus badcalibrate calibrate_clino\
100 badunits badbegin anonstn anonstnbad anonstnrev doubleinc reenterlots\
101 cs csbad csbadsdfix csfeet cslonglat omitfixaroundsolve repeatreading\
102 mixedeols utf8bom nonewlineateof suspectreadings cmd_data_default\
103 cmd_data_ignore\
104 quadrant_bearing bad_quadrant_bearing\
105 samename tabinhighlight legacytokens\
106 3dexport \
107 dxffullcoords dxfsurfequate\
108 gpxexport hpglexport jsonexport kmlexport pltexport svgexport\
109"}}
110
111# Test file stnsurvey3.svx missing: pos=fail # We exit before the error count.
112
113LC_ALL=C
114export LC_ALL
115SURVEXLANG=en
116export SURVEXLANG
117
118# Suppress checking for leaks on exit if we're build with lsan - we don't
119# generally waste effort to free all allocations as the OS will reclaim
120# memory on exit.
121LSAN_OPTIONS=leak_check_at_exit=0
122export LSAN_OPTIONS
123
124# Allow datestamps in 3d files (we normalise the expected output for GPX
125# etc) to allow for the datestamp not being fixed, but under SOURCE_DATE_EPOCH
126# the datestamp is omitted entirely which would break those testcases.
127unset SOURCE_DATE_EPOCH
128
129vg_error=123
130vg_log=$testdir/vg.log
131if [ -n "$VALGRIND" ] ; then
132  rm -f "$vg_log"
133  CAVERN="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $CAVERN"
134  DIFFPOS="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $DIFFPOS"
135  DUMP3D="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $DUMP3D"
136  SURVEXPORT="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $SURVEXPORT"
137fi
138
139for file in $TESTS ; do
140  case $file in
141    nonexistent_file*|ONELEG)
142      # ONELEG tests that we don't apply special handling to command line
143      # arguments, only those in *include.
144      realfile= ;;
145    *.*) realfile=$srcdir/$file ;;
146    *) realfile=$srcdir/$file.svx ;;
147  esac
148
149  if [ x"$file" = xONELEG ] && [ -f "ONELEG.SVX" ] ; then
150    echo "Case insensitive filing system - skipping ONELEG testcase"
151    continue
152  fi
153
154  if [ -n "$realfile" ] && [ ! -r "$realfile" ] ; then
155    echo "Don't know how to run test '$file'"
156    exit 1
157  fi
158
159  echo "$file"
160
161  # how many warnings to expect (or empty not to check)
162  warn=
163
164  # how many errors to expect (or empty not to check)
165  error=
166
167  # One of:
168  # yes : diffpos 3D file output with <testcase_name>.pos
169  # no : Check that a 3D file is produced, but not positions in it
170  # fail : Check that a 3D file is NOT produced
171  # 3d : Convert to 3D with survexport, compare dump3d to <testcase_name>.dump
172  # dxf : Convert to DXF with survexport and compare with <testcase_name>.dxf
173  # gpx : Convert to GPX with survexport and compare with <testcase_name>.gpx
174  # json : Convert to JSON with survexport and compare with <testcase_name>.json
175  # kml : Convert to KML with survexport and compare with <testcase_name>.kml
176  # plt : Convert to PLT with survexport and compare with <testcase_name>.plt
177  # svg : Convert to SVG with survexport and compare with <testcase_name>.svg
178  pos=
179
180  case $file in
181    backread.dat|clptest.dat|clptest.clp|depthguage.dat|karstcompat.dat)
182      pos=dump
183      warn=0
184      ;;
185    flags.dat)
186      pos=dump
187      warn=1
188      ;;
189    *.dat)
190      # .dat files can't start with a comment.  All the other .dat tests
191      # have the same settings.
192      pos=yes
193      warn=0
194      ;;
195    nonexistent_file*|ONELEG)
196      # These testcase files don't exist (or for ONELEG exist with a different
197      # case).  They all have the same settings.
198      pos=fail
199      ;;
200    wallsbaddatum.wpj)
201      # .wpj files can't start with a comment.
202      pos=fail
203      warn=0
204      err=1
205      ;;
206    *.wpj)
207      # .wpj files can't start with a comment.
208      pos=dump
209      warn=0
210      ;;
211    *)
212      survexportopts=
213      read header < "$realfile"
214      set dummy $header
215      while shift && [ -n "$1" ] ; do
216        case $1 in
217          pos=*) pos=`expr "$1" : 'pos=\(.*\)'` ;;
218          warn=*) warn=`expr "$1" : 'warn=\(.*\)'` ;;
219          error=*) error=`expr "$1" : 'error=\(.*\)'` ;;
220          survexportopt=*)
221            survexportopts="$survexportopts "`expr "$1" : 'survexportopt=\(.*\)'`
222            ;;
223        esac
224      done
225      ;;
226  esac
227
228  basefile=$srcdir/$file
229  case $file in
230  *.*)
231    input="./$file"
232    basefile=`echo "$basefile"|sed 's/\.[^.]*$//'` ;;
233  *)
234    input="./$file.svx" ;;
235  esac
236  outfile=$basefile.out
237  outfile2=$basefile.altout
238  posfile=$basefile.pos
239  rm -f tmp.*
240  pwd=`pwd`
241  cd "$srcdir"
242  srcdir=. SOURCE_DATE_EPOCH=1 $CAVERN "$input" --output="$pwd/tmp" > "$pwd/tmp.out"
243  exitcode=$?
244  cd "$pwd"
245  test -n "$VERBOSE" && cat tmp.out
246  if [ -n "$VALGRIND" ] ; then
247    if [ $exitcode = "$vg_error" ] ; then
248      cat "$vg_log"
249      rm "$vg_log"
250      exit 1
251    fi
252    rm "$vg_log"
253  fi
254  if test fail = "$pos" ; then
255    # success gives 0, signal (128 + <signal number>)
256    test $exitcode = 1 || exit 1
257  else
258    test $exitcode = 0 || exit 1
259  fi
260  if test -n "$warn" ; then
261    w=`sed '$!d;s/^There were \([0-9]*\).*/\1/p;d' tmp.out`
262    if test x"${w:-0}" != x"$warn" ; then
263      test -n "$VERBOSE" && echo "Got $w warnings, expected $warn"
264      exit 1
265    fi
266  fi
267  if test -n "$error" ; then
268    e=`sed '$!d;s/^There were .* and \([0-9][0-9]*\).*/\1/p;d' tmp.out`
269    if test x"${e:-0}" != x"$error" ; then
270      test -n "$VERBOSE" && echo "Got $e errors, expected $error"
271      exit 1
272    fi
273  fi
274  # Fail if nan, NaN, etc in output (which might be followed by m for metres or
275  # s for seconds).
276  if egrep -q '(^|[^A-Za-z0-9])nan[ms]?($|[^A-Za-z0-9])' tmp.out ; then
277    echo "Not-a-number appears in output"
278    exit 1
279  fi
280
281  case $pos in
282  yes)
283    if test -n "$VERBOSE" ; then
284      $DIFFPOS "$posfile" tmp.3d
285      exitcode=$?
286    else
287      $DIFFPOS "$posfile" tmp.3d > /dev/null
288      exitcode=$?
289    fi
290    if [ -n "$VALGRIND" ] ; then
291      if [ $exitcode = "$vg_error" ] ; then
292        cat "$vg_log"
293        rm "$vg_log"
294        exit 1
295      fi
296      rm "$vg_log"
297    fi
298    [ "$exitcode" = 0 ] || exit 1
299    ;;
300  dump)
301    expectedfile=$basefile.dump
302    tmpfile=tmp.dump
303    $DUMP3D --show-dates --legs tmp.3d > "$tmpfile"
304    exitcode=$?
305    if [ -n "$VALGRIND" ] ; then
306      if [ $exitcode = "$vg_error" ] ; then
307        cat "$vg_log"
308        rm "$vg_log"
309        exit 1
310      fi
311      rm "$vg_log"
312    fi
313    [ "$exitcode" = 0 ] || exit 1
314
315    if test -n "$VERBOSE" ; then
316      $DIFF "$expectedfile" "$tmpfile" || exit 1
317    else
318      $QUIET_DIFF "$expectedfile" "$tmpfile" || exit 1
319    fi
320    ;;
321  dxf|gpx|hpgl|json|kml|plt|svg)
322    # $pos gives us the file extension here.
323    expectedfile=$basefile.$pos
324    tmpfile=tmp.$pos
325    if test -n "$VERBOSE" ; then
326      $SURVEXPORT --defaults$survexportopts tmp.3d "$tmpfile"
327      exitcode=$?
328    else
329      $SURVEXPORT --defaults$survexportopts tmp.3d "$tmpfile" > /dev/null
330      exitcode=$?
331    fi
332    if [ -n "$VALGRIND" ] ; then
333      if [ $exitcode = "$vg_error" ] ; then
334        cat "$vg_log"
335        rm "$vg_log"
336        exit 1
337      fi
338      rm "$vg_log"
339    fi
340    [ "$exitcode" = 0 ] || exit 1
341
342    # Normalise exported file if required.
343    case $pos in
344      dxf)
345        # On x86 excess precision can result in -0.00 for some coordinates.
346        sed 's/-0\.00\>/ 0.00/g' < "$tmpfile" > tmp.tmp
347        mv tmp.tmp "$tmpfile"
348        ;;
349      json)
350        # On x86 excess precision can result in -0.00 for some coordinates.
351        sed 's/-0\.00\>/0.00/g' < "$tmpfile" > tmp.tmp
352        mv tmp.tmp "$tmpfile"
353        ;;
354      gpx)
355        sed 's,<time>[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]Z</time>,<time>REDACTED</time>,;s,survex [0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*,survex REDACTED,' < "$tmpfile" > tmp.tmp
356        mv tmp.tmp "$tmpfile"
357        ;;
358    esac
359
360    if test -n "$VERBOSE" ; then
361      $DIFF "$expectedfile" "$tmpfile" || exit 1
362    else
363      $QUIET_DIFF "$expectedfile" "$tmpfile" || exit 1
364    fi
365    ;;
366  3d)
367    expectedfile=$basefile.dump
368    tmpfile=tmp.dump
369    if test -n "$VERBOSE" ; then
370      SOURCE_DATE_EPOCH=1 $SURVEXPORT --defaults$survexportopts tmp.3d "$tmpfile.3d"
371      exitcode=$?
372    else
373      SOURCE_DATE_EPOCH=1 $SURVEXPORT --defaults$survexportopts tmp.3d "$tmpfile.3d" > /dev/null
374      exitcode=$?
375    fi
376    $DUMP3D --show-dates --legs "$tmpfile.3d" > "$tmpfile"
377    if [ -n "$VALGRIND" ] ; then
378      if [ $exitcode = "$vg_error" ] ; then
379        cat "$vg_log"
380        rm "$vg_log"
381        exit 1
382      fi
383      rm "$vg_log"
384    fi
385    [ "$exitcode" = 0 ] || exit 1
386
387    if test -n "$VERBOSE" ; then
388      $DIFF "$expectedfile" "$tmpfile" || exit 1
389    else
390      $QUIET_DIFF "$expectedfile" "$tmpfile" || exit 1
391    fi
392    ;;
393  no)
394    test -f tmp.3d || exit 1 ;;
395  fail)
396    test -f tmp.3d && exit 1
397    # Check that last line doesn't contains "Bug in program detected"
398    case `tail -n 1 tmp.out` in
399    *"Bug in program detected"*) exit 1 ;;
400    esac ;;
401  *)
402    echo "Bad value for pos: '$pos'" ; exit 1 ;;
403  esac
404
405  if test -f "$outfile" ; then
406    # Version and time used info from output, working around Apple's stone-age
407    # sed.
408    sed '1,/^Copyright/d;/^\(CPU \)*[Tt]ime used  *[0-9][0-9.]*s$/d;s!.*/src/\(cavern: \)!\1!' tmp.out > tmp.out2
409    mv tmp.out2 tmp.out
410    # Check output is as expected.
411    if $QUIET_DIFF "$outfile" tmp.out ; then
412      : # Matches.
413    elif [ -f "$outfile2" ] && $QUIET_DIFF "$outfile2" tmp.out ; then
414      : # Matches alternative output (e.g. due to older PROJ).
415    else
416      test -z "$VERBOSE" || $DIFF "$outfile" tmp.out
417      exit 1
418    fi
419  fi
420  rm -f tmp.*
421done
422test -n "$VERBOSE" && echo "Test passed"
423exit 0
Note: See TracBrowser for help on using the repository browser.