0.6.11.12:
[sbcl.git] / tests / run-program.test.sh
1 #!/bin/sh
2
3 # tests related to SB-EXT:RUN-PROGRAM
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 # Make sure that there's at least something in the environment (for
17 # one of the tests below).
18 export SOMETHING_IN_THE_ENVIRONMENT='yes there is'
19
20 sbcl="$1"
21
22 $sbcl <<EOF
23   (let ((string (with-output-to-string (stream)
24                   (sb-ext:run-program "/bin/echo"
25                                       '("foo" "bar")
26                                       :output stream))))
27     (assert (string= string "foo bar
28 ")))
29   ;; Unix environment strings are ordinarily passed with SBCL convention
30   ;; (instead of CMU CL alist-of-keywords convention).
31   (let ((string (with-output-to-string (stream)
32                   (sb-ext:run-program "/usr/bin/env" ()
33                                       :output stream
34                                       :environment '("FEEFIE=foefum")))))
35     (assert (string= string "FEEFIE=foefum
36 ")))
37   ;; The default Unix environment for the subprocess is the same as
38   ;; for the parent process. (I.e., we behave like perl and lots of
39   ;; other programs, but not like CMU CL.)
40   (let ((string (with-output-to-string (stream)
41                   (sb-ext:run-program "/usr/bin/env" ()
42                                       :output stream)))
43         (expected (apply #'concatenate
44                          'string
45                          (mapcar (lambda (environ-string)
46                                    (concatenate 'string
47                                                 environ-string
48                                                 (string #\newline)))
49                                  (sb-ext:posix-environ)))))
50     (assert (string= string expected)))
51   ;; That's not just because POSIX-ENVIRON is having a bad hair
52   ;; day and returning NIL, is it?
53   (assert (plusp (length (sb-ext:posix-environ))))
54   ;; success convention for this Lisp program run as part of a larger script
55   (sb-ext:quit :unix-status 52)))
56 EOF
57 if [ $? != 52 ]; then
58     echo test failed: $?
59     exit 1
60 fi
61
62 # known bugs:
63 #
64 #   sbcl-0.6.8:
65 #
66 #     (SB-EXT:RUN-PROGRAM "echo" NIL)
67 #     => error in function SB-IMPL::%ENUMERATE-SEARCH-LIST:
68 #        Undefined search list: path
69 #
70 #     (SB-EXT:RUN-PROGRAM "/bin/uname" '("-a") :OUTPUT :STREAM)
71 #     doesn't return a STREAM (the way doc string claims)
72
73 # success convention
74 exit 104