From 36abd4152a3064d02c58a369233e88618c964f7b Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Sat, 10 Apr 2021 16:07:06 +0200 Subject: [PATCH] List tasks test --- src/babashka/impl/tasks.clj | 21 ++++++++++----------- test/babashka/bb_edn_test.clj | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/babashka/impl/tasks.clj b/src/babashka/impl/tasks.clj index 27d04d66..e0b3cc64 100644 --- a/src/babashka/impl/tasks.clj +++ b/src/babashka/impl/tasks.clj @@ -122,20 +122,19 @@ (let [names (keys tasks) raw-names (filter symbol? names) names (map str raw-names) - names (sort names) + names (remove #(str/starts-with? % "-") names) + names (remove #(:private (get tasks (symbol %))) names) longest (apply max (map count names)) fmt (str "%1$-" longest "s")] (println "The following tasks are available:") (println) - (doseq [k raw-names - :let [task (get tasks k)]] - (when-not (or (str/starts-with? k "-") - (:private task)) - (let [task (if (qualified-symbol? task) - {:doc (format "Runs %s. See `bb doc %s` for more info." task task)} - task)] - (println (str (format fmt k) - (when-let [d (:doc task)] - (str " " d)))))))) + (doseq [k names + :let [task (get tasks (symbol k))]] + (let [task (if (qualified-symbol? task) + {:doc (format "Runs %s. See `bb doc %s` for more info." task task)} + task)] + (println (str (format fmt k) + (when-let [d (:doc task)] + (str " " d))))))) (println "No tasks found.")))) diff --git a/test/babashka/bb_edn_test.clj b/test/babashka/bb_edn_test.clj index 2dfa6400..6affb2b1 100644 --- a/test/babashka/bb_edn_test.clj +++ b/test/babashka/bb_edn_test.clj @@ -51,6 +51,28 @@ (bb "foo") (is (= "quux\nbaz\nbar\nfoo\n" (slurp out)))))) +(deftest list-tasks-test + (test-utils/with-config {} + (let [res (test-utils/bb nil "tasks")] + (is (str/includes? res "No tasks found.")))) + (test-utils/with-config {:tasks {'task1 + {:doc "task1 doc" + :task '(+ 1 2 3)} + 'task2 + {:doc "task2 doc" + :task '(+ 4 5 6)} + '-task3 + {:task '(+ 1 2 3)} + 'task4 + {:task '(+ 1 2 3) + :private true}}} + (let [res (test-utils/bb nil "tasks")] + (is (str/includes? res "The following tasks are available:")) + (is (str/includes? res "task1 task1 doc")) + (is (str/includes? res "task2 task2 doc")) + (is (not (str/includes? res "task3"))) + (is (not (str/includes? res "task4")))))) + ;; TODO: ;; Do we want to support the same parsing as the clj CLI? ;; Or do we want `--aliases :foo:bar`