[#535] fix order in --uberscript (2)

This commit is contained in:
Michiel Borkent 2020-08-16 18:00:39 +02:00
parent 0829ccbe2e
commit 02032625ee
6 changed files with 37 additions and 9 deletions

2
sci

@ -1 +1 @@
Subproject commit 0da67e32e2930aa0ea18c9350b8a40fc0b9cb502
Subproject commit a92fce09210f47a8243a30e6d4a0a6febca21c27

View file

@ -32,6 +32,7 @@
[clojure.string :as str]
[sci.addons :as addons]
[sci.core :as sci]
[sci.impl.namespaces :as sci-namespaces]
[sci.impl.unrestrict :refer [*unrestricted*]]
[sci.impl.vars :as vars])
(:gen-class))
@ -479,11 +480,18 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
(System/getenv "BABASHKA_CLASSPATH"))
_ (when classpath
(add-classpath* classpath))
load-fn (fn [{:keys [:namespace]}]
(when-let [{:keys [:loader]} @cp-state]
(let [res (cp/source-for-namespace loader namespace nil)]
(when uberscript (swap! uberscript-sources conj (:source res)))
res)))
load-fn (fn [{:keys [:namespace :reload]}]
(when-let [{:keys [:loader]}
@cp-state]
(if ;; ignore built-in namespaces when uberscripting, unless with :reload
(and uberscript
(not reload)
(or (contains? namespaces namespace)
(contains? sci-namespaces/namespaces namespace)))
""
(let [res (cp/source-for-namespace loader namespace nil)]
(when uberscript (swap! uberscript-sources conj (:source res)))
res))))
_ (when file
(let [abs-path (.getAbsolutePath (io/file file))]
(vars/bindRoot sci/file abs-path)
@ -516,8 +524,7 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
:classes classes/class-map
:imports imports
:load-fn load-fn
:dry-run uberscript
:reload true
:uberscript uberscript
:readers core/data-readers}
opts (addons/future opts)
sci-ctx (sci/init opts)

View file

@ -0,0 +1,6 @@
(ns my.impl
(:require [clojure.string]))
(defn impl-fn
"identity"
[x] x)

View file

@ -0,0 +1,4 @@
(ns my.impl2
(:require [my.impl :as impl]))
(def impl-fn impl/impl-fn)

View file

@ -0,0 +1,6 @@
(ns my.main
(:require [my.impl :as impl])
(:require [my.impl2 :as impl2]))
(defn -main [& args]
(impl/impl-fn args))

View file

@ -39,7 +39,12 @@
(.deleteOnExit tmp-file)
(is (empty? (tu/bb nil "--classpath" "test-resources/babashka/src_for_classpath_test" "-m" "my.main" "--uberscript" (.getPath tmp-file))))
(is (= "(\"1\" \"2\" \"3\" \"4\")\n"
(tu/bb nil "--file" (.getPath tmp-file) "1" "2" "3" "4")))))
(tu/bb nil "--file" (.getPath tmp-file) "1" "2" "3" "4")))
(testing "order of namespaces is correct"
(tu/bb nil "--classpath" "test-resources/babashka/uberscript/src" "-m" "my.main" "--uberscript" (.getPath tmp-file))
(prn (slurp (.getPath tmp-file)))
(is (= "(\"1\" \"2\" \"3\" \"4\")\n"
(tu/bb nil "--file" (.getPath tmp-file) "1" "2" "3" "4"))))))
(deftest error-while-loading-test
(is (true?