add dynamic var *source-path* to clojure.core

This commit is contained in:
Bob 2024-05-29 20:19:10 -04:00
parent 2907e1fb19
commit f9e883248c
No known key found for this signature in database
2 changed files with 19 additions and 0 deletions

View file

@ -27,6 +27,7 @@
(def math-context (core-dynamic-var '*math-context*)) (def math-context (core-dynamic-var '*math-context*))
(def compile-path (core-dynamic-var '*compile-path* *compile-path*)) (def compile-path (core-dynamic-var '*compile-path* *compile-path*))
(def compiler-options (core-dynamic-var '*compiler-options*)) (def compiler-options (core-dynamic-var '*compiler-options*))
(def source-path (core-dynamic-var '*source-path*))
(defn read+string (defn read+string
"Added for compatibility. Must be used with "Added for compatibility. Must be used with
@ -167,6 +168,7 @@
'*math-context* math-context '*math-context* math-context
'*compiler-options* compiler-options '*compiler-options* compiler-options
'*compile-path* compile-path '*compile-path* compile-path
'*source-path* source-path
'with-precision (sci/copy-var with-precision clojure-core-ns) 'with-precision (sci/copy-var with-precision clojure-core-ns)
'-with-precision (sci/copy-var -with-precision clojure-core-ns) '-with-precision (sci/copy-var -with-precision clojure-core-ns)
;; STM ;; STM

View file

@ -0,0 +1,17 @@
(ns babashka.impl.clojure.core-test
(:require [babashka.test-utils :as tu]
[clojure.test :as t :refer [deftest is testing]]
[clojure.tools.reader.edn :as edn]))
(def bb
(comp edn/read-string tu/bb))
(deftest source-path-test
(testing "source path is nil by default"
(is (empty? (bb nil "*source-path*"))))
(testing "source path can be bound dynamically"
(is (= ["some_value.clj" nil]
(bb nil (pr-str '(let [x (binding [*source-path* "some_value.clj"]
*source-path*)
y *source-path*]
[x y])))))))