Fix bug in topological sorting
This commit is contained in:
parent
cf55681114
commit
0ae56e7098
3 changed files with 24 additions and 5 deletions
|
|
@ -85,11 +85,12 @@
|
||||||
(let [task (tasks task-name)
|
(let [task (tasks task-name)
|
||||||
depends (:depends task)]
|
depends (:depends task)]
|
||||||
(loop [deps (seq depends)]
|
(loop [deps (seq depends)]
|
||||||
(let [p @processed
|
(let [deps (remove #(contains? @processed %) deps)
|
||||||
deps (remove #(contains? p %) deps)
|
|
||||||
order (vec (mapcat #(target-order tasks % processed) deps))]
|
order (vec (mapcat #(target-order tasks % processed) deps))]
|
||||||
(vswap! processed conj task-name)
|
(if-not (contains? @processed task-name)
|
||||||
(conj order task-name))))))
|
(do (vswap! processed conj task-name)
|
||||||
|
(conj order task-name))
|
||||||
|
order))))))
|
||||||
|
|
||||||
(defn assemble-task [task-name]
|
(defn assemble-task [task-name]
|
||||||
(let [task-name (symbol task-name)
|
(let [task-name (symbol task-name)
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,15 @@
|
||||||
(test-utils/with-config {:tasks {'foo (list 'shell {:out out}
|
(test-utils/with-config {:tasks {'foo (list 'shell {:out out}
|
||||||
"echo hello")}}
|
"echo hello")}}
|
||||||
(bb "foo")
|
(bb "foo")
|
||||||
(is (= "hello\n" (slurp out))))))
|
(is (= "hello\n" (slurp out))))
|
||||||
|
(test-utils/with-config {:tasks {'quux (list 'spit out "quux\n")
|
||||||
|
'baz (list 'spit out "baz\n" :append true)
|
||||||
|
'bar {:depends ['baz]
|
||||||
|
:task (list 'spit out "bar\n" :append true)}
|
||||||
|
'foo {:depends ['quux 'bar 'baz]
|
||||||
|
:task (list 'spit out "foo\n" :append true)}}}
|
||||||
|
(bb "foo")
|
||||||
|
(is (= "quux\nbaz\nbar\nfoo\n" (slurp out))))))
|
||||||
|
|
||||||
;; TODO:
|
;; TODO:
|
||||||
;; Do we want to support the same parsing as the clj CLI?
|
;; Do we want to support the same parsing as the clj CLI?
|
||||||
|
|
|
||||||
10
test/babashka/impl/tasks_test.clj
Normal file
10
test/babashka/impl/tasks_test.clj
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
(ns babashka.impl.tasks-test
|
||||||
|
(:require [babashka.impl.tasks :as sut]
|
||||||
|
[clojure.test :as t]))
|
||||||
|
|
||||||
|
(t/deftest target-order-test
|
||||||
|
(t/is (= '[quux bar foo]
|
||||||
|
(sut/target-order
|
||||||
|
{'foo {:depends ['bar 'quux]}
|
||||||
|
'bar {:depends ['quux]}}
|
||||||
|
'foo))))
|
||||||
Loading…
Reference in a new issue