diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 0e8dc4b6..b1c71bb0 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -365,6 +365,8 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that :cp new-cp}))) nil) +(defn classpath [] + (:cp @cp-state)) ;;(def ^:private server-ns-obj (sci/create-ns 'clojure.core.server nil)) @@ -395,7 +397,8 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that (let [opts (apply hash-map opts)] (repl/start-repl! @common/ctx opts)))} 'clojure.test t/clojure-test-namespace - 'babashka.classpath {'add-classpath add-classpath*} + 'babashka.classpath {'add-classpath add-classpath* + 'classpath classpath} 'clojure.pprint pprint-namespace 'babashka.curl curl-namespace 'babashka.pods pods/pods-namespace @@ -674,4 +677,3 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that ;;;; Scratch (comment) - diff --git a/test/babashka/classpath_test.clj b/test/babashka/classpath_test.clj index b1d5630d..00b1bbd1 100644 --- a/test/babashka/classpath_test.clj +++ b/test/babashka/classpath_test.clj @@ -20,6 +20,14 @@ (tu/bb nil "(require '[foo :as f])")))) +(deftest babashka-classpath-test + (is (= "test-resources" + (bb nil "--classpath" "test-resources" + "(require '[babashka.classpath :as cp]) (cp/classpath)"))) + (is (= "test-resources:foobar" + (bb nil "--classpath" "test-resources" + "(require '[babashka.classpath :as cp]) (cp/add-classpath \"foobar\") (cp/classpath)")))) + (deftest classpath-env-test ;; for this test you have to set `BABASHKA_CLASSPATH` to test-resources/babashka/src_for_classpath_test/env ;; and `BABASHKA_PRELOADS` to "(require '[env-ns])"