Skip to content

Commit

Permalink
Revert to earlier test fn
Browse files Browse the repository at this point in the history
  • Loading branch information
shen-tian committed Sep 24, 2019
1 parent 2c9fc2f commit 29ee553
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 38 deletions.
1 change: 0 additions & 1 deletion Makefile
Expand Up @@ -3,7 +3,6 @@
VERSION ?= 1.10

test:
javac test-resources/HelloFactory.java
lein with-profile +$(VERSION),+test test

eastwood:
Expand Down
63 changes: 26 additions & 37 deletions test/clojure/nrepl/core_test.clj
Expand Up @@ -1088,9 +1088,6 @@
(defn- sideloader-client
[session resources classes]
(fn [{:keys [type name]}]
(.println System/out (str "look: " [type name]))
(.println System/out (str "r: " resources))
(.println System/out (str "c: " classes))
(case type
"resource"
(session {:id (uuid)
Expand All @@ -1110,60 +1107,52 @@
:type type
:name name
:content (if-some [^File file (classes name)]
(let [x (-> file
io/input-stream
sideloader/base64-encode)]
(.println System/out (str "b64:" x))
x)
(do
(.println System/out (str "not found"))
(.println System/out (str classes))
""))}))))
(-> file
io/input-stream
sideloader/base64-encode)
"")}))))

(defn- eval-with-sideloader [session code resources classes]
(let [eval-id "eval"
loader-id "sideload"
slc (sideloader-client session resources classes)
;; Deals with sideloader messages
_ (future
(run! (fn [{:keys [id status] :as msg}]
(when (some #{"sideloader-lookup" :sideloader-lookup} status)
(slc msg)))
(message session {:id loader-id
:op "sideloader-start"})))
msgs (message session {:id eval-id
:op "eval" :code code})]
(let [eval-id (uuid)
loader-id (uuid)
_ (session {:id loader-id :op "sideloader-start"})
msgs (session {:id eval-id :op "eval" :code code})
slc (sideloader-client session resources classes)]
(->> msgs
response-values)))

(def-repl-test sideloader-1
(remove (fn [{:keys [id status] :as msg}]
(when (and (= id loader-id)
(some #{"sideloader-lookup" :sideloader-lookup} status))
(slc msg))
(not= id eval-id)))
(map read-response-value)
(reduce (fn [v {:keys [id status value] :as msg}]
(cond-> (or v value)
(some #{:done "done"} status) reduced)) nil))))

(def-repl-test sideloader
(testing "Loading resources"
(let [code-snippet (code (slurp (.getResourceAsStream (.getContextClassLoader (Thread/currentThread)) "hello")))]
(is (= ["Hello nREPL"]
(is (= "Hello nREPL"
(eval-with-sideloader session
code-snippet
{"hello" "Hello nREPL"} {}))))))

(def-repl-test sideloader-2a
{"hello" "Hello nREPL"} {})))))
(let [code-snippet (code
(with-bindings
{clojure.lang.Compiler/LOADER (.getContextClassLoader (Thread/currentThread))}
(require '[foo.bar :as bar]))
(bar/hello))]
(testing "Loading source as resource (clj)"
(is (= [nil "Hello nREPL"]
(is (= "Hello nREPL"
(eval-with-sideloader session
code-snippet
{"foo/bar.clj" "(ns foo.bar) (defn hello [] \"Hello nREPL\")"}
{}))))
(testing "Loading source as resource (cljc)"
(is (= [nil "Hello nREPL"]
(is (= "Hello nREPL"
(eval-with-sideloader session
code-snippet
{"foo/bar.cljc" "(ns foo.bar) (defn hello [] \"Hello nREPL\")"}
{}))))))

(def-repl-test sideloader-3
{})))))
(testing "Loading class"
(let [code-snippet (code
(with-bindings
Expand All @@ -1172,7 +1161,7 @@
(import 'nrepl.HelloFactory)
nil))
(nrepl.HelloFactory/hello))]
(is (= [nil "Hello nREPL"]
(is (= "Hello nREPL"
(eval-with-sideloader session
code-snippet
{}
Expand Down

0 comments on commit 29ee553

Please sign in to comment.