diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 0e1ca428..377f1527 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -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) diff --git a/test/babashka/bb_edn_test.clj b/test/babashka/bb_edn_test.clj index 163696e6..ef42fd09 100644 --- a/test/babashka/bb_edn_test.clj +++ b/test/babashka/bb_edn_test.clj @@ -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