Skip a known failure on openbsd.
[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 tmpout=$TEST_FILESTEM.lisp-out
22 tmperr=$TEST_FILESTEM.lisp-err
23
24 echo '(quit :unix-status 7)' > $tmpscript
25 run_sbcl --script $tmpscript
26 check_status_maybe_lose "--script exit status from QUIT" $? 7 "(quit status good)"
27
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)"
35
36 echo 'nil'> $tmpscript
37 run_sbcl --script $tmpscript
38 check_status_maybe_lose "--script exit status from normal exit" $? 0 "(everything ok)"
39
40 cat > $tmpscript <<EOF
41 #+(or darwin netbsd openbsd)
42 (progn
43   (format t "silently skipping known failure in script.test.sh~%")
44   (sb-ext:quit :unix-status 3))
45 (setf *standard-output* (open "/dev/stdout"))
46 (close *standard-output*)
47 (sb-ext:quit :unix-status 3)
48 EOF
49 run_sbcl --script $tmpscript >/dev/null
50 check_status_maybe_lose "--script exit status from QUIT when stdout closed" $? 3 "(as given)"
51 run_sbcl --load $tmpscript >/dev/null
52 check_status_maybe_lose "--load exit status from QUIT when stdout closed" $? 3 "(as given)"
53
54 cat > $tmpscript <<EOF
55 (loop (write-line (read-line)))
56 EOF
57 echo ONE | run_sbcl --script $tmpscript 1> $tmpout 2> $tmperr
58 check_status_maybe_lose "--script exit status when stdin closed" $? 0 "(as given)"
59 if [ -s $tmperr ] || [ "ONE" != `cat $tmpout` ]
60 then
61     echo "--script outputs wrong"
62     exit $EXIT_LOSE
63 fi
64
65 cat > $tmpscript <<EOF
66 (loop (write-line "foo"))
67 EOF
68 run_sbcl --script $tmpscript 2> $tmperr | head -n1 > $tmpout
69 check_status_maybe_lose "--script exit status when stdout closed" $? 0 "(as given)"
70 if [ -s $tmperr ] || [ "foo" != `cat $tmpout` ]
71 then
72     echo "--script unexpected error output"
73     exit $EXIT_LOSE
74 fi
75 echo '(write-line "Ok!")' | run_sbcl --script 1>$tmpout 2>$tmperr
76 check_status_maybe_lose "--script exit status script from stdin" $? 0 "(ok)"
77 if [ -s $tmperr ] || [ "Ok!" != `cat $tmpout` ]
78 then
79     echo "--script unexpected error output"
80     exit $EXIT_LOSE
81 fi
82
83 # --script
84 cat > $tmpscript <<EOF
85 (print :script-ok)
86 EOF
87 run_sbcl --script $tmpscript --eval foo \
88   < /dev/null > $tmpout
89 if [ "`grep -c :SCRIPT-OK $tmpout`" != 1 ] ; then
90    echo "failed --script test using PRINT"
91    exit $EXIT_LOSE
92 fi
93
94 rm -f $tmpscript $tmpout $tmperr
95
96 exit $EXIT_TEST_WIN