List tasks test
This commit is contained in:
parent
0ae56e7098
commit
36abd4152a
2 changed files with 32 additions and 11 deletions
|
|
@ -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."))))
|
||||
|
||||
|
|
|
|||
|
|
@ -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`
|
||||
|
|
|
|||
Loading…
Reference in a new issue