redesign exiting SBCL
[sbcl.git] / tests / script.test.sh
blob33483bad68b7cd0f2146308afcc5b33c70da1222
1 #!/bin/sh
3 # tests related to --script
5 # This software is part of the SBCL system. See the README file for
6 # more information.
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
10 # from CMU CL.
12 # This software is in the public domain and is provided with
13 # absolutely no warranty. See the COPYING and CREDITS files for
14 # more information.
16 . ./subr.sh
18 use_test_subdirectory
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*)
43 (sb-ext:exit :code 3)
44 EOF
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)
53 EOF
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)
62 EOF
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)))
70 EOF
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` ]
74 then
75 echo "--script outputs wrong"
76 exit $EXIT_LOSE
79 cat > $tmpscript <<EOF
80 (loop (write-line "foo"))
81 EOF
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` ]
85 then
86 echo "--script unexpected error output"
87 exit $EXIT_LOSE
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` ]
92 then
93 echo "--script unexpected error output"
94 exit $EXIT_LOSE
97 # --script
98 cat > $tmpscript <<EOF
99 (print :script-ok)
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"
105 exit $EXIT_LOSE
108 rm -f $tmpscript $tmpout $tmperr
110 exit $EXIT_TEST_WIN