0.7.1.1:
[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 SOMETHING_IN_THE_ENVIRONMENT='yes there is'
19 export SOMETHING_IN_THE_ENVIRONMENT
20
21 ${SBCL:-sbcl} <<EOF
22   (let ((string (with-output-to-string (stream)
23                   (sb-ext:run-program "/bin/echo"
24                                       '("foo" "bar")
25                                       :output stream))))
26     (assert (string= string "foo bar
27 ")))
28   ;; Unix environment strings are ordinarily passed with SBCL convention
29   ;; (instead of CMU CL alist-of-keywords convention).
30   (let ((string (with-output-to-string (stream)
31                   (sb-ext:run-program "/usr/bin/env" ()
32                                       :output stream
33                                       :environment '("FEEFIE=foefum")))))
34     (assert (string= string "FEEFIE=foefum
35 ")))
36   ;; The default Unix environment for the subprocess is the same as
37   ;; for the parent process. (I.e., we behave like perl and lots of
38   ;; other programs, but not like CMU CL.)
39   (let ((string (with-output-to-string (stream)
40                   (sb-ext:run-program "/usr/bin/env" ()
41                                       :output stream)))
42         (expected (apply #'concatenate
43                          'string
44                          (mapcar (lambda (environ-string)
45                                    (concatenate 'string
46                                                 environ-string
47                                                 (string #\newline)))
48                                  (sb-ext:posix-environ)))))
49     (assert (string= string expected)))
50   ;; That's not just because POSIX-ENVIRON is having a bad hair
51   ;; day and returning NIL, is it?
52   (assert (plusp (length (sb-ext:posix-environ))))
53   ;; success convention for this Lisp program run as part of a larger script
54   (sb-ext:quit :unix-status 52)))
55 EOF
56 if [ $? != 52 ]; then
57     echo test failed: $?
58     exit 1
59 fi
60
61 # success convention
62 exit 104