source: git/tests/cavern.tst @ cbf7643

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

Normalise -0.00 in DXF bounds properly

The existing normalisation worked for coordinates, but introduced
a space before bounds.

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