source: git/tests/cavern.tst

Last change on this file was 50f0ad5, checked in by Olly Betts <olly@…>, 5 weeks ago

Parse *instrument commands

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