source: git/tests/cavern.tst

log-select
Last change on this file 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
RevLine 
[fbc3a20]1#!/bin/sh
[b4fe9fb]2#
3# Survex test suite - cavern tests
[fdffa7d]4# Copyright (C) 1999-2024 Olly Betts
[b4fe9fb]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
[d333899]18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
[fbc3a20]19
[d4d8efe]20testdir=`echo $0 | sed 's!/[^/]*$!!' || echo '.'`
21
[6b8ff5b]22# allow us to run tests standalone more easily
[d4d8efe]23: ${srcdir="$testdir"}
[647407d]24
[64b4d1c]25# force VERBOSE if we're run on a subset of tests
26test -n "$*" && VERBOSE=1
27
[87681b8]28test -x "$testdir"/../src/cavern || testdir=.
29
[9ef8aa6]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
[d4d8efe]34: ${CAVERN="$testdir"/../src/cavern}
35: ${DIFFPOS="$testdir"/../src/diffpos}
[fdffa7d]36: ${DUMP3D="$testdir"/../src/dump3d}
[79b32a95]37: ${SURVEXPORT="$testdir"/../src/survexport}
[647407d]38
[e0c8f98]39: ${TESTS=${*:-"singlefix singlereffix oneleg midpoint noose cross firststn\
[107b8bd]40 deltastar deltastar2 bug3 calibrate_tape nosurvey2 cartesian cartesian2\
[4772e46]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\
[5d59477]43 cmd_set_bad cmd_set_dot_in_name\
44 beginroot revcomplist break_replace_pfx bug0 bug1 bug2 bug4 bug5\
[cfa16ef]45 expobug require export export2 includecomment\
[4fb15a1]46 self_loop self_eq_loop reenterwarn cmd_default cmd_prefix cmd_prefix_bad\
[b9c82c2]47 cmd_begin_bad cmd_equate_bad cmd_export_bad\
[cfa16ef]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\
[c6ff64b]52 hanging_cpt badinc badinc2 badinc3 badinc4 badinc5.mak nonexistent_file ONELEG\
[2b0cec5]53 stnsurvey1 stnsurvey2\
[0af7076]54 tapelessthandepth longname chinabug chinabug2\
[54c4612]55 multinormal multinormignall multidiving multicylpolar multicartesian\
56 multinosurv multinormalbad multibug\
[e0c7cd1]57 cmd_title cmd_titlebad cmd_dummy cmd_infer cmd_date cmd_datebad cmd_datebad2\
[4fb15a1]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\
[5d1c60c]61 omitclino back back2 bad_back\
[a26c346]62 notentranceorexport inferunknown inferexports bad_units_factor\
[699bf50]63 bad_units_qlist\
[b4fe9fb]64 percent_gradient dotinsurvey leandroclino lowsd revdir gettokennullderef\
[dfe4a520]65 nosurveyhanging cmd_solve_nothing cmd_solve_nothing_implicit\
[58edecc]66 cmd_calibrate cmd_declination cmd_declination_auto cmd_declination_auto_bad\
67 cmd_declination_conv cmd_declination_conv_proj_bug\
[850fdc4]68 lech level 2fixbug dot17 3dcorner\
[be4d0a0]69 unconnected-bug\
[1fbe9d43]70 backread.dat corrections.dat depthguage.dat flags.dat karstcompat.dat\
71 lrud.dat nomeasure.dat noteam.dat\
[ec580039]72 badmak.mak\
[d624d86]73 fixfeet.mak utm.mak\
[bf3acff]74 clptest.dat clptest.clp\
[e363f8b]75 surfequate passage hanging_lrud equatenosuchstn surveytypo\
[da96015]76 skipafterbadomit passagebad badreadingdotplus badcalibrate calibrate_clino\
[c092d72]77 badunits badbegin anonstn anonstnbad anonstnrev doubleinc reenterlots\
[567efed]78 cs csbad csbadsdfix csfeet cslonglat omitfixaroundsolve repeatreading\
[65b2851]79 mixedeols utf8bom nonewlineateof suspectreadings cmd_data_default\
[5a0ab6a]80 quadrant_bearing bad_quadrant_bearing\
[d3fa693]81 samename\
[8c4cefb]82 gpxexport jsonexport kmlexport pltexport svgexport\
[c092d72]83"}}
[cd971de]84
[2b0cec5]85# Test file stnsurvey3.svx missing: pos=fail # We exit before the error count.
86
[cd971de]87LC_ALL=C
88export LC_ALL
[6e47b72]89SURVEXLANG=en
[cd971de]90export SURVEXLANG
[4515ba18]91
[43e8c72]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
[b1200a6]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
[67a2822]103vg_error=123
[9f5bcd3]104vg_log=$testdir/vg.log
[67a2822]105if [ -n "$VALGRIND" ] ; then
106  rm -f "$vg_log"
107  CAVERN="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $CAVERN"
[38c4c5c]108  DIFFPOS="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $DIFFPOS"
[fdffa7d]109  DUMP3D="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $DUMP3D"
[79b32a95]110  SURVEXPORT="$VALGRIND --log-file=$vg_log --error-exitcode=$vg_error $SURVEXPORT"
[67a2822]111fi
112
[4515ba18]113for file in $TESTS ; do
[2b0cec5]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= ;;
[a69860f]119    *.*) realfile=$srcdir/$file ;;
120    *) realfile=$srcdir/$file.svx ;;
[2b0cec5]121  esac
122
[858a791]123  if [ x"$file" = xONELEG ] && [ -f "ONELEG.SVX" ] ; then
124    echo "Case insensitive filing system - skipping ONELEG testcase"
125    continue
126  fi
127
[2b0cec5]128  if [ -n "$realfile" ] && [ ! -r "$realfile" ] ; then
[a69860f]129    echo "Don't know how to run test '$file'"
130    exit 1
[2b0cec5]131  fi
132
133  echo "$file"
134
[db26f60]135  # how many warnings to expect (or empty not to check)
[b97d134]136  warn=
[db26f60]137
138  # how many errors to expect (or empty not to check)
[b97d134]139  error=
[2b0cec5]140
[db26f60]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
[aaeb71f]146  # gpx : Convert to GPX with survexport and compare with <testcase_name>.gpx
[4fcdd51a]147  # json : Convert to JSON with survexport and compare with <testcase_name>.json
[aaeb71f]148  # kml : Convert to KML with survexport and compare with <testcase_name>.kml
[3ee5c47]149  # plt : Convert to PLT with survexport and compare with <testcase_name>.plt
[8c4cefb]150  # svg : Convert to SVG with survexport and compare with <testcase_name>.svg
[db26f60]151  pos=
152
[0d3c93b]153  case $file in
[2635234]154    backread.dat|clptest.dat|clptest.clp|depthguage.dat|flags.dat|karstcompat.dat)
[fdffa7d]155      pos=dump
156      warn=0
157      ;;
[2b0cec5]158    *.dat)
[838a7f4c]159      # .dat files can't start with a comment.  All the other .dat tests
160      # have the same settings.
[2b0cec5]161      pos=yes
162      warn=0
163      ;;
164    nonexistent_file*|ONELEG)
[3ebfd6a]165      # These testcase files don't exist (or for ONELEG exist with a different
166      # case).  They all have the same settings.
[2b0cec5]167      pos=fail
168      ;;
169    *)
[aaeb71f]170      survexportopts=
[2b0cec5]171      read header < "$realfile"
172      set dummy $header
[f9aaa2c]173      while shift && [ -n "$1" ] ; do
[2b0cec5]174        case $1 in
175          pos=*) pos=`expr "$1" : 'pos=\(.*\)'` ;;
176          warn=*) warn=`expr "$1" : 'warn=\(.*\)'` ;;
177          error=*) error=`expr "$1" : 'error=\(.*\)'` ;;
[aaeb71f]178          survexportopt=*)
179            survexportopts="$survexportopts "`expr "$1" : 'survexportopt=\(.*\)'`
180            ;;
[2b0cec5]181        esac
182      done
183      ;;
[cfa16ef]184  esac
[4a2bb00]185
[aba729d]186  basefile=$srcdir/$file
[2b0cec5]187  case $file in
188  *.*)
189    input="./$file"
[aba729d]190    basefile=`echo "$basefile"|sed 's/\.[^.]*$//'` ;;
[2b0cec5]191  *)
[aba729d]192    input="./$file.svx" ;;
[2b0cec5]193  esac
[aba729d]194  outfile=$basefile.out
[cccc545]195  outfile2=$basefile.altout
[aba729d]196  posfile=$basefile.pos
[2b0cec5]197  rm -f tmp.*
198  pwd=`pwd`
199  cd "$srcdir"
[fdffa7d]200  srcdir=. SOURCE_DATE_EPOCH=1 $CAVERN "$input" --output="$pwd/tmp" > "$pwd/tmp.out"
[2b0cec5]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
[837e8bb]219    w=`sed '$!d;s/^There were \([0-9]*\).*/\1/p;d' tmp.out`
220    if test x"${w:-0}" != x"$warn" ; then
[2b0cec5]221      test -n "$VERBOSE" && echo "Got $w warnings, expected $warn"
222      exit 1
223    fi
224  fi
225  if test -n "$error" ; then
[837e8bb]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
[2b0cec5]228      test -n "$VERBOSE" && echo "Got $e errors, expected $error"
229      exit 1
230    fi
231  fi
[f5012ca]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"
[2b0cec5]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
[67a2822]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
[2b0cec5]256    [ "$exitcode" = 0 ] || exit 1
257    ;;
[fdffa7d]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    ;;
[8c4cefb]279  dxf|gpx|json|kml|plt|svg)
[aaeb71f]280    # $pos gives us the file extension here.
281    expectedfile=$basefile.$pos
282    tmpfile=tmp.$pos
[2b0cec5]283    if test -n "$VERBOSE" ; then
[aaeb71f]284      $SURVEXPORT --defaults$survexportopts tmp.3d "$tmpfile"
[2b0cec5]285      exitcode=$?
[cfa16ef]286    else
[aaeb71f]287      $SURVEXPORT --defaults$survexportopts tmp.3d "$tmpfile" > /dev/null
[2b0cec5]288      exitcode=$?
[cfa16ef]289    fi
[2b0cec5]290    if [ -n "$VALGRIND" ] ; then
291      if [ $exitcode = "$vg_error" ] ; then
292        cat "$vg_log"
293        rm "$vg_log"
[62e7e3c]294        exit 1
295      fi
[2b0cec5]296      rm "$vg_log"
[cfa16ef]297    fi
[2b0cec5]298    [ "$exitcode" = 0 ] || exit 1
[aaeb71f]299
300    # Normalise exported file if required.
301    case $pos in
302      gpx)
[24f2d99]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
[aaeb71f]304        mv tmp.tmp "$tmpfile"
305        ;;
306    esac
307
[2b0cec5]308    if test -n "$VERBOSE" ; then
[aaeb71f]309      diff "$expectedfile" "$tmpfile" || exit 1
[2b0cec5]310    else
[aaeb71f]311      cmp -s "$expectedfile" "$tmpfile" || exit 1
312    fi
313    ;;
[2b0cec5]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
[cd971de]325
[aba729d]326  if test -f "$outfile" ; then
[cccc545]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).
[2b0cec5]336    else
[cccc545]337      test -z "$VERBOSE" || diff "$outfile" tmp.out
338      exit 1
[cd971de]339    fi
[cfa16ef]340  fi
[2b0cec5]341  rm -f tmp.*
[4a2bb00]342done
[cfcfd28]343test -n "$VERBOSE" && echo "Test passed"
[fbc3a20]344exit 0
Note: See TracBrowser for help on using the repository browser.