Fork me on GitHub
#babashka
<
2023-07-14
>
Stephan Renatus12:07:04

I believe I must be doing something wrong. so -- I’ve got a bunch of tests, laid out like this

.
├── bb.edn
├── test
│   ├── basic
│   │   └── basic_test.clj
│   ├── data-kafka
│   │   └── data_kafka_test.clj
│   ├── sql-send
│   │   └── sql_send_test.clj
each of the test/xyz folders contains some extra files. now to run them via bb run tests , I’ve got a bb.edn of
{:tasks
 {tests {:extra-paths ["test/basic" "test/data-kafka" "test/sql-send" "test/"]
         :extra-deps {io.github.cognitect-labs/test-runner {:git/tag "v0.5.1" :git/sha "dfb30dd"}
                      listora/again {:mvn/version "1.0.0"}}
         :task (exec 'cognitect.test-runner.api/test)
         :exec-args {:dirs ["test"]}
         :org.babashka/cli {:coerce {:nses [:symbol]
                                     :vars [:symbol]}}}}}
and what bugs me is that I seemingly need to list all sub-directories in :extra-paths. but I don’t know where to start cleaning this up. 🧵

2
Stephan Renatus12:07:57

please correct me if I’m wrong here: I provide those paths to extra-paths to > add paths to the classpath and bb will load everything that in the classpath; and the test runner will walk all vars, checking for tests.

Stephan Renatus12:07:50

oh. I could put all the .clj files into test/ and still reference the dirs like I did before and it’ll probably just work. I have to try this.

borkdude12:07:28

you could just add "test" to the extra-paths and adjust your namespace names accordingly

Stephan Renatus12:07:58

so, leave the files where they are? in the subdirs?

Stephan Renatus12:07:11

I think I’m missing some basic thing wrt file names and namespaces.

Bob B12:07:31

the entries in paths should generally be the classpath roots from which namespaces can be resolved - I guess I would see the trade-off as "if I need to keep those test sets separate because I'm going to refer to them separately, then I need the separate dirs; if I'm always going to use all the directories together, then they could presumably be one directory" (and maybe tweak the ns names like borkdude said)

Stephan Renatus12:07:14

what namespace should

test/basic/basic_test.clj
have then?

borkdude12:07:21

If you add test to the extra paths and you have a file like:

test/foo/bar.clj
the namespace name has to be (ns foo.bar)

borkdude12:07:44

so in the case of:

test/basic/basic_test.clj
the ns name should be:
(ns basic.basic-test)

Stephan Renatus12:07:52

thanks! that helps a lot

Stephan Renatus12:07:59

basic seems to work fine, but kondo keeps complaining about

(ns data-kafka.data-kafka-test)
for
test/data-kafka/data_kafka_test.clj

borkdude12:07:07

you need to use an underscore:

test/data_kafka/data_kafka_test.clj

Stephan Renatus12:07:07

> Example trigger: a folder/file containing dashes instead of underscores, example: example-namespace/foo.clj containing a namespace (ns example-namespace.foo).

Stephan Renatus12:07:17

yep! thanks again

Stephan Renatus13:07:49

and it all works thank you so much

🎉 2
richiardiandrea16:07:51

I there, I had the following in a bb.edn (shell "bb" uberjar (str uber-file) "-f" script-path "-m" (str main-sym)) This now v1.3.181 throws

----- Error --------------------------------------------------------------------
Type:     java.lang.Exception
Message:  File does not exist: -f
Did I miss a breaking change?

richiardiandrea16:07:33

I don't see -f anymore to uberjar

richiardiandrea16:07:21

well it probably has never been there but now it actually is not only ignored but bb fails properly (maybe)

borkdude17:07:28

Hmm, I think this is a regression

richiardiandrea17:07:54

Oh ok, I am going to open an issue on GitHub then

richiardiandrea17:07:09

@U04V15CAJ Sorry, I might not remember this properly but what was the original purpose of -f ? I might want to remove it cause I see all the namespaces in the produced jar

borkdude17:07:34

if it works without it, then that's fine I guess

borkdude17:07:57

normally -f is used to start bb with a script, but you can leave out -f

borkdude17:07:04

bb script.clj bb -f script.clj same thing

👍 2
richiardiandrea17:07:25

cause it is not in the eval-opts - so I was now thinking that it is correct that it fails

borkdude17:07:45

there was a change around -f recently which had to do with running scripts with an adjacent bb.edn file.

borkdude17:07:55

and this is likely where the difference comes from

👍 2
richiardiandrea17:07:28

I honestly don't see it used [here](https://github.com/babashka/babashka/blob/94c5141a3eda7e07ed2efa40c11efe3d4c13a297/src/babashka/main.clj#L1088-L1101) so probably this behavior is breaking but correct and my script was wrong

borkdude17:07:39

ok good to know :)

❤️ 2