[#329] create non-existing ns in nREPL message

This commit is contained in:
Michiel Borkent 2020-04-06 00:04:30 +02:00
parent 3499310944
commit b522531e79
2 changed files with 5 additions and 4 deletions

View file

@ -41,7 +41,7 @@
(defn eval-msg [ctx o msg #_threads]
(try
(let [ns-str (get msg :ns)
sci-ns (when ns-str (sci-utils/namespace-object (:env ctx) (symbol ns-str) nil false))
sci-ns (when ns-str (sci-utils/namespace-object (:env ctx) (symbol ns-str) true nil))
sw (StringWriter.)]
(sci/with-bindings (cond-> {sci/out sw}
sci-ns (assoc vars/current-ns sci-ns))

View file

@ -69,13 +69,14 @@
"id" (new-id!)
"ns" "ns0"})
(is (= ":foo0" (:value (read-reply in session @id)))))
(testing "providing an ns value of a non-existing namespace falls back the last defined namespace"
(testing "providing an ns value of a non-existing namespace creates the namespace"
(bencode/write-bencode os {"op" "eval"
"code" "(foo)"
"code" "(ns-name *ns*)"
"session" session
"id" (new-id!)
"ns" "unicorn"})
(is (= ":foo1" (:value (read-reply in session @id)))))))
(let [reply (read-reply in session @id)]
(is (= "unicorn" (:value reply)))))))
(testing "load-file"
(bencode/write-bencode os {"op" "load-file" "file" "(ns foo) (defn foo [] :foo)" "session" session "id" (new-id!)})
(read-reply in session @id)