source: git/tests/cavern.tst @ f15c53d9

stereo-2025
Last change on this file since f15c53d9 was f15c53d9, checked in by Olly Betts <olly@…>, 4 months ago

Implement parsing of *copyright

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