do test
This commit is contained in:
parent
343c363319
commit
612edd6fc9
2 changed files with 159 additions and 142 deletions
|
|
@ -373,7 +373,8 @@ Use -- to separate script command line args from bb command line args.
|
|||
tasks (when (and k bb-edn)
|
||||
(:tasks bb-edn))
|
||||
user-task (when tasks (get tasks k))]
|
||||
(if user-task (resolve-task user-task {:command-line-args (next options)})
|
||||
(if user-task
|
||||
(resolve-task user-task {:command-line-args (next options)})
|
||||
(let [opts (loop [options options
|
||||
opts-map {}]
|
||||
(if options
|
||||
|
|
@ -480,11 +481,10 @@ Use -- to separate script command line args from bb command line args.
|
|||
(assoc opts-map :main (first options))))
|
||||
(":do")
|
||||
(let [options (next options)
|
||||
options (into [] (comp (partition-by #(= % ":--"))
|
||||
(take-nth 2))
|
||||
options)
|
||||
parsed (map parse-opts options)]
|
||||
{:do parsed})
|
||||
options (into [] (comp (partition-by #(or (= % ":and-do")
|
||||
(= % ":or-do"))))
|
||||
options)]
|
||||
{:do options})
|
||||
(":invoke")
|
||||
{:exec-src
|
||||
(pr-str '(if-let [f (requiring-resolve (symbol (first *command-line-args*)))]
|
||||
|
|
@ -737,11 +737,14 @@ Use -- to separate script command line args from bb command line args.
|
|||
(defn main [& args]
|
||||
(let [opts (parse-opts args)]
|
||||
(if-let [do-opts (:do opts)]
|
||||
(reduce (fn [_ opts]
|
||||
(let [ret (exec opts)]
|
||||
(if (pos? ret)
|
||||
(reduced ret)
|
||||
ret)))
|
||||
(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
|
||||
(exec (parse-opts opts)))))
|
||||
0
|
||||
do-opts)
|
||||
(exec opts))))
|
||||
|
|
|
|||
|
|
@ -33,3 +33,17 @@
|
|||
(is (fs/exists? temp-file))
|
||||
(bb :clean)
|
||||
(is (not (fs/exists? temp-file))))))
|
||||
|
||||
(deftest do-task-test
|
||||
(let [temp-dir (fs/create-temp-dir)
|
||||
temp-file (fs/create-file (fs/path temp-dir "temp-file.txt"))]
|
||||
(with-config {:tasks {:clean {:task/type :shell
|
||||
:args ["rm" (str temp-file)]}
|
||||
:sum {:task/type :babashka
|
||||
:args ["-e" "(+ 1 2 3)"]}
|
||||
:all {:task/type :babashka
|
||||
:args [:do :clean :and-do :sum]}}}
|
||||
(is (fs/exists? temp-file))
|
||||
(let [res (bb :all)]
|
||||
(is (= 6 res)))
|
||||
(is (not (fs/exists? temp-file))))))
|
||||
|
|
|
|||
Loading…
Reference in a new issue