From 26473b8a4230054af51adae8cb03ef162b3af140 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Thu, 16 Apr 2020 20:57:59 +0200 Subject: [PATCH] [#317] add clojure.repl/source --- script/compile | 2 +- test/babashka/main_test.clj | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/script/compile b/script/compile index c1515cbc..3d1562a4 100755 --- a/script/compile +++ b/script/compile @@ -38,7 +38,7 @@ args=( -jar $BABASHKA_JAR \ --initialize-at-run-time=java.lang.Math\$RandomNumberGeneratorHolder \ --initialize-at-build-time \ -H:Log=registerResource: \ - -H:EnableURLProtocols=jar,http,https \ + -H:EnableURLProtocols=http,https \ --enable-all-security-services \ -H:+JNI \ --verbose \ diff --git a/test/babashka/main_test.clj b/test/babashka/main_test.clj index bbe33abb..956e1b08 100644 --- a/test/babashka/main_test.clj +++ b/test/babashka/main_test.clj @@ -122,6 +122,7 @@ (deftest load-file-test (let [tmp (java.io.File/createTempFile "script" ".clj")] + (.deleteOnExit tmp) (spit tmp "(ns foo) (defn foo [x y] (+ x y)) (defn bar [x y] (* x y))") (is (= "120\n" (test-utils/bb nil (format "(load-file \"%s\") (foo/bar (foo/foo 10 30) 3)" (.getPath tmp))))) @@ -130,6 +131,31 @@ (bb nil (format "(ns start-ns) (load-file \"%s\") (ns-name *ns*)" (.getPath tmp)))))))) +(deftest repl-source-test + (let [tmp (java.io.File/createTempFile "lib" ".clj") + name (str/replace (.getName tmp) ".clj" "") + dir (.getParent tmp)] + (.deleteOnExit tmp) + (testing "print source from loaded file" + (spit tmp (format " +(ns %s) + +(defn foo [x y] + (+ x y))" name)) + (is (= "(defn foo [x y]\n (+ x y))\n" + (bb nil (format " +(load-file \"%s\") +(require '[clojure.repl :refer [source]]) +(with-out-str (source %s/foo))" + (.getPath tmp) + name))))) + (testing "print source from file on classpath" + (is (= "(defn foo [x y]\n (+ x y))\n" + (bb nil + "-cp" dir + "-e" (format "(require '[clojure.repl :refer [source]] '[%s])" name) + "-e" (format "(with-out-str (source %s/foo))" name))))))) + (deftest eval-test (is (= "120\n" (test-utils/bb nil "(eval '(do (defn foo [x y] (+ x y)) (defn bar [x y] (* x y))