Tasks: fix execution of fully qualified symbol

This commit is contained in:
Michiel Borkent 2021-04-25 11:42:11 +02:00
parent 647ef40250
commit 21bb768e9f
3 changed files with 19 additions and 5 deletions

View file

@ -162,10 +162,11 @@
prog (wrap-depends prog depends parallel?) prog (wrap-depends prog depends parallel?)
prog (wrap-def task-name prog parallel? last? log-level) prog (wrap-def task-name prog parallel? last? log-level)
prog (format " prog (format "
(do (require (quote %s)) (when-not (resolve '%s) (require (quote %s)))
%s)" %s"
task
(namespace task) (namespace task)
prog)] prog)]
prog) prog)
(let [task (pr-str task) (let [task (pr-str task)
prog (wrap-depends task depends parallel?) prog (wrap-depends task depends parallel?)

View file

@ -8,4 +8,5 @@
(defn foo (defn foo
"Foo docstring" "Foo docstring"
[]) []
:foo)

View file

@ -98,7 +98,19 @@
(is (= "quux\nbaz\nbar\nfoo\n" (slurp out))))) (is (= "quux\nbaz\nbar\nfoo\n" (slurp out)))))
(testing "map returned from task" (testing "map returned from task"
(test-utils/with-config '{:tasks {foo {:task {:a 1 :b 2}}}} (test-utils/with-config '{:tasks {foo {:task {:a 1 :b 2}}}}
(is (= {:a 1 :b 2} (bb "foo"))))))) (is (= {:a 1 :b 2} (bb "foo")))))
(testing "fully qualified symbol execution"
(test-utils/with-config {:paths ["test-resources/task_scripts"]
:tasks '{foo tasks/foo}}
(is (= :foo (bb "foo"))))
(test-utils/with-config {:paths ["test-resources/task_scripts"]
:tasks '{:requires ([tasks :as t])
foo t/foo}}
(is (= :foo (bb "foo"))))
(test-utils/with-config {:paths ["test-resources/task_scripts"]
:tasks '{foo {:requires ([tasks :as t])
:task t/foo}}}
(is (= :foo (bb "foo")))))))
(deftest list-tasks-test (deftest list-tasks-test
(test-utils/with-config {} (test-utils/with-config {}