From b522531e79cccb75f9d083c61f99af2965f1362d Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Mon, 6 Apr 2020 00:04:30 +0200 Subject: [PATCH] [#329] create non-existing ns in nREPL message --- src/babashka/impl/nrepl_server.clj | 2 +- test/babashka/impl/nrepl_server_test.clj | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/babashka/impl/nrepl_server.clj b/src/babashka/impl/nrepl_server.clj index 2f65dfce..22214c20 100644 --- a/src/babashka/impl/nrepl_server.clj +++ b/src/babashka/impl/nrepl_server.clj @@ -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)) diff --git a/test/babashka/impl/nrepl_server_test.clj b/test/babashka/impl/nrepl_server_test.clj index 42f3bca1..f0947bbc 100644 --- a/test/babashka/impl/nrepl_server_test.clj +++ b/test/babashka/impl/nrepl_server_test.clj @@ -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)