source: git/tests/cavern.tst @ a286d26

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

Add tests of bad *data nosurvey commands

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