diff options
author | Rutger van Beusekom <rutger.van.beusekom@verum.com> | 2020-03-02 10:38:57 +0100 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2020-05-16 22:36:19 +0200 |
commit | 786fbcd32764813969bd1a211d0003cf4a161b65 (patch) | |
tree | a76ea62308a6fadd9404dd9b6110e481b76b84f8 /test-suite/tests/popen.test | |
parent | 2c07a32ad85d6fce8a0e09bb457e7ff1885b4615 (diff) | |
download | guile-786fbcd32764813969bd1a211d0003cf4a161b65.tar.gz |
popen: Add 'pipeline' procedure.
* libguile/posix.c (scm_open_process): Remove.
(scm_piped_process): Add to replace open_process.
* module/ice-9/popen.scm (pipe->fdes): Add to convert pipe pair to fdes pair.
(open-process): Add open-process for backwards compatibility.
(pipeline): Add to implement a pipeline using piped-process.
* doc/ref/posix.texi (Pipes): Document it.
* test-suite/tests/popen.test ("open-process")
("piped-process", "piped-process: with output")
("pipeline"): New tests.
Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'test-suite/tests/popen.test')
-rw-r--r-- | test-suite/tests/popen.test | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/test-suite/tests/popen.test b/test-suite/tests/popen.test index 2c0877484..529166802 100644 --- a/test-suite/tests/popen.test +++ b/test-suite/tests/popen.test @@ -1,6 +1,6 @@ ;;;; popen.test --- exercise ice-9/popen.scm -*- scheme -*- ;;;; -;;;; Copyright 2003, 2006, 2010, 2011, 2013, 2014 Free Software Foundation, Inc. +;;;; Copyright 2003, 2006, 2010, 2011, 2013, 2014, 2020 Free Software Foundation, Inc. ;;;; ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public @@ -17,7 +17,10 @@ ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA (define-module (test-suite test-ice-9-popen) - #:use-module (test-suite lib)) + #:use-module (test-suite lib) + #:use-module (ice-9 receive) + #:use-module (ice-9 rdelim)) + ;; read from PORT until eof is reached, return what's read as a string (define (read-string-to-eof port) @@ -211,3 +214,34 @@ exec 2>~a; read REPLY" (let ((st (close-pipe (open-output-pipe "exit 1")))) (and (status:exit-val st) (= 1 (status:exit-val st))))))) + + +;; +;; pipeline related tests +;; + +(pass-if "open-process" + (receive (from to pid) + ((@@ (ice-9 popen) open-process) OPEN_BOTH "rev") + (display "dlrow olleh" to) (close to) + (and (equal? "hello world" (read-string from)) + (= 0 (status:exit-val (cdr (waitpid pid))))))) + +(pass-if "piped-process" + (= 42 (status:exit-val + (cdr (waitpid ((@@ (ice-9 popen) piped-process) + "./meta/guile" '("-c" "(exit 42)"))))))) + +(pass-if "piped-process: with output" + (let* ((p (pipe)) + (pid ((@@ (ice-9 popen) piped-process) "echo" '("foo" "bar") + (cons (port->fdes (car p)) + (port->fdes (cdr p)))))) + (and (equal? "foo bar\n" (read-string (car p))) + (= 0 (status:exit-val (cdr (waitpid pid))))))) + +(pass-if "pipeline" + (receive (from to pids) + (pipeline '(("echo" "dlrow olleh") ("rev"))) + (and (string=? "hello world\n" (read-string from)) + (equal? '(0 0) (map (compose status:exit-val cdr waitpid) pids))))) |