1#! /bin/sh 2# 3# nana-gammon - a small automated testing program. 4# 5# Copyright (C) 1999, Phil Maker, <pjm@gnu.org>, Quoll Systems. 6# 7# This program is free software; you can redistribute it and/or modify 8# it under the terms of the GNU General Public License as published by 9# the Free Software Foundation; either version 2 of the License, or 10# (at your option) any later version. 11# 12# This program is distributed in the hope that it will be useful, 13# but WITHOUT ANY WARRANTY; without even the implied warranty of 14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15# GNU General Public License for more details. 16# 17# You should have received a copy of the GNU General Public License 18# along with this program; if not, write to the Free Software 19# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20# 21# $Id: gammon.in,v 1.1.1.1 1999/09/12 03:26:50 pjm Exp $ 22# 23 24## ./configure sets up some variables for use in the test scripts 25 26SHELL="/bin/bash" 27CFLAGS="-g -O2" 28CPPFLAGS="" 29CXXFLAGS="-g -O2" 30FFLAGS="@FFLAGS@" 31DEFS="-DPACKAGE_NAME=\"nana\" -DPACKAGE_TARNAME=\"nana\" -DPACKAGE_VERSION=\"3.0\" -DPACKAGE_STRING=\"nana\ 3.0\" -DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -DPACKAGE=\"nana\" -DVERSION=\"3.0\" -DHAVE_VSPRINTF=1 -DHAVE_VSNPRINTF=1 -DHAVE_GETTIMEOFDAY=1" 32LDFLAGS="" 33LIBS="" 34exec_prefix="${prefix}" 35prefix="/usr/local" 36program_transform_name="s,x,x," 37bindir="${exec_prefix}/bin" 38sbindir="${exec_prefix}/sbin" 39libexecdir="${exec_prefix}/libexec" 40datadir="${prefix}/share" 41sysconfdir="${prefix}/etc" 42sharedstatedir="${prefix}/com" 43localstatedir="${prefix}/var" 44libdir="${exec_prefix}/lib" 45includedir="${prefix}/include" 46oldincludedir="/usr/include" 47infodir="${prefix}/share/info" 48mandir="${prefix}/share/man" 49host="x86_64-pc-linux-gnu" 50host_alias="" 51host_cpu="x86_64" 52host_vendor="pc" 53host_os="linux-gnu" 54target="x86_64-pc-linux-gnu" 55target_alias="" 56target_cpu="x86_64" 57target_vendor="pc" 58target_os="linux-gnu" 59build="x86_64-pc-linux-gnu" 60build_alias="" 61build_cpu="x86_64" 62build_vendor="pc" 63build_os="linux-gnu" 64INSTALL_PROGRAM="${INSTALL}" 65INSTALL_SCRIPT="${INSTALL}" 66INSTALL_DATA="${INSTALL} -m 644" 67PACKAGE="nana" 68VERSION="3.0" 69ACLOCAL="aclocal-1.14" 70AUTOCONF="autoconf" 71AUTOMAKE="automake-1.14" 72AUTOHEADER="autoheader" 73MAKEINFO="makeinfo" 74TAR="tar" 75AMTARFLAGS="@AMTARFLAGS@" 76SET_MAKE="" 77CC="gcc" 78AWK="gawk" 79F77="@F77@" 80CPP="gcc -E" 81CXX="g++" 82CXXCPP="g++ -E" 83RANLIB="ranlib" 84 85src_dir=. 86top_srcdir=.. 87export src_dir 88export top_srcdir 89 90export SHELL 91export CFLAGS 92export CPPFLAGS 93export CXXFLAGS 94export FFLAGS 95export DEFS 96export LDFLAGS 97export LIBS 98export exec_prefix 99export prefix 100export program_transform_name 101export bindir 102export sbindir 103export libexecdir 104export datadir 105export sysconfdir 106export sharedstatedir 107export localstatedir 108export libdir 109export includedir 110export oldincludedir 111export infodir 112export mandir 113export host 114export host_alias 115export host_cpu 116export host_vendor 117export host_os 118export target 119export target_alias 120export target_cpu 121export target_vendor 122export target_os 123export build 124export build_alias 125export build_cpu 126export build_vendor 127export build_os 128export INSTALL_PROGRAM 129export INSTALL_SCRIPT 130export INSTALL_DATA 131export PACKAGE 132export VERSION 133export ACLOCAL 134export AUTOCONF 135export AUTOMAKE 136export AUTOHEADER 137export MAKEINFO 138export TAR 139export AMTARFLAGS 140export SET_MAKE 141export CC 142export AWK 143export F77 144export CPP 145export CXX 146export CXXCPP 147export RANLIB 148 149## initialise files for this set of tests 150 151rm -f [0-9]* 152rm -f *.var 153cat /dev/null >passed-tests 154cat /dev/null >failed-run 155cat /dev/null >failed-compile 156 157## clean - used to remove all the test result files 158clean () { 159 rm -f [0-9]* 160 rm -f *.var 161 rm -f passed-tests 162 rm -f failed-run 163 rm -f failed-compile 164 exit 0 165} 166 167## option setting commands 168 169# 170# only run these particular tests 171# 172# usage: only [testnumber ...] 173# example: only 1 3 19 20 174# causes only tests 1 3 19 20 to be run 175# 176runonly=false 177only () { 178 runonly=true 179 rm -f only-tests 180 for t in $* 181 do 182 echo $t >> only-tests 183 done 184} 185 186# 187# show or hide messages about each of the following tests. 188# hide with no arguments hides everything whilst 189# show with no arguments shows everything. 190# 191# usage: show [option ...] 192# hide [option ...] 193# 194# example: 195# hide 196# 197showsource=true # show the source code for this test 198showinput=true # show the input for this test 199showoutput=true # show the output from the program 200showexpect=true # show the expected (correct) output 201showerror=true # show the error output 202showexit=true # show the exit code from the program 203showblank=true # put a blank line between each test 204showtitle=true # show the title for each test 205showresult=true # show the result (pass/fail) for each test 206showcompile=true # show the compile command used for this test 207 208show () { 209 case $# 210 in 211 0) 212 for f in source input output expect \ 213 error exit tests blank title result compile 214 do 215 eval show${f}=true 216 done 217 ;; 218 *) 219 for f in $* 220 do 221 eval show${f}=true 222 done 223 ;; 224 esac 225} 226 227hide () { 228 case $# 229 in 230 0) 231 for f in source input output expect \ 232 error exit tests blank title result compile 233 do 234 eval show${f}=false 235 done 236 ;; 237 *) 238 for f in $* 239 do 240 eval show${f}=false 241 done 242 ;; 243 esac 244} 245 246# if keepclean then tests that pass are removed as we go, otherwise 247# we keep all the source code etc around. 248keepclean=true 249 250keepall () { 251 keepclean=false 252} 253 254keepnone () { 255 keepclean=true 256} 257 258## 259## Test setup functions - each of the following functions is used to 260## set up part of each test. In particular for the function expect 261## a file called expect.var which is then used as the expected 262## output from the program. This file is then copied to 1-expect, 263## 2-expect, etc as the testing progresses. 264## 265## Note that the source function also runs the test. 266## 267## Usage: 268## 269## source "exit(0);" 270## 271## or 272## 273## source <<EOF 274## line1 275## line2 276## ... 277## EOF 278## 279 280# source code for this test + run the test. 281source () { 282 case $# 283 in 284 0) cat >source.var ;; 285 *) echo "$*" >source.var ;; 286 esac 287 runtest 288} 289echo >source.var 290 291# the header for this and subsequent tests 292# this is the code that goes at the top of each test program 293header () { 294 case $# 295 in 296 0) cat >header.var ;; 297 *) echo "$*" >header.var ;; 298 esac 299} 300echo >header.var 301 302# the footer for this and subsequent tests 303# this code goes at the bottom of each test program 304footer () { 305 case $# 306 in 307 0) cat >footer.var ;; 308 *) echo "$*" >footer.var ;; 309 esac 310} 311echo >footer.var 312 313# the compile script for this and subsequent tests 314# it is passed the test number as argument 1 and should set things 315# up for the run script. 316compile () { 317 case $# 318 in 319 0) cat >compile.var ;; 320 *) echo "$*" >compile.var ;; 321 esac 322} 323echo >compile.var 324 325# the run script that executes the test program 326run () { 327 case $# 328 in 329 0) cat >run.var ;; 330 *) echo "$*" >run.var ;; 331 esac 332} 333echo "./\$1.out" >run.var 334 335# the input for this and subsequent tests 336input () { 337 case $# 338 in 339 0) cat >input.var ;; 340 *) echo "$*" >input.var ;; 341 esac 342} 343echo >input.var 344 345# the expected (correct) output from this program 346expect () { 347 case $# 348 in 349 0) cat >expect.var ;; 350 *) echo "$*" >expect.var ;; 351 esac 352} 353echo >expect.var 354 355# the program that checks the output for correctness 356check () { 357 case $# 358 in 359 0) cat >check.var ;; 360 *) echo "$*" >check.var ;; 361 esac 362} 363echo "exec cmp -s \$1-output \$1-expect" >check.var 364 365# the topic for this and subsequent tests (e.g. topic Q.h) 366topic () { 367 case $# 368 in 369 0) cat >topic.var ;; 370 *) echo "$*" >topic.var ;; 371 esac 372} 373echo >topic.var 374 375# the title for this particular test 376title () { 377 case $# 378 in 379 0) cat >title.var ;; 380 *) echo "$*" >title.var ;; 381 esac 382} 383echo >title.var 384 385# 386# manysource generates one source call per line of its arguments 387# and is used to generate a large number of tests from a code system. 388# 389# example: 390# 391# manysource "Q.c" <<EOF 392# test 1 393# test 2 394# test 3 395# EOF 396# 397manysource () { 398 case $# 399 in 400 0) ;; 401 *) topic $* ;; 402 esac 403 404 while read line 405 do 406 title $line 407 source $line 408 done 409} 410 411# 412# runtest - used to run an individual test which will already be 413# setup by the previous commands such as expect, etc. 414# This is called automatically by the source command and should 415# NOT normally be called by the user. 416# 417 418n=0 419passes=0 420runtime_failures=0 421compile_failures=0 422 423runtest () { 424 # increase the test number 425 n=`expr $n + 1` 426 427 # runonly is used to only run particular tests based on number. 428 if $runonly 429 then 430 if grep -q ^$n\$ only-tests 431 then 432 true 433 else 434 return 435 fi 436 else 437 true 438 fi 439 440 # generate the files for this particular test 441 for f in source header footer compile run input expect check topic title 442 do 443 cp $f.var $n-$f 444 done 445 446 # print the log message 447 $showtitle && echo "$n. `cat $n-topic` `cat $n-title`" 448 449 # display the source code if appropriate 450 $showsource && sed -e 's/^/ source: /' $n-source 451 452 # compile the program (this may be a nop) 453 sh -x $n-compile $n >$n-compile.out 2>$n-compile.err 454 $showcompile && sed -e 's/^+ / compile: /' $n-compile.err 455 456 case $? 457 in 458 0) 459 ;; 460 *) 461 $showresult && echo " * compilation failed" 462 $showblank && echo 463 echo "$n" >> failed-compile 464 compile_failures=`expr $compile_failures + 1` 465 return 466 ;; 467 esac 468 469 # run the program 470 sh $n-run $n <$n-input >$n-output 2>$n-error 471 echo $? >$n-exit 472 473 # print the details for this test 474 $showinput && sed -e 's/^/ input: /' $n-input 475 $showoutput && sed -e 's/^/ output: /' $n-output 476 $showexpect && sed -e 's/^/ expect: /' $n-expect 477 $showerror && sed -e 's/^/ error: /' $n-error 478 $showexit && sed -e 's/^/ exit: /' $n-exit 479 480 # check the output 481 sh $n-check $n 482 case $? 483 in 484 0) 485 $showresult && echo " * passed" 486 echo "$n" >> passed-tests 487 passes=`expr $passes + 1` 488 # keepclean causes us to remove successful test files 489 $keepclean && rm -f $n-* $n.out 490 ;; 491 *) 492 $showresult && echo " * failed" 493 echo "$n" >> failed-run 494 runtime_failures=`expr $runtime_failures + 1` 495 ;; 496 esac 497 498 499 # separate each test by a line 500 $showblank && echo 501} 502 503summary () { 504 TOTAL_TESTS=`expr $passes + $runtime_failures + $compile_failures` 505 echo "* Result Summary: $passes passes out of $TOTAL_TESTS tests" 506 507 echo 508 echo " $passes passes:" 509 fmt passed-tests | sed -e 's/^/ /' 510 echo 511 512 echo " $runtime_failures run time failures:" 513 fmt failed-run | sed -e 's/^/ /' 514 echo 515 516 echo " $compile_failures compile failures:" 517 fmt failed-compile | sed -e 's/^/ /' 518 echo 519 520 521} 522 523# 524# And finally run all the tests specified in the command line 525# 526# examples: 527# gammon 528# 529# gammon a.gam 530# 531# gammon "only 14 18 21" "show" all.gam 532# 533 534case $# 535in 536 0) 537 . $src_dir/all.gam 538 ;; 539 *) 540 for a in "$@" 541 do 542 case "$a" 543 in 544 *.gam) 545 echo "Running tests from $a" 546 . "$a" 547 ;; 548 *) 549 echo "Evaling from $a" 550 eval "$a" 551 ;; 552 esac 553 done 554esac 555 556summary 557 558if test -s failed-run || test -s failed-compile 559then 560 exit 1 561else 562 exit 0 563fi 564 565 566