Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 2 commits
  • 2 files changed
  • 0 comments
  • 1 contributor
Sep 30, 2012
Anthony Grimes If output is a future, wait for it to finish.
If a user wants to use a callback and not wait for a program to finish, he can
use :background to run the whole thing in a future. In fact, :background might
go away in the future, seeing as how it is less characters to just wrap the
program call in a future manually.
6021a9c
Anthony Grimes Test :err and clean up tests a bit. 40d9e44
2  src/conch/sh.clj
@@ -119,6 +119,8 @@
119 119
       (conch/done proc))
120 120
     (let [proc-out (redirect out options :out proc)
121 121
           proc-err (redirect err options :err proc)]
  122
+      (when (future? proc-out) @proc-out)
  123
+      (when (future? proc-err) @proc-err)
122 124
       (cond
123 125
        verbose {:proc proc
124 126
                 :exit-code @exit-code
33  test/conch/sh_test.clj
@@ -3,16 +3,23 @@
3 3
   (:require [conch.sh :as sh]))
4 4
 
5 5
 (deftest output-test
6  
-  (testing "By default, output is accumulated into a monolitic string"
7  
-    (is (= "hi\n" (sh/with-programs [echo] (echo "hi")))))
8  
-  (testing "Output can be a lazy sequence"
9  
-    (is (= ["hi" "there"] (sh/with-programs [echo] (echo "hi\nthere" {:seq true})))))
10  
-  (testing "Can redirect output to a file"
11  
-    (let [output "hi\nthere\n"]
12  
-      (sh/with-programs [echo] (echo "hi\nthere" {:out (java.io.File. "testfile")}))
13  
-      (is (= output (slurp "testfile")))))
14  
-  (testing "Can redirect output to a callback function"
15  
-    (let [x (atom [])]
16  
-      (sh/with-programs [echo]
17  
-        (echo "hi\nthere" {:out (fn [line _] (swap! x conj line))}))
18  
-      (is (= ["hi" "there"] @x)))))
  6
+  (sh/let-programs [errecho "test/testfiles/errecho"]
  7
+    (sh/with-programs [echo]
  8
+      (testing "By default, output is accumulated into a monolitic string"
  9
+        (is (= "hi\n" (echo "hi"))))
  10
+      (testing "Output can be a lazy sequence"
  11
+        (is (= ["hi" "there"] (echo "hi\nthere" {:seq true}))))
  12
+      (testing "Can redirect output to a file"
  13
+        (let [output "hi\nthere\n"
  14
+              testfile "test/testfiles/foo"]
  15
+          (echo "hi\nthere" {:out (java.io.File. testfile)})
  16
+          (is (= output (slurp testfile)))
  17
+          (errecho "hi\nthere" {:err (java.io.File. testfile)})
  18
+          (is (= output (slurp testfile)))))
  19
+      (testing "Can redirect output to a callback function"
  20
+        (let [x (atom [])
  21
+              ex (atom [])]
  22
+          (echo "hi\nthere" {:out (fn [line _] (swap! x conj line))})
  23
+          (is (= ["hi" "there"] @x))
  24
+          (errecho "hi\nthere" {:err (fn [line _] (swap! ex conj line))})
  25
+          (is (= ["hi" "there"] @ex)))))))

No commit comments for this range

Something went wrong with that request. Please try again.