3 # tests related to --script
5 # This software is part of the SBCL system. See the README file for
8 # While most of SBCL is derived from the CMU CL system, the test
9 # files (like this one) were written from scratch after the fork
12 # This software is in the public domain and is provided with
13 # absolutely no warranty. See the COPYING and CREDITS files for
20 tmpscript
=$TEST_FILESTEM.lisp-script
21 tmpfasl
=$TEST_FILESTEM.lisp-fasl
22 tmpout
=$TEST_FILESTEM.lisp-out
23 tmperr
=$TEST_FILESTEM.lisp-err
25 echo '(exit :code 7)' > $tmpscript
26 run_sbcl
--script $tmpscript
27 check_status_maybe_lose
"--script exit status from EXIT" $?
7 "(status good)"
29 echo '(when (and (null *load-verbose*) (null *compile-verbose*)) (exit :code 7))' > $tmpscript
30 run_sbcl
--script $tmpscript
31 check_status_maybe_lose
"--script verbosity" $?
7 "(silent)"
33 echo '(error "oops")' > $tmpscript
34 run_sbcl
--script $tmpscript 1> $tmpout 2> $tmperr
35 check_status_maybe_lose
"--script exit status from ERROR" $?
1 "(error implies 1)"
36 grep Backtrace
$tmpout > /dev
/null
37 check_status_maybe_lose
"--script backtrace not to stdout" $?
1 "(ok)"
38 grep Backtrace
$tmperr > /dev
/null
39 check_status_maybe_lose
"--script backtrace to stderr" $?
0 "(ok)"
41 echo 'nil'> $tmpscript
42 run_sbcl
--script $tmpscript
43 check_status_maybe_lose
"--script exit status from normal exit" $?
0 "(everything ok)"
45 cat > $tmpscript <<EOF
46 (setf *standard-output* (make-broadcast-stream))
47 (close *standard-output*)
50 run_sbcl
--script $tmpscript >/dev
/null
51 check_status_maybe_lose
"--script exit status from QUIT when standard-output closed" $?
3 "(as given)"
52 run_sbcl
--load $tmpscript >/dev
/null
53 check_status_maybe_lose
"--load exit status from QUIT when standard-output closed" $?
3 "(as given)"
55 cat > $tmpscript <<EOF
56 (close *standard-output*)
57 (sb-ext:quit :unix-status 3)
59 run_sbcl
--script $tmpscript >/dev
/null
60 check_status_maybe_lose
"--script exit status from QUIT when original standard-output closed" $?
3 "(as given)"
61 run_sbcl
--load $tmpscript >/dev
/null
62 check_status_maybe_lose
"--load exit status from QUIT when original standard-output closed" $?
3 "(as given)"
64 cat > $tmpscript <<EOF
65 (close sb-sys:*stdout*)
66 (sb-ext:quit :unix-status 3)
68 run_sbcl
--script $tmpscript >/dev
/null
69 check_status_maybe_lose
"--script exit status from EXIT when stdout closed" $?
3 "(as given)"
70 run_sbcl
--load $tmpscript >/dev
/null
71 check_status_maybe_lose
"--load exit status from EXIT when stdout closed" $?
3 "(as given)"
73 cat > $tmpscript <<EOF
74 (loop (write-line (read-line)))
76 echo ONE | run_sbcl
--script $tmpscript 1> $tmpout 2> $tmperr
77 check_status_maybe_lose
"--script exit status when stdin closed" $?
0 "(as given)"
78 if [ -s $tmperr ] ||
[ "ONE" != `cat $tmpout` ]
80 echo "--script outputs wrong"
84 cat > $tmpscript <<EOF
85 (loop (write-line "foo"))
87 run_sbcl
--script $tmpscript 2> $tmperr |
head -n1 > $tmpout
88 check_status_maybe_lose
"--script exit status when stdout closed" $?
0 "(as given)"
89 if [ -s $tmperr ] ||
[ "foo" != `cat $tmpout` ]
91 echo "--script unexpected error output"
94 echo '(write-line "Ok!")' | run_sbcl
--script 1>$tmpout 2>$tmperr
95 check_status_maybe_lose
"--script exit status from stdin" $?
0 "(ok)"
96 if [ -s $tmperr ] ||
[ "Ok!" != `cat $tmpout` ]
98 echo "--script unexpected error output"
103 cat > $tmpscript <<EOF
106 run_sbcl
--script $tmpscript --eval foo \
107 < /dev
/null
> $tmpout
108 if [ "`grep -c :SCRIPT-OK $tmpout`" != 1 ] ; then
109 echo "failed --script test using PRINT"
113 # automatically executing fasls
115 # this test is fragile, with its SBCL_HOME hack to get the shebang
116 # line in the fasl to find the right core, and also is unlikely to
117 # work with that mechanism on Windows.
118 echo '(format t "Hello, Fasl~%")' > $tmpscript
119 run_sbcl
--eval "(compile-file \"$tmpscript\" :output-file \"$tmpfasl\")" </dev
/null
>/dev
/null
121 SBCL_HOME
=`dirname $SBCL_CORE` .
/$tmpfasl >$tmpout 2>$tmperr
122 check_status_maybe_lose
"--script exit status from fasl" $?
0 "(ok)"
123 if [ -s $tmperr ] ||
[ "Hello, Fasl" != "`cat $tmpout`" ]
125 echo "--script from fasl unexpected output"
129 rm -f $tmpscript $tmpout $tmperr $tmpfasl