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 tmpout=$TEST_FILESTEM.lisp-out
22 tmperr=$TEST_FILESTEM.lisp-err
24 echo '(exit :code 7)' > $tmpscript
25 run_sbcl --script $tmpscript
26 check_status_maybe_lose "--script exit status from EXIT" $? 7 "(status good)"
28 echo '(error "oops")' > $tmpscript
29 run_sbcl --script $tmpscript 1> $tmpout 2> $tmperr
30 check_status_maybe_lose "--script exit status from ERROR" $? 1 "(error implies 1)"
31 grep BACKTRACE $tmpout > /dev/null
32 check_status_maybe_lose "--script backtrace not to stdout" $? 1 "(ok)"
33 grep BACKTRACE $tmperr > /dev/null
34 check_status_maybe_lose "--script backtrace to stderr" $? 0 "(ok)"
36 echo 'nil'> $tmpscript
37 run_sbcl --script $tmpscript
38 check_status_maybe_lose "--script exit status from normal exit" $? 0 "(everything ok)"
40 cat > $tmpscript <<EOF
41 (setf *standard-output* (make-broadcast-stream))
42 (close *standard-output*)
45 run_sbcl --script $tmpscript >/dev/null
46 check_status_maybe_lose "--script exit status from QUIT when standard-output closed" $? 3 "(as given)"
47 run_sbcl --load $tmpscript >/dev/null
48 check_status_maybe_lose "--load exit status from QUIT when standard-output closed" $? 3 "(as given)"
50 cat > $tmpscript <<EOF
51 (close *standard-output*)
52 (sb-ext:quit :unix-status 3)
54 run_sbcl --script $tmpscript >/dev/null
55 check_status_maybe_lose "--script exit status from QUIT when original standard-output closed" $? 3 "(as given)"
56 run_sbcl --load $tmpscript >/dev/null
57 check_status_maybe_lose "--load exit status from QUIT when original standard-output closed" $? 3 "(as given)"
59 cat > $tmpscript <<EOF
60 (close sb-sys:*stdout*)
61 (sb-ext:quit :unix-status 3)
63 run_sbcl --script $tmpscript >/dev/null
64 check_status_maybe_lose "--script exit status from EXIT when stdout closed" $? 3 "(as given)"
65 run_sbcl --load $tmpscript >/dev/null
66 check_status_maybe_lose "--load exit status from EXIT when stdout closed" $? 3 "(as given)"
68 cat > $tmpscript <<EOF
69 (loop (write-line (read-line)))
71 echo ONE | run_sbcl --script $tmpscript 1> $tmpout 2> $tmperr
72 check_status_maybe_lose "--script exit status when stdin closed" $? 0 "(as given)"
73 if [ -s $tmperr ] || [ "ONE" != `cat $tmpout` ]
75 echo "--script outputs wrong"
79 cat > $tmpscript <<EOF
80 (loop (write-line "foo"))
82 run_sbcl --script $tmpscript 2> $tmperr | head -n1 > $tmpout
83 check_status_maybe_lose "--script exit status when stdout closed" $? 0 "(as given)"
84 if [ -s $tmperr ] || [ "foo" != `cat $tmpout` ]
86 echo "--script unexpected error output"
89 echo '(write-line "Ok!")' | run_sbcl --script 1>$tmpout 2>$tmperr
90 check_status_maybe_lose "--script exit status script from stdin" $? 0 "(ok)"
91 if [ -s $tmperr ] || [ "Ok!" != `cat $tmpout` ]
93 echo "--script unexpected error output"
98 cat > $tmpscript <<EOF
101 run_sbcl --script $tmpscript --eval foo \
102 < /dev/null > $tmpout
103 if [ "`grep -c :SCRIPT-OK $tmpout`" != 1 ] ; then
104 echo "failed --script test using PRINT"
108 rm -f $tmpscript $tmpout $tmperr