source: git/tests/cavern.tst

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

Reject some invalid Walls readings

Multi-component readings shouldn't allow a decimal point in anything but
the final component, and cavern now checks this.

Some examples of invalid readings which now give an error with cavern
are 12.5i3. 12.5:29, 12.5:29:30 and 12:29.5:30.

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