This commit is contained in:
Michiel Borkent 2021-03-20 14:33:44 +01:00
parent ff3d1e56ba
commit 200caef226
2 changed files with 16 additions and 7 deletions

View file

@ -738,12 +738,13 @@ Use -- to separate script command line args from bb command line args.
(let [opts (parse-opts args)]
(if-let [do-opts (:do opts)]
(reduce (fn [prev-exit opts]
(if (and (pos? prev-exit)
(not= [":or-do"] opts))
(reduced prev-exit)
(if (or (= [":and-do"] opts)
(= [":or-do"] opts))
0
(if (pos? prev-exit)
(case opts
[":or-do"] 0
(reduced prev-exit))
(case opts
[":or-do"] (reduced prev-exit) ;; short-cutting
[":and-do"] 0 ;; skipping, returning 0
(exec (parse-opts opts)))))
0
do-opts)

View file

@ -57,7 +57,15 @@
:args [:do :div-by-zero :and-do :sum]}}}
(is (thrown-with-msg? Exception #"Divide"
(bb :all)))))
(testing ":or-do succeeding"
(testing ":or-do short-cutting"
(with-config {:tasks {:sum-1 {:task/type :babashka
:args ["-e" "(+ 1 2 3)"]}
:sum-2 {:task/type :babashka
:args ["-e" "(+ 4 5 6)"]}
:all {:task/type :babashka
:args [:do :sum-1 :or-do :sum-2]}}}
(is (= 6 (bb :all)))))
(testing ":or-do succeeding after failing"
(with-config {:tasks {:div-by-zero {:task/type :babashka
:args ["-e" "(/ 1 0)"]}
:sum {:task/type :babashka