source: git/tests/cavern.tst @ cdc771d

stereo-2025
Last change on this file since cdc771d was 9918c3d, checked in by Olly Betts <olly@…>, 7 months ago

Remove now-bogus assertion to handle hanging data

If a delta-star transform was applied to survey data not connected to a
fixed point then we would fail with an assertion (since 1.4.10 made
unconnected data a warning instead of an error). Reported by Philip
Balister.

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