File: script.test.sh

package info (click to toggle)
sbcl 2%3A2.6.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 52,008 kB
  • sloc: lisp: 535,135; ansic: 42,629; sh: 5,737; asm: 2,406; pascal: 717; makefile: 432; python: 56; cpp: 27
file content (131 lines) | stat: -rw-r--r-- 4,400 bytes parent folder | download | duplicates (3)
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
#!/bin/sh

# tests related to --script

# This software is part of the SBCL system. See the README file for
# more information.
#
# While most of SBCL is derived from the CMU CL system, the test
# files (like this one) were written from scratch after the fork
# from CMU CL.
#
# This software is in the public domain and is provided with
# absolutely no warranty. See the COPYING and CREDITS files for
# more information.

. ./subr.sh

use_test_subdirectory

tmpscript=$TEST_FILESTEM.lisp-script
tmpfasl=$TEST_FILESTEM.lisp-fasl
tmpout=$TEST_FILESTEM.lisp-out
tmperr=$TEST_FILESTEM.lisp-err

echo '(exit :code 7)' > $tmpscript
run_sbcl --script $tmpscript
check_status_maybe_lose "--script exit status from EXIT" $? 7 "(status good)"

echo '(when (and (null *load-verbose*) (null *compile-verbose*)) (exit :code 7))' > $tmpscript
run_sbcl --script $tmpscript
check_status_maybe_lose "--script verbosity" $? 7 "(silent)"

echo '(error "oops")' > $tmpscript
run_sbcl --script $tmpscript 1> $tmpout 2> $tmperr
check_status_maybe_lose "--script exit status from ERROR" $? 1 "(error implies 1)"
grep Backtrace $tmpout > /dev/null
check_status_maybe_lose "--script backtrace not to stdout" $? 1 "(ok)"
grep Backtrace $tmperr > /dev/null
check_status_maybe_lose "--script backtrace to stderr" $? 0 "(ok)"

echo 'nil'> $tmpscript
run_sbcl --script $tmpscript
check_status_maybe_lose "--script exit status from normal exit" $? 0 "(everything ok)"

cat > $tmpscript <<EOF
(setf *standard-output* (make-broadcast-stream))
(close *standard-output*)
(sb-ext:exit :code 3)
EOF
run_sbcl --script $tmpscript >/dev/null
check_status_maybe_lose "--script exit status from QUIT when standard-output closed" $? 3 "(as given)"
run_sbcl --load $tmpscript >/dev/null
check_status_maybe_lose "--load exit status from QUIT when standard-output closed" $? 3 "(as given)"

cat > $tmpscript <<EOF
(close *standard-output*)
(sb-ext:quit :unix-status 3)
EOF
run_sbcl --script $tmpscript >/dev/null
check_status_maybe_lose "--script exit status from QUIT when original standard-output closed" $? 3 "(as given)"
run_sbcl --load $tmpscript >/dev/null
check_status_maybe_lose "--load exit status from QUIT when original standard-output closed" $? 3 "(as given)"

cat > $tmpscript <<EOF
(close sb-sys:*stdout*)
(sb-ext:quit :unix-status 3)
EOF
run_sbcl --script $tmpscript >/dev/null
check_status_maybe_lose "--script exit status from EXIT when stdout closed" $? 3 "(as given)"
run_sbcl --load $tmpscript >/dev/null
check_status_maybe_lose "--load exit status from EXIT when stdout closed" $? 3 "(as given)"

cat > $tmpscript <<EOF
(loop (write-line (read-line)))
EOF
echo ONE | run_sbcl --script $tmpscript 1> $tmpout 2> $tmperr
check_status_maybe_lose "--script exit status when stdin closed" $? 0 "(as given)"
if [ -s $tmperr ] || [ "ONE" != `cat $tmpout` ]
then
    echo "--script outputs wrong"
    exit $EXIT_LOSE
fi

cat > $tmpscript <<EOF
(loop (write-line "foo"))
EOF
run_sbcl --script $tmpscript 2> $tmperr | head -n1 > $tmpout
check_status_maybe_lose "--script exit status when stdout closed" $? 0 "(as given)"
if [ -s $tmperr ] || [ "foo" != `cat $tmpout` ]
then
    echo "--script unexpected error output"
    exit $EXIT_LOSE
fi
echo '(write-line "Ok!")' | run_sbcl --script 1>$tmpout 2>$tmperr
check_status_maybe_lose "--script exit status from stdin" $? 0 "(ok)"
if [ -s $tmperr ] || [ "Ok!" != `cat $tmpout` ]
then
    echo "--script unexpected error output"
    exit $EXIT_LOSE
fi

# --script
cat > $tmpscript <<EOF
(print :script-ok)
EOF
run_sbcl --script $tmpscript --eval foo \
  < /dev/null > $tmpout
if [ "`grep -c :SCRIPT-OK $tmpout`" != 1 ] ; then
   echo "failed --script test using PRINT"
   exit $EXIT_LOSE
fi

# automatically executing fasls
#
# this test is fragile, with its SBCL_HOME hack to get the shebang
# line in the fasl to find the right core, and also is unlikely to
# work with that mechanism on Windows.
echo '(format t "Hello, Fasl~%")' > $tmpscript
run_sbcl --eval "(compile-file \"$tmpscript\" :output-file \"$tmpfasl\")"  </dev/null >/dev/null
chmod +x $tmpfasl
SBCL_HOME=`dirname $SBCL_CORE` ./$tmpfasl >$tmpout 2>$tmperr
check_status_maybe_lose "--script exit status from fasl" $? 0 "(ok)"
if [ -s $tmperr ] || [ "Hello, Fasl" != "`cat $tmpout`" ]
then
    echo "--script from fasl unexpected output"
    exit $EXIT_LOSE
fi

rm -f $tmpscript $tmpout $tmperr $tmpfasl

exit $EXIT_TEST_WIN