test.sh 2.47 KB
Newer Older
1
#!/bin/bash
Luke Gorrie's avatar
Luke Gorrie committed
2

Helmut Eller's avatar
Helmut Eller committed
3
# Run the SLIME test suite inside screen, saving the results to a file.
Luke Gorrie's avatar
Luke Gorrie committed
4

Helmut Eller's avatar
Helmut Eller committed
5

Luke Gorrie's avatar
Luke Gorrie committed
6 7 8 9 10 11 12
# This script's exit status is the number of tests failed. If no tests
# fail then no output is printed. If at least one test fails then a
# one-line summary is printed.

# If something unexpected fails, you might get an exit code like 127
# or 255 instead. Sorry.

13 14 15
# This code has been placed in the Public Domain.  All warranties
# are disclaimed.

Helmut Eller's avatar
Helmut Eller committed
16
function usage () {
17
    cat <<EOF
18
Usage: $name [-bsRTS] [-n <name>] <emacs> <lisp>"
Helmut Eller's avatar
Helmut Eller committed
19
  -b  use batch mode
20
  -s  use screen to hide emacs
Helmut Eller's avatar
Helmut Eller committed
21
  -R  don't show results file
22
  -T  no temp directory (use slime in current directory)
23 24
  -S  don't execute tests in random order (use default ordering)
  -n <name>  run only the test with name <name>
25
EOF
Luke Gorrie's avatar
Luke Gorrie committed
26
    exit 1
Helmut Eller's avatar
Helmut Eller committed
27 28 29
}

name=$0
Helmut Eller's avatar
Helmut Eller committed
30
batch_mode="" # command line arg for emacs
31
dump_results=true
32
use_temp_dir=true
33 34
test_name=nil
randomize=t
Helmut Eller's avatar
Helmut Eller committed
35

36
while getopts bsRTSn: opt; do
Helmut Eller's avatar
Helmut Eller committed
37
    case $opt in
Helmut Eller's avatar
Helmut Eller committed
38
	b) batch_mode="-batch";;
39
	s) use_screen=true;;
40 41
	n) test_name="'$OPTARG";;
	S) randomize=nil;;
Helmut Eller's avatar
Helmut Eller committed
42
	R) dump_results=false;;
43
	T) use_temp_dir=false;;
Helmut Eller's avatar
Helmut Eller committed
44 45 46
	*) usage;;
    esac
done
Luke Gorrie's avatar
Luke Gorrie committed
47

Helmut Eller's avatar
Helmut Eller committed
48 49 50 51
shift $((OPTIND - 1))
[ $# = 2 ] || usage

emacs=$1; lisp=$2;
Luke Gorrie's avatar
Luke Gorrie committed
52 53 54 55

# Move the code into a directory in /tmp, so that we can compile it
# for the current lisp.

Helmut Eller's avatar
Helmut Eller committed
56
slimedir=$(dirname $name)
57 58 59 60 61 62 63 64
tmpdir=/tmp/slime-test.$$
if [ $use_temp_dir == true ] ; then
    testdir=$tmpdir
else
    testdir=$(pwd)
fi
results=$tmpdir/results
statusfile=$tmpdir/status
Helmut Eller's avatar
Helmut Eller committed
65

66
test -d $tmpdir && rm -r $tmpdir
Helmut Eller's avatar
Helmut Eller committed
67

68
trap "rm -r $tmpdir" EXIT	# remove temporary directory on exit
Luke Gorrie's avatar
Luke Gorrie committed
69

70 71
mkdir $tmpdir
if [ $use_temp_dir == true ] ; then 
72 73
    cp -r $slimedir/*.{el,lisp} ChangeLog $tmpdir 
    # cp -r $slimedir/contrib $tmpdir 
74
fi
Luke Gorrie's avatar
Luke Gorrie committed
75

76
cmd=($emacs -nw -q -no-site-file $batch_mode --no-site-file
77 78 79 80
       --eval "(setq debug-on-quit t)"
       --eval "(add-to-list 'load-path \"$testdir\")"
       --eval "(require 'slime)"
       --eval "(setq inferior-lisp-program \"$lisp\")"
81
       --eval "(slime-batch-test \"$results\" $test_name $randomize)")
Helmut Eller's avatar
Helmut Eller committed
82

83
if [ "$use_screen" = "" ]; then
84 85 86 87 88 89 90
    "${cmd[@]}"
    echo $? > $statusfile
else 
    session=slime-screen.$$
    screen -S $session -m -D \
	bash -c "\"\$@\"; echo \$? > $statusfile" "" "${cmd[@]}" &
    screenpid=$!
91
    trap "screen -S $session -X quit" SIGINT SIGQUIT
92 93
    wait $screenpid
fi
Helmut Eller's avatar
Helmut Eller committed
94 95

if [ -f "$statusfile" ]; then
96 97 98
    [ "$dump_results" = true ] && cat $results
    status=$(cat $statusfile)
    echo $status "test(s) failed."
99 100 101
else
    # Tests crashed
    echo crashed
102
    status=255
Luke Gorrie's avatar
Luke Gorrie committed
103 104 105
fi

exit $status