Welcome! Please see the About page for a little more info on how this works.

0 votes
in Test by

My -main function reads arguments from *in*, like this:

(defn -main
  [& args]
  (doseq [ln (line-seq (java.io.BufferedReader. *in*))]
  ; Do something...

I use my app basically like: $ lein run < input.txt.

I would like to test this function but I don't know how I would write a test case that simulates the stdin passing data to my -main function.

Thank you.

2 Answers

+1 vote

*in* is a dynamic variable - you can rebind it in a test to something that reads from a string (using something like java.io.StringReader).

0 votes

Use with-in-str https://clojuredocs.org/clojure.core/with-in-str.

(with-in-str "inputstring"