add clojure.main/with-read-known
This commit is contained in:
parent
d56ad70e3e
commit
f9452b4977
3 changed files with 26 additions and 0 deletions
|
|
@ -55,6 +55,13 @@ by default when a new command-line REPL is started."} repl-requires
|
|||
'[[clojure.repl :refer (source apropos pst dir doc find-doc)]
|
||||
[clojure.pprint :refer (pp pprint)]])
|
||||
|
||||
(defmacro with-read-known
|
||||
"Evaluates body with *read-eval* set to a \"known\" value,
|
||||
i.e. substituting true for :unknown if necessary."
|
||||
[& body]
|
||||
`(binding [*read-eval* (if (= :unknown *read-eval*) true *read-eval*)]
|
||||
~@body))
|
||||
|
||||
(defn repl
|
||||
"Generic, reusable, read-eval-print loop. By default, reads from *in*,
|
||||
writes to *out*, and prints exception summaries to *err*. If you use the
|
||||
|
|
|
|||
|
|
@ -385,6 +385,7 @@ Use bb run --help to show this help output.
|
|||
(repl/start-repl! (common/ctx) opts))) {:ns clojure-main-ns})
|
||||
'with-bindings (sci/copy-var clojure-main/with-bindings clojure-main-ns)
|
||||
'repl-caught (sci/copy-var repl/repl-caught clojure-main-ns)
|
||||
'with-read-known (sci/copy-var clojure-main/with-read-known clojure-main-ns)
|
||||
'main main-var}
|
||||
'clojure.test t/clojure-test-namespace
|
||||
'clojure.math math-namespace
|
||||
|
|
|
|||
18
test/babashka/impl/clojure/main_test.clj
Normal file
18
test/babashka/impl/clojure/main_test.clj
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
(ns babashka.impl.clojure.main-test
|
||||
(:require [babashka.test-utils :as tu]
|
||||
[clojure.edn :as edn]
|
||||
[clojure.test :as t :refer [deftest is testing]]))
|
||||
|
||||
(def bb
|
||||
(comp edn/read-string tu/bb))
|
||||
|
||||
(deftest with-read-known-test
|
||||
(testing ":unknown gets set to true"
|
||||
(is (true? (bb nil (pr-str '(binding [*read-eval* :unknown]
|
||||
(clojure.main/with-read-known *read-eval*)))))))
|
||||
(testing "other values don't change"
|
||||
(t/are [read-eval-value]
|
||||
(= read-eval-value
|
||||
(bb nil (str "(binding [*read-eval* " read-eval-value "]"
|
||||
" (clojure.main/with-read-known *read-eval*))")))
|
||||
false true 5)))
|
||||
Loading…
Reference in a new issue