A test no longer fails.
[sbcl.git] / tests / script.test.sh
blobe837136956d8104a5a669c12314956d98b3d25ff
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 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*)
48 (sb-ext:exit :code 3)
49 EOF
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)
58 EOF
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)
67 EOF
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)))
75 EOF
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` ]
79 then
80 echo "--script outputs wrong"
81 exit $EXIT_LOSE
84 cat > $tmpscript <<EOF
85 (loop (write-line "foo"))
86 EOF
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` ]
90 then
91 echo "--script unexpected error output"
92 exit $EXIT_LOSE
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` ]
97 then
98 echo "--script unexpected error output"
99 exit $EXIT_LOSE
102 # --script
103 cat > $tmpscript <<EOF
104 (print :script-ok)
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"
110 exit $EXIT_LOSE
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
120 chmod +x $tmpfasl
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`" ]
124 then
125 echo "--script from fasl unexpected output"
126 exit $EXIT_LOSE
129 rm -f $tmpscript $tmpout $tmperr $tmpfasl
131 exit $EXIT_TEST_WIN