[#478] Add babashka.file property
This commit is contained in:
parent
8a75a70bbe
commit
d422cbb91a
4 changed files with 20 additions and 3 deletions
|
|
@ -479,7 +479,10 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
|
|||
(let [res (cp/source-for-namespace loader namespace nil)]
|
||||
(when uberscript (swap! uberscript-sources conj (:source res)))
|
||||
res)))
|
||||
_ (when file (vars/bindRoot sci/file (.getCanonicalPath (io/file file))))
|
||||
_ (when file
|
||||
(let [canonical-path (.getCanonicalPath (io/file file))]
|
||||
(vars/bindRoot sci/file canonical-path)
|
||||
(System/setProperty "babashka.file" canonical-path)))
|
||||
;; TODO: pull more of these values to compile time
|
||||
opts {:aliases aliases
|
||||
:namespaces (-> namespaces
|
||||
|
|
|
|||
6
test-resources/babashka/file_property1.clj
Normal file
6
test-resources/babashka/file_property1.clj
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(ns babashka.file-property1
|
||||
(:require [clojure.java.io :as io]))
|
||||
|
||||
(prn (= *file* (System/getProperty "babashka.file")))
|
||||
|
||||
(load-file (.getPath (io/file "test-resources" "babashka" "file_property2.clj")))
|
||||
3
test-resources/babashka/file_property2.clj
Normal file
3
test-resources/babashka/file_property2.clj
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(ns babashka.file-property2)
|
||||
|
||||
(prn (= *file* (System/getProperty "babashka.file")))
|
||||
|
|
@ -486,11 +486,10 @@
|
|||
(deftest data-diff-test
|
||||
(is (= [[nil 1] [nil 2] [1 nil 2]] (bb nil "(require '[clojure.data :as d]) (d/diff [1 1 2] [1 2 2])"))))
|
||||
|
||||
(deftest version-test
|
||||
(deftest version-property-test
|
||||
(is (= "true\ntrue\nfalse\n"
|
||||
(test-utils/bb nil (.getPath (io/file "test-resources" "babashka" "version.clj"))))))
|
||||
|
||||
|
||||
(defmethod clojure.test/assert-expr 'working? [msg form]
|
||||
(let [body (next form)]
|
||||
`(do ~@body
|
||||
|
|
@ -503,6 +502,12 @@
|
|||
(testing "bb executes the empty expression and doesn't start a REPL"
|
||||
(is (working? (test-utils/bb nil "-e" "")))))
|
||||
|
||||
(deftest file-property-test
|
||||
(is (= "true\nfalse\n"
|
||||
(test-utils/bb nil (.getPath (io/file "test-resources" "babashka" "file_property1.clj")))))
|
||||
(is (= "true\n"
|
||||
(test-utils/bb nil (.getPath (io/file "test-resources" "babashka" "file_property2.clj"))))))
|
||||
|
||||
;;;; Scratch
|
||||
|
||||
(comment
|
||||
|
|
|
|||
Loading…
Reference in a new issue