Peter Bex avatar Peter Bex committed 06f4fed

Fix nested pipe expressions and run/sexps, adding tests for both

Comments (0)

Files changed (2)

 (define (run/sexp* thunk)
   (read (run/port* thunk)))
 (define (run/sexps* thunk)
-  (read-all (run/port* thunk)))
+  (read-file (run/port* thunk)))
 
 ;;;;;;;;;;;;
 ;; Syntax ;;
              ((_ ((?from0 ?from1 ___ ?to) ___) ?pf0 ___ ?last-pf)
               (let ((conns `((?from0 ?from1 ___ ?to) ___)))
                  (setup-redirection ?redir0) ...
-                (begin (fork/pipe+ conns (lambda () (exec-epf (epf ?pf0))))
-                       ___
-                       (exec-epf (epf ?last-pf))))))))
+                 (begin (fork/pipe+ conns (lambda () (exec-epf (epf ?pf0))))
+                        ___
+                        (exec-epf (epf ?last-pf))))))))
        (pipe+ ?args ...)))
     ((_ (begin ?expr0 ...))
      (begin (setup-redirection (= 0 (current-input-port)))
             (setup-redirection (= 1 (current-output-port)))
             (setup-redirection (= 2 (current-error-port)))
             ?expr0 ...))
-    ;; epf can be used if you happen to have a program called
-    ;; "epf", "begin", "pipe", etc which you'd like to run.
-    ((_ (epf ?args ...))
-     (let-syntax ((exec-epf
-                   (syntax-rules ___ ()
-                     ((_ (?prog ?arg0 ___) ?redir0 ___)
-                      (begin
-                        (setup-redirection ?redir0) ___
-                        (exec-path `?prog `?arg0 ___))))))
-       (exec-epf ?args ...)))
+    ((_ (epf ?args ...))          ; TODO: Figure out the point of this
+     (exec-epf ?args ...))
     ;; This is purely for convenience, so you don't need the (epf ...) wrapper
     ((_ (?prog ?arg0 ...) ?redir0 ...)
-     (exec-epf (epf (?prog ?arg0 ...) ?redir0 ...)))))
+     (begin
+       (setup-redirection ?redir0) ...
+       (exec-path `?prog `?arg0 ...)))))
 
 )
 
  (test "Simple run/string"
        "hi, there\n"
-       (run/string (echo "hi, there"))))
+       (run/string (echo "hi, there")))
+
+ (test "Simple run/sexp"
+       '("hi, there")
+       (run/sexp (echo "(\"hi, there\")")))
+
+ (test "Simple run/sexps"
+       '(("hi, there") (a b c))
+       (run/sexps (echo "(\"hi, there\") (a b c)")))
+
+ (test "Nested output redirection with pipe+"
+       "foo\n"
+       (run/string (pipe+ ((1 0))
+                          (pipe+ ((2 0)) (sh -c "echo foo >&2") (cat))
+                          (cat)))))
 
 (test-exit)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.