Tasks: better error msg for unresolved task

This commit is contained in:
Michiel Borkent 2021-05-02 14:31:57 +02:00
parent 92dde5ce38
commit fb3d24b23c
2 changed files with 15 additions and 3 deletions

View file

@ -288,7 +288,7 @@
(merge extra-deps (:extra-deps task)) (merge extra-deps (:extra-deps task))
(concat requires (:requires task))) (concat requires (:requires task)))
[(binding [*out* *err*] [(binding [*out* *err*]
(println "No such task:" task-name)) 1]) (println "No such task:" t)) 1])
(if-let [task (get tasks t)] (if-let [task (get tasks t)]
(let [prog (str prog "\n" (let [prog (str prog "\n"
(apply str (map deref-task depends)) (apply str (map deref-task depends))
@ -299,7 +299,7 @@
requires (concat requires (:requires task))] requires (concat requires (:requires task))]
[[(format-task init extra-paths extra-deps requires prog)] nil]) [[(format-task init extra-paths extra-deps requires prog)] nil])
[(binding [*out* *err*] [(binding [*out* *err*]
(println "No such task:" task-name)) 1]))))) (println "No such task:" t)) 1])))))
[[(format-task [[(format-task
init init
(:extra-paths task) (:extra-paths task)

View file

@ -158,7 +158,19 @@
(testing "run" (testing "run"
(test-utils/with-config '{:tasks {a (+ 1 2 3) (test-utils/with-config '{:tasks {a (+ 1 2 3)
b (prn (run 'a))}} b (prn (run 'a))}}
(is (= 6 (bb "run" "b")))))) (is (= 6 (bb "run" "b")))))
(testing "no such task"
(test-utils/with-config '{:tasks {a (+ 1 2 3)}}
(is (thrown-with-msg?
Exception #"No such task: b"
(bb "run" "b")))))
(testing "unresolved dependency"
(test-utils/with-config '{:tasks {a (+ 1 2 3)
b {:depends [x]
:task (+ a 4 5 6)}}}
(is (thrown-with-msg?
Exception #"No such task: x"
(bb "run" "b"))))))
(deftest list-tasks-test (deftest list-tasks-test
(test-utils/with-config {} (test-utils/with-config {}