Q about exec in a bb task: it looks like (exec 'cognitect.test-runner.api/test) will "exec" (as in clojure -X) that function, and it will do so via Babashka itself (so, testing bb compatibility). Is there a way to invoke a test runner's -main and pass string arguments -- and still have it run inside Babashka?
Context: I want to be able to run LazyTest via Babashka and it doesn't have an "exec" API, only -main, so I need to invoke it with lazytest.main/-main but pass an empty sequence of strings.
I’ll answer in a few hours if nobody has answered your question yet
So Sean, you want to run your tests not only from bb but in bb (and not run them under the clojure JVM)?
Maybe this will help, from babashka.process bb tasks a https://github.com/babashka/process/blob/35760b076eaad176a61a575b58685c3d3e475d6f/bb.edn#L73-L75 that ends up calling the test runner https://github.com/babashka/process/blob/35760b076eaad176a61a575b58685c3d3e475d6f/bb.edn#L49.
@seancorfield You can execute a main function like any other function:
(lazytest.main/-main)
?@lee shouldn't cognitect.test-runner.-main be cognitect.test-runner/-main in that bb.edn? 🤔
@seancorfield a shortcut for executing a main function with command line argument in bb tasks is:
{:task foo.bar/-main}
it doesn't require any additional :requiresI do a ton of this in https://github.com/clj-commons/rewrite-clj/blob/b8a2a670ee0124033093f63ffd9b8cba03701b29/bb.edn#L18-L43
Yeah. That's weird @borkdude:
$ bb repl
Babashka v1.12.206 REPL.
Use :repl/quit or :repl/exit to quit the REPL.
Clojure rocks, Bash reaches.
user=> (apply clojure.core.+ [1 2 3])
6
JVM repl:
Clojure 1.12.1
user=> (apply clojure.core.+ [1 2 3])
Syntax error (ClassNotFoundException) compiling at (REPL:1:1).
clojure.core.+
Maybe a sci-ism?@lee weird!
I think it may have to do with resolving vars as classes or something, since types likes records and deftypes in SCI are really vars (so far) and people sometimes refer to those by "class" name
anyway, better to not rely on that
might change in next version
yep. I'll do a quick fix of the typo in bb process.
Oh... gosh, that's simpler than I imagined! Duh!
Hey, you helped us stumble on an interesting weirdness, so it was all worth it! simple_smile
Okay, I now have a branch of deps-new that you can add :build :bb when you create a new app project and the result will have a simpler build.clj and will now have a bb.edn for running tasks including tests. And you can choose a :test-runner of :lazytest (as opposed to Cognitect's test runner) and that also works with Babashka!
Now I just need to update the other templates the same way 🙂
and on top of that, deps-new itself also works with bb :)
So, calling a main function like this:
{:task foo.bar/-main}
isn't so great when -main calls System/exit since it happens in-process and stops the bb pipeline. Took me a while to figure out why my :depends was running but the actual :task was not -- I was depending on a task that ran -main in-process and exited 😞 So I've gone back to exec and figured out an entry point in LazyTest that works that way.If folks would like to try the :build :bb option in deps-new before I formally cut a v0.10.0 release, I'd appreciate that:
clojure -Ttools install io.github.seancorfield/deps-new '{:git/sha "20e82f8c27b890d03ce71665e07a0f0936a1c3bf"}' :as new
clojure -Tnew app :name myuser/myapp :build :bb