X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=tests%2Frun-program.test.sh;h=03778521bce05af1be75da7c6ee2a808ed2f7b3c;hb=cf49f2d086069a9c1b57f501df9a6a0bd3a34c3c;hp=a1a36e71b91c50c3a5c50160a0d21c8168fa30e7;hpb=cc1f30efe1c7438bfe6a413f16145ba2d63f7fe2;p=sbcl.git diff --git a/tests/run-program.test.sh b/tests/run-program.test.sh index a1a36e7..0377852 100644 --- a/tests/run-program.test.sh +++ b/tests/run-program.test.sh @@ -2,30 +2,112 @@ # tests related to SB-EXT:RUN-PROGRAM -sbcl --noinform --noprint --sysinit /dev/null --userinit /dev/null < error in function SB-IMPL::%ENUMERATE-SEARCH-LIST: -# Undefined search list: path -# -# (SB-EXT:RUN-PROGRAM "/bin/uname" '("-a") :OUTPUT :STREAM) -# doesn't return a STREAM (the way doc string claims) + ;; Unicode strings + (flet ((try (sb-impl::*default-external-format* x y) + (let* ((process (run-program + "/bin/sh" (list "-c" (format nil "echo ~c, $SB_TEST_FOO." x)) + :environment (list (format nil "SB_TEST_FOO=~c" y)) + :output :stream + :wait t)) + (output (read-line (process-output process))) + (wanted (format nil "~c, ~c." x y))) + (unless (equal output wanted) + (error "wanted ~S, got ~S" wanted output)) + (process-close process)))) + (try :ascii #\s #\b) + (try :latin-1 (code-char 197) (code-char 229)) + #+sb-unicode + (try :utf-8 #\GREEK_CAPITAL_LETTER_OMEGA #\GREEK_SMALL_LETTER_OMEGA)) + + ;; The default Unix environment for the subprocess is the same as + ;; for the parent process. (I.e., we behave like perl and lots of + ;; other programs, but not like CMU CL.) + (let ((string (with-output-to-string (stream) + (sb-ext:run-program "/usr/bin/env" () + :output stream))) + (expected (apply #'concatenate + 'string + (mapcar (lambda (environ-string) + (concatenate 'string + environ-string + (string #\newline))) + (sb-ext:posix-environ))))) + (assert (string= string expected))) + ;; That's not just because POSIX-ENVIRON is having a bad hair + ;; day and returning NIL, is it? + (assert (plusp (length (sb-ext:posix-environ)))) + ;; make sure that a stream input argument is basically reasonable. + (let ((string (let ((i (make-string-input-stream "abcdef"))) + (with-output-to-string (stream) + (sb-ext:run-program "/bin/cat" () + :input i :output stream))))) + (assert (= (length string) 6)) + (assert (string= string "abcdef"))) + + ;;; Test the bookkeeping involved in decoding the child's output: + + ;; repeated short, properly-encoded reads exposed one bug. (But + ;; note: this test will be inconclusive if the child's stderr is + ;; fully buffered.) + (let ((str (with-output-to-string (s) + (run-program "/bin/sh" + '("-c" "(echo Foo; sleep 2; echo Bar)>&2") + :output s :search t :error :output :wait t)))) + (assert (string= str (format nil "Foo~%Bar~%")))) + + ;; end of file in the middle of a UTF-8 character + (typep (nth-value 1 (ignore-errors + (let ((sb-impl::*default-external-format* :utf-8)) + (with-output-to-string (s) + (run-program "printf" '("\\316") + :output s :search t :wait t))))) + 'error) + + ;; success convention for this Lisp program run as part of a larger script + (sb-ext:quit :unix-status *exit-ok*))) +EOF +check_status_maybe_lose "run program tests" $? -# success convention -exit 104 +exit $EXIT_TEST_WIN