Clojure reading error as part of leiningen test

I am testing some kind of sound behavior and I need the user to evaluate whether something is passing or not. I would like to ask the user to respond as part of the leiningen test. But something is happening with read-line, which prevents it.

This is sample test code after creating a new clojure project with "lein new foo" and editing the file foo / test / foo / core_test.clj:

(ns foo.core-test
  (:use clojure.test
        foo.core))

(deftest a-test
  (testing "FIXME, what a fail."
    (let [_ (println "enter something")
          yn (read-line)]
      (println yn)
      (is (= yn "y")))))

and this is what happens in the “lein test”

lein test foo.core-test
enter something
hi
there
what
is 
going on?
^C

only control-C stops the call (read-line).

I am using clojure 1.4.0 and Leiningen 2.0.0-preview7 on Java 1.6.0_35 Java HotSpot (TM) 64-bit server VM

Any ideas on how to get read-line to work inside the test?

I should also note that (read-line) works fine inside "lein repl" for me ...

> lein repl
nREPL server started on port 54398
REPL-y 0.1.0-beta8
Clojure 1.4.0
    Exit: Control+D or (exit) or (quit)
Commands: (user/help)
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
          (user/sourcery function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
Examples from clojuredocs.org: [clojuredocs or cdoc]
          (user/clojuredocs name-here)
          (user/clojuredocs "ns-here" "name-here")

user=> (println (read-line))
       hi
hi
nil
user=> (read-line)
       ho
"ho"

UPDATE:

@DaoWen . Google, stdin b0rken leiningen. , , , . , , .

(ns foo.core-test
  (:use clojure.test
        foo.core))

(import 'javax.swing.JOptionPane)

(defn ask-yn
  "return 0 on pass, 1 on fail"
  [prompt]
  (JOptionPane/showConfirmDialog nil prompt "User Input" JOptionPane/YES_NO_OPTION))

(deftest a-test
  (testing "a-test"
    (let [yn (ask-yn "did a-test pass?")]
      (is (= yn 0)))))

(deftest b-test
  (testing "b-test"
    (let [yn (ask-yn "did b-test pass?")]
      (is (= yn 0)))))
+5
1

, read-line, , , , JOptionPane . , "" "", , .

(import 'javax.swing.JOptionPane)
(JOptionPane/showConfirmDialog nil "Did the test pass?" "User Input" JOptionPane/YES_NO_OPTION)

Update:

, :

read-line ENTER ( ) lein run, lein repl?

, lein trampoline test lein test, stdin.

+2

All Articles