source: git/tests/cavern.tst @ 66be513

stereo-2025
Last change on this file since 66be513 was bf9faf6, checked in by Olly Betts <olly@…>, 9 months ago

Fix component counting bugs

The component count was wrong in some cases, and we calculate the number
of loops using this component count, so the loop count would be wrong by
the same amount in these cases.

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