From fb3d24b23c49e9c5c1abfb00c87e17c503f14167 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Sun, 2 May 2021 14:31:57 +0200 Subject: [PATCH] Tasks: better error msg for unresolved task --- src/babashka/impl/tasks.clj | 4 ++-- test/babashka/bb_edn_test.clj | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/babashka/impl/tasks.clj b/src/babashka/impl/tasks.clj index 758fbadc..7cad019f 100644 --- a/src/babashka/impl/tasks.clj +++ b/src/babashka/impl/tasks.clj @@ -288,7 +288,7 @@ (merge extra-deps (:extra-deps task)) (concat requires (:requires task))) [(binding [*out* *err*] - (println "No such task:" task-name)) 1]) + (println "No such task:" t)) 1]) (if-let [task (get tasks t)] (let [prog (str prog "\n" (apply str (map deref-task depends)) @@ -299,7 +299,7 @@ requires (concat requires (:requires task))] [[(format-task init extra-paths extra-deps requires prog)] nil]) [(binding [*out* *err*] - (println "No such task:" task-name)) 1]))))) + (println "No such task:" t)) 1]))))) [[(format-task init (:extra-paths task) diff --git a/test/babashka/bb_edn_test.clj b/test/babashka/bb_edn_test.clj index 17d1906e..0f9e24c2 100644 --- a/test/babashka/bb_edn_test.clj +++ b/test/babashka/bb_edn_test.clj @@ -158,7 +158,19 @@ (testing "run" (test-utils/with-config '{:tasks {a (+ 1 2 3) 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 (test-utils/with-config {}