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