Fork me on GitHub
#babashka
<
2022-11-21
>
skylize18:11:24

Confusing behavior of dependent tasks that run Clojure. ๐Ÿงต

skylize18:11:39

{...
 :tasks
 {-install-ws {:doc "Ensure ws is installed for koacha-cljs."
               :task ws/-main}

  test-bb {:doc "Run tests using Babashka"
           :requires ([cognitect.test-runner :as runner])
           :task ((apply runner/-main "-d" "test" *command-line-args*))}

  test-clj {:doc "Run tests using Clojure"
            :task (clojure "-M:test:runner" "clj")}

  test-cljs {:doc "Run tests using ClojureScript"
             :depends [-install-ws]
             :task (clojure "-M:test:runner" "cljs")}

  test {:doc "Run all tests"
        :depends [test-clj test-cljs test-bb]}}}
If I run bb test, it runs all 3 test suites in specified order. But if in test/depends I swap the order, to put test-bb first, then any tasks listed after it do not run. Or if I run bb run --parallel test,then again only test-bb runs, exiting long before the JVM has time to start up for the other tasks.

borkdude18:11:19

this is because the test runner calls System/exit probably

skylize19:11:49

Problem is that takes away all the infrastructure around picking test suites to run. But I'm just going to ignore that for now. It's plenty fast enough for this project to just run every BB test every time.

borkdude19:11:10

@U90R0EPHA You can do this:

(merge default-opts (babashka.cli/parse-args *commmand-line-args*))

borkdude19:11:45

I've made a babashka cli wrapper around test-runner here: https://github.com/babashka/cli/blob/main/test/babashka/test_runner.clj

borkdude19:11:20

and then call the api function with:

(exec 'cognitect.test-runner.api)

borkdude19:11:37

and then options on the command line will be parsed accordingly and passed to the API function

borkdude19:11:54

and you can also specify :exec-args as default arguments

borkdude19:11:05

So this basically:

{:tasks {test:bb {:extra-paths ["test"]
                  :extra-deps {io.github.cognitect-labs/test-runner
                               {:git/tag "v0.5.1" :git/sha "dfb30dd"}}
                  :task (exec 'cognitect.test-runner.api/test)
                  :exec-args {:dirs ["test"]}
                  :org.babashka/cli {:coerce {:nses [:symbol]
                                              :vars [:symbol]}}}}}

borkdude19:11:26

and then:

$ bb test:bb --nses foobar foobaz

skylize20:11:00

Great. Got everything working as expected. Thank you

Annaia Danvers20:11:58

Say I have a big repo, with some subfoloders made up of babashka tasks we've written, each in their own subfolder with their own bb.edn. Would it be possible somehow to make a root bb.edn I can expose as a Git dependency, with each of the subfolders as local dependencies? I've attempted to set this up but I found that :local/root/`:local/deps` didn't work because they wouldn't find the bb.edn files. Is this even a good idea, or would I be better just reorganizing things around a single shared bb.edn?

๐Ÿ‘€ 1
borkdude21:11:55

How do people solve this problem with Make?

skylize21:11:57

Is there any special way to call out to a task from a script or from a task function? or should I just shell out to calling bb?

borkdude21:11:43

You can do this:

(babashka.tasks/run 'the-task)

๐Ÿ‘ 1
skylize22:11:42

Trying to use pod-babashka-fswatcher, but every file save triggers 4 duplicate :write events. Is this common and/or expected?

borkdude22:11:52

There is also another one you can try. I've also seen this but as I haven't written the underlying lib, not sure what is the solution

skylize22:11:25

Got pod-babashka-filewatcher working instead.