source: git/tests/cavern.tst @ 124892c

Last change on this file since 124892c was 3a2a157, checked in by Olly Betts <olly@…>, 20 hours ago

Walls: Downgrade some "Unknown command" to warning

There are some invalid directives which Walls quietly accepts, so
downgrade the error to a warning for these.

Issue highlighted by a dataset from Darek Lubomski.

  • 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\
110 unknowndirective.srv\
111 wallsbaddatum.wpj\
112 wallsdecl.wpj\
113 passage hanging_lrud equatenosuchstn surveytypo\
114 skipafterbadomit passagebad badreadingdotplus badcalibrate calibrate_clino\
115 badunits badbegin anonstn anonstnbad anonstnrev doubleinc reenterlots\
116 cs csbad csbadsdfix csfeet cslonglat omitfixaroundsolve repeatreading\
117 mixedeols utf8bom nonewlineateof suspectreadings cmd_data_default\
118 cmd_data_ignore\
119 quadrant_bearing bad_quadrant_bearing\
120 samename tabinhighlight legacytokens\
121 component_count_bug component_count_bug2\
122 $TESTS_
123"}}
124
125# Skip 3dexport...svgexport for mingw for now FIXME
126
127# Test file stnsurvey3.svx missing: pos=fail # We exit before the error count.
128
129LC_ALL=C
130export LC_ALL
131SURVEXLANG=en
132export SURVEXLANG
133
134# Suppress checking for leaks on exit if we're build with lsan - we don't
135# generally waste effort to free all allocations as the OS will reclaim
136# memory on exit.
137LSAN_OPTIONS=leak_check_at_exit=0
138export LSAN_OPTIONS
139
140# Allow datestamps in 3d files (we normalise the expected output for GPX
141# etc) to allow for the datestamp not being fixed, but under SOURCE_DATE_EPOCH
142# the datestamp is omitted entirely which would break those testcases.
143unset SOURCE_DATE_EPOCH
144
145vg_error=123
146vg_log=$testdir/vg.log
147if [ -n "$VALGRIND" ] ; then
148  rm -f "$vg_log"
149  CAVERN="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $CAVERN"
150  DIFFPOS="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $DIFFPOS"
151  DUMP3D="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $DUMP3D"
152  SURVEXPORT="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $SURVEXPORT"
153fi
154
155for file in $TESTS ; do
156  case $file in
157    nonexistent_file*|ONELEG)
158      # ONELEG tests that we don't apply special handling to command line
159      # arguments, only those in *include.
160      realfile= ;;
161    *.*) realfile=$srcdir/$file ;;
162    *) realfile=$srcdir/$file.svx ;;
163  esac
164
165  if [ x"$file" = xONELEG ] && [ -f "ONELEG.SVX" ] ; then
166    echo "Case insensitive filing system - skipping ONELEG testcase"
167    continue
168  fi
169
170  if [ -n "$realfile" ] && [ ! -r "$realfile" ] ; then
171    echo "Don't know how to run test '$file'"
172    exit 1
173  fi
174
175  echo "$file"
176
177  # how many warnings to expect (or empty not to check)
178  warn=
179
180  # how many errors to expect (or empty not to check)
181  error=
182
183  # One of:
184  # yes : diffpos 3D file output with <testcase_name>.pos
185  # no : Check that a 3D file is produced, but not positions in it
186  # fail : Check that a 3D file is NOT produced
187  # dump : Compare output of dump3d to <testcase_name>.dump
188  # 3d : Convert to 3D with survexport, compare dump3d to <testcase_name>.dump
189  # dxf : Convert to DXF with survexport and compare with <testcase_name>.dxf
190  # gpx : Convert to GPX with survexport and compare with <testcase_name>.gpx
191  # json : Convert to JSON with survexport and compare with <testcase_name>.json
192  # kml : Convert to KML with survexport and compare with <testcase_name>.kml
193  # plt : Convert to PLT with survexport and compare with <testcase_name>.plt
194  # svg : Convert to SVG with survexport and compare with <testcase_name>.svg
195  pos=
196
197  case $file in
198    backread.dat|clptest.dat|clptest.clp|depthguage.dat|karstcompat.dat)
199      pos=dump
200      warn=0
201      ;;
202    flags.dat)
203      pos=dump
204      warn=1
205      ;;
206    *.dat)
207      # .dat files can't start with a comment.  All the other .dat tests
208      # have the same settings.
209      pos=yes
210      warn=0
211      ;;
212    nonexistent_file*|ONELEG)
213      # These testcase files don't exist (or for ONELEG exist with a different
214      # case).  They all have the same settings.
215      pos=fail
216      ;;
217    wallsbaddatum.wpj)
218      # .wpj files can't start with a comment.
219      pos=fail
220      warn=0
221      err=1
222      ;;
223    *.wpj)
224      # .wpj files can't start with a comment.
225      pos=dump
226      warn=0
227      ;;
228    *)
229      survexportopts=
230      read header < "$realfile"
231      set dummy $header
232      while shift && [ -n "$1" ] ; do
233        case $1 in
234          pos=*) pos=`expr "$1" : 'pos=\(.*\)'` ;;
235          warn=*) warn=`expr "$1" : 'warn=\(.*\)'` ;;
236          error=*) error=`expr "$1" : 'error=\(.*\)'` ;;
237          survexportopt=*)
238            survexportopts="$survexportopts "`expr "$1" : 'survexportopt=\(.*\)'`
239            ;;
240        esac
241      done
242      ;;
243  esac
244
245  basefile=$srcdir/$file
246  case $file in
247  *.*)
248    input="./$file"
249    basefile=`echo "$basefile"|sed 's/\.[^.]*$//'` ;;
250  *)
251    input="./$file.svx" ;;
252  esac
253  outfile=$basefile.out
254  outfile2=$basefile.altout
255  posfile=$basefile.pos
256  rm -f tmp.*
257  pwd=`pwd`
258  cd "$srcdir"
259  srcdir=. SOURCE_DATE_EPOCH=1 $CAVERN "$input" --output="$pwd/tmp" > "$pwd/tmp.out"
260  exitcode=$?
261  cd "$pwd"
262  if test "$VERBOSE" = 1 ; then
263    if test fail = "$pos" ; then
264      test $exitcode != 0 || cat tmp.out
265    else
266      test $exitcode = 0 || cat tmp.out
267    fi
268  elif test -n "$VERBOSE" ; then
269    cat tmp.out
270  fi
271  if [ -n "$VALGRIND" ] ; then
272    if [ $exitcode = "$vg_error" ] ; then
273      cat "$vg_log"
274      rm "$vg_log"
275      exit 1
276    fi
277    rm "$vg_log"
278  fi
279  if test fail = "$pos" ; then
280    # success gives 0, signal (128 + <signal number>)
281    test $exitcode = 1 || exit 1
282  else
283    test $exitcode = 0 || exit 1
284  fi
285  if test -n "$warn" ; then
286    w=`sed '$!d;s/^There were \([0-9]*\).*/\1/p;d' tmp.out`
287    if test x"${w:-0}" != x"$warn" ; then
288      test -n "$VERBOSE" && echo "Got $w warnings, expected $warn"
289      exit 1
290    fi
291  fi
292  if test -n "$error" ; then
293    e=`sed '$!d;s/^There were .* and \([0-9][0-9]*\).*/\1/p;d' tmp.out`
294    if test x"${e:-0}" != x"$error" ; then
295      test -n "$VERBOSE" && echo "Got $e errors, expected $error"
296      exit 1
297    fi
298  fi
299  # Fail if nan, NaN, etc in output (which might be followed by m for metres or
300  # s for seconds).
301  if egrep -q '(^|[^A-Za-z0-9])nan[ms]?($|[^A-Za-z0-9])' tmp.out ; then
302    echo "Not-a-number appears in output"
303    exit 1
304  fi
305
306  case $pos in
307  yes)
308    if test "$VERBOSE" = 1 ; then
309      $DIFFPOS "$posfile" tmp.3d > tmp.stdout
310      exitcode=$?
311      test $exitcode = 0 || cat tmp.stdout
312      rm tmp.stdout
313    elif test -n "$VERBOSE" ; then
314      $DIFFPOS "$posfile" tmp.3d
315      exitcode=$?
316    else
317      $DIFFPOS "$posfile" tmp.3d > /dev/null
318      exitcode=$?
319    fi
320    if [ -n "$VALGRIND" ] ; then
321      if [ $exitcode = "$vg_error" ] ; then
322        cat "$vg_log"
323        rm "$vg_log"
324        exit 1
325      fi
326      rm "$vg_log"
327    fi
328    [ "$exitcode" = 0 ] || exit 1
329    ;;
330  dump)
331    expectedfile=$basefile.dump
332    tmpfile=tmp.dump
333    $DUMP3D --show-dates --legs tmp.3d > "$tmpfile"
334    exitcode=$?
335    if [ -n "$VALGRIND" ] ; then
336      if [ $exitcode = "$vg_error" ] ; then
337        cat "$vg_log"
338        rm "$vg_log"
339        exit 1
340      fi
341      rm "$vg_log"
342    fi
343    [ "$exitcode" = 0 ] || exit 1
344
345    if ! $QUIET_DIFF "$expectedfile" "$tmpfile" ; then
346      test -z "$VERBOSE" || $DIFF "$expectedfile" "$tmpfile"
347      exit 1
348    fi
349    ;;
350  dxf|gpx|hpgl|json|kml|plt|svg)
351    # $pos gives us the file extension here.
352    expectedfile=$basefile.$pos
353    tmpfile=tmp.$pos
354    if test "$VERBOSE" = 1 ; then
355      $SURVEXPORT --defaults$survexportopts tmp.3d "$tmpfile" > tmp.stdout
356      exitcode=$?
357      test $exitcode = 0 || cat tmp.stdout
358      rm tmp.stdout
359    elif test -n "$VERBOSE" ; then
360      $SURVEXPORT --defaults$survexportopts tmp.3d "$tmpfile"
361      exitcode=$?
362    else
363      $SURVEXPORT --defaults$survexportopts tmp.3d "$tmpfile" > /dev/null
364      exitcode=$?
365    fi
366    if [ -n "$VALGRIND" ] ; then
367      if [ $exitcode = "$vg_error" ] ; then
368        cat "$vg_log"
369        rm "$vg_log"
370        exit 1
371      fi
372      rm "$vg_log"
373    fi
374    [ "$exitcode" = 0 ] || exit 1
375
376    # Normalise exported file if required.
377    case $pos in
378      dxf)
379        # On x86 excess precision can result in -0.00 for some coordinates.
380        sed 's/^-0\.00\>/0.00/;s/ -0\.00\>/  0.00/g' < "$tmpfile" > tmp.tmp
381        mv tmp.tmp "$tmpfile"
382        ;;
383      json)
384        # On x86 excess precision can result in -0.00 for some coordinates.
385        sed 's/-0\.00\>/0.00/g' < "$tmpfile" > tmp.tmp
386        mv tmp.tmp "$tmpfile"
387        ;;
388      gpx)
389        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
390        mv tmp.tmp "$tmpfile"
391        ;;
392    esac
393
394    if ! $QUIET_DIFF "$expectedfile" "$tmpfile" ; then
395      test -z "$VERBOSE" || $DIFF "$expectedfile" "$tmpfile"
396      exit 1
397    fi
398    ;;
399  3d)
400    expectedfile=$basefile.dump
401    tmpfile=tmp.dump
402    if test "$VERBOSE" = 1 ; then
403      SOURCE_DATE_EPOCH=1 $SURVEXPORT --defaults$survexportopts tmp.3d "$tmpfile.3d" > tmp.stdout
404      exitcode=$?
405      test $exitcode = 0 || cat tmp.stdout
406    elif test -n "$VERBOSE" ; then
407      SOURCE_DATE_EPOCH=1 $SURVEXPORT --defaults$survexportopts tmp.3d "$tmpfile.3d"
408      exitcode=$?
409    else
410      SOURCE_DATE_EPOCH=1 $SURVEXPORT --defaults$survexportopts tmp.3d "$tmpfile.3d" > /dev/null
411      exitcode=$?
412    fi
413    $DUMP3D --show-dates --legs "$tmpfile.3d" > "$tmpfile"
414    if [ -n "$VALGRIND" ] ; then
415      if [ $exitcode = "$vg_error" ] ; then
416        cat "$vg_log"
417        rm "$vg_log"
418        exit 1
419      fi
420      rm "$vg_log"
421    fi
422    [ "$exitcode" = 0 ] || exit 1
423
424    if ! $QUIET_DIFF "$expectedfile" "$tmpfile" ; then
425      test -z "$VERBOSE" || $DIFF "$expectedfile" "$tmpfile"
426      exit 1
427    fi
428    ;;
429  no)
430    test -f tmp.3d || exit 1 ;;
431  fail)
432    test -f tmp.3d && exit 1
433    # Check that last line doesn't contains "Bug in program detected"
434    case `tail -n 1 tmp.out` in
435    *"Bug in program detected"*) exit 1 ;;
436    esac ;;
437  *)
438    echo "Bad value for pos: '$pos'" ; exit 1 ;;
439  esac
440
441  if test -f "$outfile" ; then
442    # Version and time used info from output, working around Apple's stone-age
443    # sed.
444    sed '1,/^Copyright/d;/^\(CPU \)*[Tt]ime used  *[0-9][0-9.]*s$/d;s!.*/src/\(cavern: \)!\1!' tmp.out > tmp.out2
445    mv tmp.out2 tmp.out
446    # Check output is as expected.
447    if $QUIET_DIFF "$outfile" tmp.out ; then
448      : # Matches.
449    elif [ -f "$outfile2" ] && $QUIET_DIFF "$outfile2" tmp.out ; then
450      : # Matches alternative output (e.g. due to older PROJ).
451    else
452      test -z "$VERBOSE" || $DIFF "$outfile" tmp.out
453      exit 1
454    fi
455  fi
456  rm -f tmp.*
457done
458test -n "$VERBOSE" && echo "Test passed"
459exit 0
Note: See TracBrowser for help on using the repository browser.