Fix #1487: babashka.tasks/clojure with 0 args (#1488)

This commit is contained in:
Michiel Borkent 2023-02-06 22:36:26 +01:00 committed by GitHub
parent a1858774b6
commit 6d1f295f47
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 96 additions and 85 deletions

View file

@ -10,6 +10,7 @@ A preview of the next release can be installed from
## Unreleased ## Unreleased
- [#1000](https://github.com/babashka/babashka/issues/1000): add lib tests for xforms ([@bobisageek](https://github.com/bobisageek)) - [#1000](https://github.com/babashka/babashka/issues/1000): add lib tests for xforms ([@bobisageek](https://github.com/bobisageek))
- [#1482](https://github.com/babashka/babashka/issues/1482): make loading of libs thread safe - [#1482](https://github.com/babashka/babashka/issues/1482): make loading of libs thread safe
- [#1487](https://github.com/babashka/babashka/issues/1487): `babashka.tasks/clojure` should be supported without arguments to start a REPL
## 1.1.173 (2023-02-04) ## 1.1.173 (2023-02-04)

2
fs

@ -1 +1 @@
Subproject commit 4a03880df423a16263bbcd2c24f4ac6c7fb18d25 Subproject commit 9f6b88ba3fb3ee23e753d6558940757eae98cdfe

View file

@ -67,12 +67,14 @@
(apply log-info args) (apply log-info args)
(handle-non-zero (pp/process* {:opts opts :cmd cmd :prev prev}) opts)))) (handle-non-zero (pp/process* {:opts opts :cmd cmd :prev prev}) opts))))
(defn clojure [cmd & args] (defn clojure [& args]
(let [[opts cmd args] (let [[cmd & args] args
[opts cmd args]
(if (map? cmd) (if (map? cmd)
[cmd (first args) (rest args)] [cmd (first args) (rest args)]
[nil cmd args]) [nil cmd args])
cmd (cons cmd args) cmd (cond-> args
cmd (->> (cons cmd)))
local-log-level (:log-level opts)] local-log-level (:log-level opts)]
(sci/binding [log-level (or local-log-level @log-level)] (sci/binding [log-level (or local-log-level @log-level)]
(apply log-info (cons "clojure" cmd)) (apply log-info (cons "clojure" cmd))

View file

@ -308,7 +308,15 @@
(test-utils/with-config (test-utils/with-config
(pr-str '{:tasks {foo (-> (clojure {:out :string} "-J-Dfoo=\"{:port 5555 :accept clojure.core.server/repl}\" -M -e \"(clojure.edn/read-string (System/getProperty (name :foo)))\"") :out clojure.edn/read-string prn)}}) (pr-str '{:tasks {foo (-> (clojure {:out :string} "-J-Dfoo=\"{:port 5555 :accept clojure.core.server/repl}\" -M -e \"(clojure.edn/read-string (System/getProperty (name :foo)))\"") :out clojure.edn/read-string prn)}})
(is (= '{:port 5555, :accept clojure.core.server/repl} (is (= '{:port 5555, :accept clojure.core.server/repl}
(bb "run" "foo")))))) (bb "run" "foo")))))
(testing "can be called without args"
(test-utils/with-config
(pr-str '{:tasks {foo (-> (clojure {:in "(+ 1 2 3)" :out :string}) :out prn)}})
(is (str/includes? (bb "run" "foo") "6")))
;; can't properly test this, but `(clojure)` should work with zero args
#_(test-utils/with-config
(pr-str '{:tasks {foo (-> (clojure) :out prn)}})
(is (str/includes? (test-utils/bb "(+ 1 2 3)" "run" "foo") "6")))))
(deftest list-tasks-test (deftest list-tasks-test
(test-utils/with-config {} (test-utils/with-config {}