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 (when (and k bb-edn)
|
||||||
(:tasks bb-edn))
|
(:tasks bb-edn))
|
||||||
user-task (when tasks (get tasks k))]
|
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
|
(let [opts (loop [options options
|
||||||
opts-map {}]
|
opts-map {}]
|
||||||
(if options
|
(if options
|
||||||
|
|
@ -480,11 +481,10 @@ 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 #(= % ":--"))
|
options (into [] (comp (partition-by #(or (= % ":and-do")
|
||||||
(take-nth 2))
|
(= % ":or-do"))))
|
||||||
options)
|
options)]
|
||||||
parsed (map parse-opts options)]
|
{:do options})
|
||||||
{:do parsed})
|
|
||||||
(":invoke")
|
(":invoke")
|
||||||
{:exec-src
|
{:exec-src
|
||||||
(pr-str '(if-let [f (requiring-resolve (symbol (first *command-line-args*)))]
|
(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]
|
(defn main [& 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 [_ opts]
|
(reduce (fn [prev-exit opts]
|
||||||
(let [ret (exec opts)]
|
(if (and (pos? prev-exit)
|
||||||
(if (pos? ret)
|
(not= [":or-do"] opts))
|
||||||
(reduced ret)
|
(reduced prev-exit)
|
||||||
ret)))
|
(if (or (= [":and-do"] opts)
|
||||||
|
(= [":or-do"] opts))
|
||||||
|
0
|
||||||
|
(exec (parse-opts opts)))))
|
||||||
0
|
0
|
||||||
do-opts)
|
do-opts)
|
||||||
(exec opts))))
|
(exec opts))))
|
||||||
|
|
|
||||||
|
|
@ -33,3 +33,17 @@
|
||||||
(is (fs/exists? temp-file))
|
(is (fs/exists? temp-file))
|
||||||
(bb :clean)
|
(bb :clean)
|
||||||
(is (not (fs/exists? temp-file))))))
|
(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