From f9e883248c9e51fdcb5ac9cc0fc497c4f3de207c Mon Sep 17 00:00:00 2001 From: Bob Date: Wed, 29 May 2024 20:19:10 -0400 Subject: [PATCH] add dynamic var `*source-path*` to `clojure.core` --- src/babashka/impl/clojure/core.clj | 2 ++ test/babashka/impl/clojure/core_test.clj | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 test/babashka/impl/clojure/core_test.clj diff --git a/src/babashka/impl/clojure/core.clj b/src/babashka/impl/clojure/core.clj index b887715f..2aaf2e09 100644 --- a/src/babashka/impl/clojure/core.clj +++ b/src/babashka/impl/clojure/core.clj @@ -27,6 +27,7 @@ (def math-context (core-dynamic-var '*math-context*)) (def compile-path (core-dynamic-var '*compile-path* *compile-path*)) (def compiler-options (core-dynamic-var '*compiler-options*)) +(def source-path (core-dynamic-var '*source-path*)) (defn read+string "Added for compatibility. Must be used with @@ -167,6 +168,7 @@ '*math-context* math-context '*compiler-options* compiler-options '*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) ;; STM diff --git a/test/babashka/impl/clojure/core_test.clj b/test/babashka/impl/clojure/core_test.clj new file mode 100644 index 00000000..819e307e --- /dev/null +++ b/test/babashka/impl/clojure/core_test.clj @@ -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]))))))) \ No newline at end of file