source: git/tests/cavern.tst @ 74d3edd

faster-cavernloglog-selectwalls-datawalls-data-hanging-as-warning
Last change on this file since 74d3edd was d3fa693, checked in by Olly Betts <olly@…>, 4 weeks ago

Improve error for survey and station with same name

Previously this error was not emitted in the case where a name was
used first for a station, and then as a survey on an explicitly
prefixed name.

Also the problematic name is now highlighted within the line
shown for context.

Closes https://github.com/ojwb/survex/pull/4, reported by Thomas
Holder.

  • Property mode set to 100755
File size: 10.9 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
22# allow us to run tests standalone more easily
23: ${srcdir="$testdir"}
24
25# force VERBOSE if we're run on a subset of tests
26test -n "$*" && VERBOSE=1
27
28test -x "$testdir"/../src/cavern || testdir=.
29
30# Make testdir absolute, so we can cd before running cavern to get a consistent
31# path in diagnostic messages.
32testdir=`(cd "$testdir" && pwd)`
33
34: ${CAVERN="$testdir"/../src/cavern}
35: ${DIFFPOS="$testdir"/../src/diffpos}
36: ${DUMP3D="$testdir"/../src/dump3d}
37: ${SURVEXPORT="$testdir"/../src/survexport}
38
39: ${TESTS=${*:-"singlefix singlereffix oneleg midpoint noose cross firststn\
40 deltastar deltastar2 bug3 calibrate_tape nosurvey2 cartesian cartesian2\
41 lengthunits angleunits cmd_alias cmd_alias_bad cmd_truncate cmd_case cmd_fix\
42 cmd_solve cmd_entrance cmd_entrance_bad cmd_sd cmd_sd_bad cmd_fix_bad cmd_set\
43 cmd_set_bad cmd_set_dot_in_name\
44 beginroot revcomplist break_replace_pfx bug0 bug1 bug2 bug4 bug5\
45 expobug require export export2 includecomment\
46 self_loop self_eq_loop reenterwarn cmd_default cmd_prefix cmd_prefix_bad\
47 cmd_begin_bad cmd_equate_bad cmd_export_bad\
48 singlefixerr singlereffixerr\
49 begin_no_end end_no_begin end_no_begin_nest require_fail\
50 exporterr1 exporterr2 exporterr3 exporterr4 exporterr5\
51 exporterr1b exporterr2b exporterr3b exporterr6 exporterr6b\
52 hanging_cpt badinc badinc2 badinc3 badinc4 badinc5.mak nonexistent_file ONELEG\
53 stnsurvey1 stnsurvey2\
54 tapelessthandepth longname chinabug chinabug2\
55 multinormal multinormignall multidiving multicylpolar multicartesian\
56 multinosurv multinormalbad multibug\
57 cmd_title cmd_titlebad cmd_dummy cmd_infer cmd_date cmd_datebad cmd_datebad2\
58 cartes diving cylpolar normal normal_bad normignall nosurv cmd_flags\
59 bad_cmd_flags plumb unusedstation exportnakedbegin oldestyle bugdz\
60 baddatacylpolar badnewline badquantities imgoffbyone infereqtopofil 3sdfixbug\
61 omitclino back back2 bad_back\
62 notentranceorexport inferunknown inferexports bad_units_factor\
63 bad_units_qlist\
64 percent_gradient dotinsurvey leandroclino lowsd revdir gettokennullderef\
65 nosurveyhanging cmd_solve_nothing cmd_solve_nothing_implicit\
66 cmd_calibrate cmd_declination cmd_declination_auto cmd_declination_auto_bad\
67 cmd_declination_conv cmd_declination_conv_proj_bug\
68 lech level 2fixbug dot17 3dcorner\
69 unconnected-bug\
70 backread.dat corrections.dat depthguage.dat flags.dat karstcompat.dat\
71 lrud.dat nomeasure.dat noteam.dat\
72 badmak.mak\
73 fixfeet.mak utm.mak\
74 clptest.dat clptest.clp\
75 surfequate passage hanging_lrud equatenosuchstn surveytypo\
76 skipafterbadomit passagebad badreadingdotplus badcalibrate calibrate_clino\
77 badunits badbegin anonstn anonstnbad anonstnrev doubleinc reenterlots\
78 cs csbad csbadsdfix csfeet cslonglat omitfixaroundsolve repeatreading\
79 mixedeols utf8bom nonewlineateof suspectreadings cmd_data_default\
80 quadrant_bearing bad_quadrant_bearing\
81 samename\
82 gpxexport jsonexport kmlexport pltexport svgexport\
83"}}
84
85# Test file stnsurvey3.svx missing: pos=fail # We exit before the error count.
86
87LC_ALL=C
88export LC_ALL
89SURVEXLANG=en
90export SURVEXLANG
91
92# Suppress checking for leaks on exit if we're build with lsan - we don't
93# generally waste effort to free all allocations as the OS will reclaim
94# memory on exit.
95LSAN_OPTIONS=leak_check_at_exit=0
96export LSAN_OPTIONS
97
98# Allow datestamps in 3d files (we normalise the expected output for GPX
99# etc) to allow for the datestamp not being fixed, but under SOURCE_DATE_EPOCH
100# the datestamp is omitted entirely which would break those testcases.
101unset SOURCE_DATE_EPOCH
102
103vg_error=123
104vg_log=$testdir/vg.log
105if [ -n "$VALGRIND" ] ; then
106  rm -f "$vg_log"
107  CAVERN="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $CAVERN"
108  DIFFPOS="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $DIFFPOS"
109  DUMP3D="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $DUMP3D"
110  SURVEXPORT="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $SURVEXPORT"
111fi
112
113for file in $TESTS ; do
114  case $file in
115    nonexistent_file*|ONELEG)
116      # ONELEG tests that we don't apply special handling to command line
117      # arguments, only those in *include.
118      realfile= ;;
119    *.*) realfile=$srcdir/$file ;;
120    *) realfile=$srcdir/$file.svx ;;
121  esac
122
123  if [ x"$file" = xONELEG ] && [ -f "ONELEG.SVX" ] ; then
124    echo "Case insensitive filing system - skipping ONELEG testcase"
125    continue
126  fi
127
128  if [ -n "$realfile" ] && [ ! -r "$realfile" ] ; then
129    echo "Don't know how to run test '$file'"
130    exit 1
131  fi
132
133  echo "$file"
134
135  # how many warnings to expect (or empty not to check)
136  warn=
137
138  # how many errors to expect (or empty not to check)
139  error=
140
141  # One of:
142  # yes : diffpos 3D file output with <testcase_name>.pos
143  # no : Check that a 3D file is produced, but not positions in it
144  # fail : Check that a 3D file is NOT produced
145  # dxf : Convert to DXF with survexport and compare with <testcase_name>.dxf
146  # gpx : Convert to GPX with survexport and compare with <testcase_name>.gpx
147  # json : Convert to JSON with survexport and compare with <testcase_name>.json
148  # kml : Convert to KML with survexport and compare with <testcase_name>.kml
149  # plt : Convert to PLT with survexport and compare with <testcase_name>.plt
150  # svg : Convert to SVG with survexport and compare with <testcase_name>.svg
151  pos=
152
153  case $file in
154    backread.dat|clptest.dat|clptest.clp|depthguage.dat|flags.dat|karstcompat.dat)
155      pos=dump
156      warn=0
157      ;;
158    *.dat)
159      # .dat files can't start with a comment.  All the other .dat tests
160      # have the same settings.
161      pos=yes
162      warn=0
163      ;;
164    nonexistent_file*|ONELEG)
165      # These testcase files don't exist (or for ONELEG exist with a different
166      # case).  They all have the same settings.
167      pos=fail
168      ;;
169    *)
170      survexportopts=
171      read header < "$realfile"
172      set dummy $header
173      while shift && [ -n "$1" ] ; do
174        case $1 in
175          pos=*) pos=`expr "$1" : 'pos=\(.*\)'` ;;
176          warn=*) warn=`expr "$1" : 'warn=\(.*\)'` ;;
177          error=*) error=`expr "$1" : 'error=\(.*\)'` ;;
178          survexportopt=*)
179            survexportopts="$survexportopts "`expr "$1" : 'survexportopt=\(.*\)'`
180            ;;
181        esac
182      done
183      ;;
184  esac
185
186  basefile=$srcdir/$file
187  case $file in
188  *.*)
189    input="./$file"
190    basefile=`echo "$basefile"|sed 's/\.[^.]*$//'` ;;
191  *)
192    input="./$file.svx" ;;
193  esac
194  outfile=$basefile.out
195  outfile2=$basefile.altout
196  posfile=$basefile.pos
197  rm -f tmp.*
198  pwd=`pwd`
199  cd "$srcdir"
200  srcdir=. SOURCE_DATE_EPOCH=1 $CAVERN "$input" --output="$pwd/tmp" > "$pwd/tmp.out"
201  exitcode=$?
202  cd "$pwd"
203  test -n "$VERBOSE" && cat tmp.out
204  if [ -n "$VALGRIND" ] ; then
205    if [ $exitcode = "$vg_error" ] ; then
206      cat "$vg_log"
207      rm "$vg_log"
208      exit 1
209    fi
210    rm "$vg_log"
211  fi
212  if test fail = "$pos" ; then
213    # success gives 0, signal (128 + <signal number>)
214    test $exitcode = 1 || exit 1
215  else
216    test $exitcode = 0 || exit 1
217  fi
218  if test -n "$warn" ; then
219    w=`sed '$!d;s/^There were \([0-9]*\).*/\1/p;d' tmp.out`
220    if test x"${w:-0}" != x"$warn" ; then
221      test -n "$VERBOSE" && echo "Got $w warnings, expected $warn"
222      exit 1
223    fi
224  fi
225  if test -n "$error" ; then
226    e=`sed '$!d;s/^There were .* and \([0-9][0-9]*\).*/\1/p;d' tmp.out`
227    if test x"${e:-0}" != x"$error" ; then
228      test -n "$VERBOSE" && echo "Got $e errors, expected $error"
229      exit 1
230    fi
231  fi
232  # Fail if nan, NaN, etc in output (which might be followed by m for metres or
233  # s for seconds).
234  if egrep -q '(^|[^A-Za-z0-9])nan[ms]?($|[^A-Za-z0-9])' tmp.out ; then
235    echo "Not-a-number appears in output"
236    exit 1
237  fi
238
239  case $pos in
240  yes)
241    if test -n "$VERBOSE" ; then
242      $DIFFPOS "$posfile" tmp.3d
243      exitcode=$?
244    else
245      $DIFFPOS "$posfile" tmp.3d > /dev/null
246      exitcode=$?
247    fi
248    if [ -n "$VALGRIND" ] ; then
249      if [ $exitcode = "$vg_error" ] ; then
250        cat "$vg_log"
251        rm "$vg_log"
252        exit 1
253      fi
254      rm "$vg_log"
255    fi
256    [ "$exitcode" = 0 ] || exit 1
257    ;;
258  dump)
259    expectedfile=$basefile.dump
260    tmpfile=tmp.dump
261    $DUMP3D --show-dates --legs tmp.3d > "$tmpfile"
262    exitcode=$?
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    [ "$exitcode" = 0 ] || exit 1
272
273    if test -n "$VERBOSE" ; then
274      diff "$expectedfile" "$tmpfile" || exit 1
275    else
276      cmp -s "$expectedfile" "$tmpfile" || exit 1
277    fi
278    ;;
279  dxf|gpx|json|kml|plt|svg)
280    # $pos gives us the file extension here.
281    expectedfile=$basefile.$pos
282    tmpfile=tmp.$pos
283    if test -n "$VERBOSE" ; then
284      $SURVEXPORT --defaults$survexportopts tmp.3d "$tmpfile"
285      exitcode=$?
286    else
287      $SURVEXPORT --defaults$survexportopts tmp.3d "$tmpfile" > /dev/null
288      exitcode=$?
289    fi
290    if [ -n "$VALGRIND" ] ; then
291      if [ $exitcode = "$vg_error" ] ; then
292        cat "$vg_log"
293        rm "$vg_log"
294        exit 1
295      fi
296      rm "$vg_log"
297    fi
298    [ "$exitcode" = 0 ] || exit 1
299
300    # Normalise exported file if required.
301    case $pos in
302      gpx)
303        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
304        mv tmp.tmp "$tmpfile"
305        ;;
306    esac
307
308    if test -n "$VERBOSE" ; then
309      diff "$expectedfile" "$tmpfile" || exit 1
310    else
311      cmp -s "$expectedfile" "$tmpfile" || exit 1
312    fi
313    ;;
314  no)
315    test -f tmp.3d || exit 1 ;;
316  fail)
317    test -f tmp.3d && exit 1
318    # Check that last line doesn't contains "Bug in program detected"
319    case `tail -n 1 tmp.out` in
320    *"Bug in program detected"*) exit 1 ;;
321    esac ;;
322  *)
323    echo "Bad value for pos: '$pos'" ; exit 1 ;;
324  esac
325
326  if test -f "$outfile" ; then
327    # Version and time used info from output, working around Apple's stone-age
328    # sed.
329    sed '1,/^Copyright/d;/^\(CPU \)*[Tt]ime used  *[0-9][0-9.]*s$/d;s!.*/src/\(cavern: \)!\1!' tmp.out > tmp.out2
330    mv tmp.out2 tmp.out
331    # Check output is as expected.
332    if cmp -s "$outfile" tmp.out ; then
333      : # Matches.
334    elif [ -f "$outfile2" ] && cmp -s "$outfile2" tmp.out ; then
335      : # Matches alternative output (e.g. due to older PROJ).
336    else
337      test -z "$VERBOSE" || diff "$outfile" tmp.out
338      exit 1
339    fi
340  fi
341  rm -f tmp.*
342done
343test -n "$VERBOSE" && echo "Test passed"
344exit 0
Note: See TracBrowser for help on using the repository browser.