Fix make-array transforms.
[sbcl.git] / tests / script.test.sh
1 #!/bin/sh
2
3 # tests related to --script
4
5 # This software is part of the SBCL system. See the README file for
6 # more information.
7 #
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.
11 #
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.
15
16 . ./subr.sh
17
18 use_test_subdirectory
19
20 tmpscript=$TEST_FILESTEM.lisp-script
21 tmpfasl=$TEST_FILESTEM.lisp-fasl
22 tmpout=$TEST_FILESTEM.lisp-out
23 tmperr=$TEST_FILESTEM.lisp-err
24
25 echo '(exit :code 7)' > $tmpscript
26 run_sbcl --script $tmpscript
27 check_status_maybe_lose "--script exit status from EXIT" $? 7 "(status good)"
28
29 echo '(error "oops")' > $tmpscript
30 run_sbcl --script $tmpscript 1> $tmpout 2> $tmperr
31 check_status_maybe_lose "--script exit status from ERROR" $? 1 "(error implies 1)"
32 grep Backtrace $tmpout > /dev/null
33 check_status_maybe_lose "--script backtrace not to stdout" $? 1 "(ok)"
34 grep Backtrace $tmperr > /dev/null
35 check_status_maybe_lose "--script backtrace to stderr" $? 0 "(ok)"
36
37 echo 'nil'> $tmpscript
38 run_sbcl --script $tmpscript
39 check_status_maybe_lose "--script exit status from normal exit" $? 0 "(everything ok)"
40
41 cat > $tmpscript <<EOF
42 (setf *standard-output* (make-broadcast-stream))
43 (close *standard-output*)
44 (sb-ext:exit :code 3)
45 EOF
46 run_sbcl --script $tmpscript >/dev/null
47 check_status_maybe_lose "--script exit status from QUIT when standard-output closed" $? 3 "(as given)"
48 run_sbcl --load $tmpscript >/dev/null
49 check_status_maybe_lose "--load exit status from QUIT when standard-output closed" $? 3 "(as given)"
50
51 cat > $tmpscript <<EOF
52 (close *standard-output*)
53 (sb-ext:quit :unix-status 3)
54 EOF
55 run_sbcl --script $tmpscript >/dev/null
56 check_status_maybe_lose "--script exit status from QUIT when original standard-output closed" $? 3 "(as given)"
57 run_sbcl --load $tmpscript >/dev/null
58 check_status_maybe_lose "--load exit status from QUIT when original standard-output closed" $? 3 "(as given)"
59
60 cat > $tmpscript <<EOF
61 (close sb-sys:*stdout*)
62 (sb-ext:quit :unix-status 3)
63 EOF
64 run_sbcl --script $tmpscript >/dev/null
65 check_status_maybe_lose "--script exit status from EXIT when stdout closed" $? 3 "(as given)"
66 run_sbcl --load $tmpscript >/dev/null
67 check_status_maybe_lose "--load exit status from EXIT when stdout closed" $? 3 "(as given)"
68
69 cat > $tmpscript <<EOF
70 (loop (write-line (read-line)))
71 EOF
72 echo ONE | run_sbcl --script $tmpscript 1> $tmpout 2> $tmperr
73 check_status_maybe_lose "--script exit status when stdin closed" $? 0 "(as given)"
74 if [ -s $tmperr ] || [ "ONE" != `cat $tmpout` ]
75 then
76     echo "--script outputs wrong"
77     exit $EXIT_LOSE
78 fi
79
80 cat > $tmpscript <<EOF
81 (loop (write-line "foo"))
82 EOF
83 run_sbcl --script $tmpscript 2> $tmperr | head -n1 > $tmpout
84 check_status_maybe_lose "--script exit status when stdout closed" $? 0 "(as given)"
85 if [ -s $tmperr ] || [ "foo" != `cat $tmpout` ]
86 then
87     echo "--script unexpected error output"
88     exit $EXIT_LOSE
89 fi
90 echo '(write-line "Ok!")' | run_sbcl --script 1>$tmpout 2>$tmperr
91 check_status_maybe_lose "--script exit status from stdin" $? 0 "(ok)"
92 if [ -s $tmperr ] || [ "Ok!" != `cat $tmpout` ]
93 then
94     echo "--script unexpected error output"
95     exit $EXIT_LOSE
96 fi
97
98 # --script
99 cat > $tmpscript <<EOF
100 (print :script-ok)
101 EOF
102 run_sbcl --script $tmpscript --eval foo \
103   < /dev/null > $tmpout
104 if [ "`grep -c :SCRIPT-OK $tmpout`" != 1 ] ; then
105    echo "failed --script test using PRINT"
106    exit $EXIT_LOSE
107 fi
108
109 # automatically executing fasls
110 #
111 # this test is fragile, with its SBCL_HOME hack to get the shebang
112 # line in the fasl to find the right core, and also is unlikely to
113 # work with that mechanism on Windows.
114 echo '(format t "Hello, Fasl~%")' > $tmpscript
115 run_sbcl --eval "(compile-file \"$tmpscript\" :output-file \"$tmpfasl\")"  </dev/null >/dev/null
116 chmod +x $tmpfasl
117 SBCL_HOME=`dirname $SBCL_CORE` ./$tmpfasl >$tmpout 2>$tmperr
118 check_status_maybe_lose "--script exit status from fasl" $? 0 "(ok)"
119 if [ -s $tmperr ] || [ "Hello, Fasl" != "`cat $tmpout`" ]
120 then
121     echo "--script from fasl unexpected output"
122     exit $EXIT_LOSE
123 fi
124
125 rm -f $tmpscript $tmpout $tmperr $tmpfasl
126
127 exit $EXIT_TEST_WIN