Prevent CLOS dispatch functions from pointing to arenas
[sbcl.git] / tests / run-program.test.sh
blobc926e5a05fdfea0cfd7d5134dab21e6abcc90220
1 #!/bin/sh
3 # tests related to SB-EXT:RUN-PROGRAM
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 # Make sure that there's at least something in the environment (for
19 # one of the tests below).
20 SOMETHING_IN_THE_ENVIRONMENT='yes there is'
21 export SOMETHING_IN_THE_ENVIRONMENT
22 PATH=/some/path/that/does/not/exist:${PATH}
23 export PATH
25 # Increase potential soft ulimit on file descriptors for file
26 # descriptor test case below.
27 test `ulimit -n` -ge 1050 || ulimit -S -n `ulimit -H -n`
29 # This should probably be broken up into separate pieces.
30 run_sbcl --eval "(defvar *exit-ok* $EXIT_LISP_WIN)" <<'EOF'
31 (defmacro our-run-program (name &rest rest)
32 #+unix `(run-program ,name ,@rest)
33 #-unix `(run-program ,(subseq name (1+ (position #\/ name :from-end t)))
34 ,@rest :search t))
36 ;; test that $PATH is searched
37 (assert (zerop (sb-ext:process-exit-code
38 (sb-ext:run-program "true" () :search t :wait t))))
39 (assert (not (zerop (sb-ext:process-exit-code
40 (sb-ext:run-program "false" () :search t :wait t)))))
41 (let ((string (with-output-to-string (stream)
42 (run-program "echo" '("foo" "bar")
43 :search t :output stream))))
44 (assert (string= string "foo bar
45 ")))
46 (format t ";;; Smoke tests: PASS~%")
48 ;; Unix environment strings are ordinarily passed with SBCL convention
49 ;; (instead of CMU CL alist-of-keywords convention).
50 #+unix ; env works differently for msys2 apparently
51 (let ((string (with-output-to-string (stream)
52 (sb-ext:run-program "/usr/bin/env" ()
53 :output stream
54 :environment '("FEEFIE=foefum")))))
55 (assert (equal string "FEEFIE=foefum
56 ")))
58 (when (fboundp (find-symbol "UNIX-POLL" "SB-UNIX"))
59 (let ((f (open "/dev/null")))
60 (with-alien ((dup (function int int) :extern))
61 (dotimes (i 1025) (alien-funcall dup (sb-impl::fd-stream-fd f)))
62 (assert (> (alien-funcall dup (sb-impl::fd-stream-fd f)) 1024)))))
64 ;; Unicode strings
65 #+unix
66 (flet ((try (sb-impl::*default-external-format* x y)
67 (let* ((process (run-program
68 "/bin/sh" (list "-c" (format nil "echo ~c, $SB_TEST_FOO." x))
69 :environment (list (format nil "SB_TEST_FOO=~c" y))
70 :output :stream
71 :wait t))
72 (output (read-line (process-output process)))
73 (wanted (format nil "~c, ~c." x y)))
74 (unless (equal output wanted)
75 (error "wanted ~S, got ~S" wanted output))
76 (process-close process))))
77 (try :ascii #\s #\b)
78 (try :latin-1 (code-char 197) (code-char 229))
79 #+sb-unicode
80 (try :utf-8 #\GREEK_CAPITAL_LETTER_OMEGA #\GREEK_SMALL_LETTER_OMEGA))
82 ;; The default Unix environment for the subprocess is the same as
83 ;; for the parent process. (I.e., we behave like perl and lots of
84 ;; other programs, but not like CMU CL.)
85 #+unix
86 (let* ((sb-impl::*default-external-format* :latin-1)
87 (sb-alien::*default-c-string-external-format* :latin-1)
88 (string (with-output-to-string (stream)
89 (sb-ext:run-program "/usr/bin/env" ()
90 :output stream)))
91 (expected (apply #'concatenate
92 'string
93 (mapcar (lambda (environ-string)
94 (concatenate 'string
95 environ-string
96 (string #\newline)))
97 (sb-ext:posix-environ)))))
98 (assert (string= string expected))
99 ;; That's not just because POSIX-ENVIRON is having a bad hair
100 ;; day and returning NIL, is it?
101 (assert (plusp (length (sb-ext:posix-environ)))))
102 ;; make sure that a stream input argument is basically reasonable.
103 (let ((string (let ((i (make-string-input-stream "abcdef")))
104 (with-output-to-string (stream)
105 (run-program "cat" ()
106 :search t :input i :output stream)))))
107 (assert (= (length string) 6))
108 (assert (string= string "abcdef")))
110 ;;; Test the bookkeeping involved in decoding the child's output:
112 ;; repeated short, properly-encoded reads exposed one bug. (But
113 ;; note: this test will be inconclusive if the child's stderr is
114 ;; fully buffered.)
115 (let ((str (with-output-to-string (s)
116 (our-run-program "/bin/sh"
117 '("-c" "(echo Foo; sleep 2; echo Bar)>&2")
118 :output s :search t :error :output :wait t))))
119 (assert (string= str (format nil "Foo~%Bar~%"))))
121 ;; end of file in the middle of a UTF-8 character
122 ;; (FIXME: asserting failure without knowing why is almost as good as no test at all.)
123 (typep (nth-value 1 (ignore-errors
124 (let ((sb-impl::*default-external-format* :utf-8))
125 (with-output-to-string (s)
126 (run-program "printf" '("\\316")
127 :output s :search t :wait t)))))
128 'error)
130 ;; success convention for this Lisp program run as part of a larger script
131 (sb-ext:quit :unix-status *exit-ok*)))
133 check_status_maybe_lose "run program tests" $?
135 exit $EXIT_TEST_WIN