This commit is contained in:
Michiel Borkent 2021-03-20 14:47:04 +01:00
parent 200caef226
commit 5b9e3c3267
2 changed files with 23 additions and 4 deletions

View file

@ -481,7 +481,9 @@ Use -- to separate script command line args from bb command line args.
(assoc opts-map :main (first options)))) (assoc opts-map :main (first options))))
(":do") (":do")
(let [options (next options) (let [options (next options)
options (into [] (comp (partition-by #(or (= % ":and-do") options (into [] (comp (partition-by #(or
(= % ":do")
(= % ":and-do")
(= % ":or-do")))) (= % ":or-do"))))
options)] options)]
{:do options}) {:do options})
@ -738,13 +740,15 @@ Use -- to separate script command line args from bb command line args.
(let [opts (parse-opts args)] (let [opts (parse-opts args)]
(if-let [do-opts (:do opts)] (if-let [do-opts (:do opts)]
(reduce (fn [prev-exit opts] (reduce (fn [prev-exit opts]
;; (prn :prev prev-exit)
;; (prn :opts opts)
(if (pos? prev-exit) (if (pos? prev-exit)
(case opts (case opts
[":or-do"] 0 ([":do"] [":or-do"]) 0 ;; skipping, returning 0
(reduced prev-exit)) (reduced prev-exit))
(case opts (case opts
[":or-do"] (reduced prev-exit) ;; short-cutting [":or-do"] (reduced prev-exit) ;; short-cutting
[":and-do"] 0 ;; skipping, returning 0 ([":do"] [":and-do"]) 0 ;; skipping, returning 0
(exec (parse-opts opts))))) (exec (parse-opts opts)))))
0 0
do-opts) do-opts)

View file

@ -48,6 +48,21 @@
(let [res (bb :all)] (let [res (bb :all)]
(is (= 6 res))) (is (= 6 res)))
(is (not (fs/exists? temp-file)))))) (is (not (fs/exists? temp-file))))))
(testing ":do always continuing"
(with-config {:tasks {:sum-1 {:task/type :babashka
:args ["-e" "(do (+ 4 5 6) nil)"]}
:sum-2 {:task/type :babashka
:args ["-e" "(+ 1 2 3)"]}
:all {:task/type :babashka
:args [:do :sum-1 :do :sum-2]}}}
(is (= 6 (bb :all))))
(with-config {:tasks {:div-by-zero {:task/type :babashka
:args ["-e" "(/ 1 0)"]}
:sum {:task/type :babashka
:args ["-e" "(+ 1 2 3)"]}
:all {:task/type :babashka
:args [:do :div-by-zero :do :sum]}}}
(is (= 6 (bb :all)))))
(testing ":and-do failing" (testing ":and-do failing"
(with-config {:tasks {:div-by-zero {:task/type :babashka (with-config {:tasks {:div-by-zero {:task/type :babashka
:args ["-e" "(/ 1 0)"]} :args ["-e" "(/ 1 0)"]}