source: git/tests/cavern.tst @ a948c08

Last change on this file since a948c08 was a948c08, checked in by Olly Betts <olly@…>, 4 days ago

Improve handling of VERBOSE in tests

Previously VERBOSE showed output from all testcases, even ones which
passed. Now we only show output from testcases which fail for
VERBOSE=1. Other non-empty values of VERBOSE continue to show all
output for cavern.tst and smoke.tst, but have the same effect as
VERBOSE=1 for other tests.

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