metosin / bat-test

Fast Clojure.test runner for Boot and Leiningen
61 stars 10 forks source link

REPL+CLI support #44

Closed frenchy64 closed 2 years ago

frenchy64 commented 2 years ago

Close #21 Close #31

This exposes most of bat-test via the REPL or Clojure CLI.

There is an extra feature called :test-matcher-directories which only runs tests in particular directories. This is especially useful for huge projects that are split into many source directories, so you can easily boot up a watching tester for a subproject.

It's implemented as a sugar for :test-matcher.

The Actions build can be seen passing here.

Deraen commented 2 years ago

Oh, I didn't remember bat-test didn't have a main ns at all for Clojure CLI yet.

Is :exec-fn prefered over ns -main function now?

I'll want to ensure the lein version works as close as possible as this, so it would make sense to implement test-matcher-directories in the impl ns so it can be shared by both frontends.

frenchy64 commented 2 years ago

Is :exec-fn prefered over ns -main function now?

It's hard to tell exactly, but Cognitect's test-runner seems to be encouraging exec. https://github.com/cognitect-labs/test-runner

I'll want to ensure the lein version works as close as possible as this, so it would make sense to implement test-matcher-directories in the impl ns so it can be shared by both frontends.

Will do.

frenchy64 commented 2 years ago

Looking into providing a kv interface via Lein, eg., lein bat-test :watch true for full feature parity.

frenchy64 commented 2 years ago

My implementation of Leiningen test selectors is wrong, I need to go back to the drawing board.

frenchy64 commented 2 years ago

I added a separator for lein bat-test so you can provide selectors/namespaces in both styles.

lein bat-test foo.ns : :parallel? true
;; same as
lein bat-test : :selectors '[foo.ns]' :parallel? true

I really like this interface, saves a lot of typing. I'll try and port it to Clojure CLI with -M.

Deraen commented 2 years ago

Hi, what is the status now?

I see some problems with the Lein implementation, as the Lein namespace is using cli namespace directly, which requires c.t.namespace, which probably isn't available on Lein boot classpath.

I can probably fix those problems if the cli interface and the selectors work with Lein otherwise.

frenchy64 commented 2 years ago

@Deraen I was thinking of one extra feature, but was having trouble implementing it. I think this PR is good enough to start with though, if you could fix the dependency issues for me that would be great. Then it's good to merge.

Here's the idea for an extra feature:

lein bat-test ./my-dir watching tests in my-dir. Distinguished from lein bat-test my-dir because it starts with ..

You could then alternatively do cd my-dir && lein bat-test ..

Deraen commented 2 years ago

@frenchy64 I tried fixing the cli namespace uses from the Lein plugin code but wasn't successful.

Another problem is that the bat-test artifact is currently supposed to be used as a Lein or Boot plugin so that it won't have any dependencies and instead depends on the tool to add the dependencies vs. clj.

What would you think about just taking the CLI part and releasing that as a new project? I believe using the main namespace with Lein is becoming a popular way to support multiple tools (e.g., Kaocha and Figwheel-main).

frenchy64 commented 2 years ago

Thanks for trying, I have no problem with making a new project!