diff --git a/src/babashka/impl/tasks.clj b/src/babashka/impl/tasks.clj index 48f6e0e2..8e8ecff3 100644 --- a/src/babashka/impl/tasks.clj +++ b/src/babashka/impl/tasks.clj @@ -162,10 +162,11 @@ prog (wrap-depends prog depends parallel?) prog (wrap-def task-name prog parallel? last? log-level) prog (format " -(do (require (quote %s)) -%s)" +(when-not (resolve '%s) (require (quote %s))) +%s" + task (namespace task) - prog)] + prog)] prog) (let [task (pr-str task) prog (wrap-depends task depends parallel?) diff --git a/test-resources/task_scripts/tasks.clj b/test-resources/task_scripts/tasks.clj index 2fadb15d..62457461 100644 --- a/test-resources/task_scripts/tasks.clj +++ b/test-resources/task_scripts/tasks.clj @@ -8,4 +8,5 @@ (defn foo "Foo docstring" - []) + [] + :foo) diff --git a/test/babashka/bb_edn_test.clj b/test/babashka/bb_edn_test.clj index f23487d3..daa17137 100644 --- a/test/babashka/bb_edn_test.clj +++ b/test/babashka/bb_edn_test.clj @@ -98,7 +98,19 @@ (is (= "quux\nbaz\nbar\nfoo\n" (slurp out))))) (testing "map returned from task" (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 (test-utils/with-config {}