Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 3 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 32 additions and 5 deletions.
  1. +14 −5 src/conch/sh.clj
  2. +18 −0 test/conch/sh_test.clj
19 src/conch/sh.clj
@@ -96,18 +96,27 @@
:out (queue-stream (:out proc) buffer-type)
:err (queue-stream (:err proc) buffer-type)))
+(defn compute-buffer [options]
+ (update-in options [:buffer]
+ #(if-let [buffer %]
+ buffer
+ (if (or (:seq options)
+ (ifn? (:out options))
+ (ifn? (:err options)))
+ :line
+ 1024))))
(defn run-command [name args options]
(let [proc (apply conch/proc name (add-proc-args args options))
- options (update-in options [:buffer] #(or %
- (if (:seq options)
- :line
- 1024)))
+ options (compute-buffer options)
{:keys [buffer out in err timeout verbose]} options
proc (queue-output proc buffer)
exit-code (future (if timeout
(conch/exit-code proc timeout)
(conch/exit-code proc)))]
- (when in (conch/feed-from-string proc (:in proc))) ;; This will become more sophisticated.
+ (when in
+ (conch/feed-from-string proc (:in options)) ;; This will become more sophisticated.
+ (conch/done proc))
(let [proc-out (redirect out options :out proc)
proc-err (redirect err options :err proc)]
18 test/conch/sh_test.clj
@@ -0,0 +1,18 @@
+ (:use clojure.test)
+ (:require [ :as sh]))
+(deftest output-test
+ (testing "By default, output is accumulated into a monolitic string"
+ (is (= "hi\n" (sh/with-programs [echo] (echo "hi")))))
+ (testing "Output can be a lazy sequence"
+ (is (= ["hi" "there"] (sh/with-programs [echo] (echo "hi\nthere" {:seq true})))))
+ (testing "Can redirect output to a file"
+ (let [output "hi\nthere\n"]
+ (sh/with-programs [echo] (echo "hi\nthere" {:out ( "testfile")}))
+ (is (= output (slurp "testfile")))))
+ (testing "Can redirect output to a callback function"
+ (let [x (atom [])]
+ (sh/with-programs [echo]
+ (echo "hi\nthere" {:out (fn [line _] (swap! x conj line))}))
+ (is (= ["hi" "there"] @x)))))

No commit comments for this range

Something went wrong with that request. Please try again.