[#317] add clojure.repl/source
This commit is contained in:
parent
1c4014f7f9
commit
26473b8a42
2 changed files with 27 additions and 1 deletions
|
|
@ -38,7 +38,7 @@ args=( -jar $BABASHKA_JAR \
|
||||||
--initialize-at-run-time=java.lang.Math\$RandomNumberGeneratorHolder \
|
--initialize-at-run-time=java.lang.Math\$RandomNumberGeneratorHolder \
|
||||||
--initialize-at-build-time \
|
--initialize-at-build-time \
|
||||||
-H:Log=registerResource: \
|
-H:Log=registerResource: \
|
||||||
-H:EnableURLProtocols=jar,http,https \
|
-H:EnableURLProtocols=http,https \
|
||||||
--enable-all-security-services \
|
--enable-all-security-services \
|
||||||
-H:+JNI \
|
-H:+JNI \
|
||||||
--verbose \
|
--verbose \
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,7 @@
|
||||||
|
|
||||||
(deftest load-file-test
|
(deftest load-file-test
|
||||||
(let [tmp (java.io.File/createTempFile "script" ".clj")]
|
(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))")
|
(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)"
|
(is (= "120\n" (test-utils/bb nil (format "(load-file \"%s\") (foo/bar (foo/foo 10 30) 3)"
|
||||||
(.getPath tmp)))))
|
(.getPath tmp)))))
|
||||||
|
|
@ -130,6 +131,31 @@
|
||||||
(bb nil (format "(ns start-ns) (load-file \"%s\") (ns-name *ns*)"
|
(bb nil (format "(ns start-ns) (load-file \"%s\") (ns-name *ns*)"
|
||||||
(.getPath tmp))))))))
|
(.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
|
(deftest eval-test
|
||||||
(is (= "120\n" (test-utils/bb nil "(eval '(do (defn foo [x y] (+ x y))
|
(is (= "120\n" (test-utils/bb nil "(eval '(do (defn foo [x y] (+ x y))
|
||||||
(defn bar [x y] (* x y))
|
(defn bar [x y] (* x y))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue