Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add super-basic test and documentation for custom eval option, NREPL-50

  • Loading branch information...
commit a0cf4c3029087f8869feaa5d391593ddc282cca8 1 parent cf08ed5
@cemerick cemerick authored
View
2  doc/ops.md
@@ -72,8 +72,8 @@ Evaluates code.
###### Optional parameters
+* `:eval` A fully-qualified symbol naming a var whose function value will be used to evaluate [code], instead of `clojure.core/eval` (the default).
* `:id` An opaque message ID that will be included in responses related to the evaluation, and which may be used to restrict the scope of a later "interrupt" operation.
-* `:eval` A namespace qualified symbol denoting an alternative to the `clojure.core/eval` function.
###### Returns
View
3  src/main/clojure/clojure/tools/nrepl/middleware/interruptible_eval.clj
@@ -208,7 +208,8 @@
{:doc "Evaluates code."
:requires {"code" "The code to be evaluated."
"session" "The ID of the session within which to evaluate the code."}
- :optional {"id" "An opaque message ID that will be included in responses related to the evaluation, and which may be used to restrict the scope of a later \"interrupt\" operation."}
+ :optional {"id" "An opaque message ID that will be included in responses related to the evaluation, and which may be used to restrict the scope of a later \"interrupt\" operation."
+ "eval" "A fully-qualified symbol naming a var whose function value will be used to evaluate [code], instead of `clojure.core/eval` (the default)."}
:returns {}}
"interrupt"
{:doc "Attempts to interrupt some code evaluation."
View
14 src/test/clojure/clojure/tools/nrepl_test.clj
@@ -66,6 +66,20 @@
(repl-values client "(defn x [] 6)")
(is (= [6] (repl-values client "(x)"))))
+(defn- dumb-alternative-eval
+ [form]
+ (let [result (eval form)]
+ (if (number? result)
+ (- result)
+ result)))
+
+(def-repl-test use-alternative-eval-fn
+ (is (= {:value ["-124750"]}
+ (-> (message timeout-client {:op :eval :eval "clojure.tools.nrepl-test/dumb-alternative-eval"
+ :code "(reduce + (range 500))"})
+ combine-responses
+ (select-keys [:value])))))
+
(def-repl-test unknown-op
(is (= {:op "abc" :status #{"error" "unknown-op" "done"}}
(-> (message timeout-client {:op :abc}) combine-responses (select-keys [:op :status])))))
Please sign in to comment.
Something went wrong with that request. Please try again.