Fork me on GitHub
#babashka
<
2023-02-22
>
pesterhazy08:02:09

What's the latest on automated testing in babashka? I started with Cognitect's test runner as per https://blog.michielborkent.nl/babashka-test-runner.html but wanted to hear what people prefer

pesterhazy08:02:35

First, the blog post is great and got me started very quickly (like, in 3min)

pesterhazy08:02:20

It works great. One thing I don't like is that if there's a failure, the program ends with lots of extra noise

----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Test failures or errors occurred.
Data:     {}
Location: /Users/user/.gitlibs/libs/io.github.cognitect-labs/test-runner/7284cda41fb9edc0f3bc6b6185cfb7138fc8a023/src/cognitect/test_runner/api.clj:30:7

----- Context ------------------------------------------------------------------
26:   If neither :nses nor :patterns is supplied, use `:patterns [\".*-test$\"]`."
27:   [opts]
28:   (let [{:keys [fail error]} (do-test opts)]
29:     (when (> (+ fail error) 0)
30:       (throw (ex-info "Test failures or errors occurred." {})))))
          ^--- Test failures or errors occurred.

----- Stack trace --------------------------------------------------------------
cognitect.test-runner.api                      - /Users/user/.gitlibs/libs/io.github.cognitect-labs/test-runner/7284cda41fb9edc0f3bc6b6185cfb7138fc8a023/src/cognitect/test_runner/api.clj:30:7
exec-1e2ea86e-59cc-440b-86a2-56dbd9dc0f35/exec - <expr>:20:1
exec-1e2ea86e-59cc-440b-86a2-56dbd9dc0f35      - <expr>:4:1
user-4ea00c39-b876-47c8-8d44-bfa33f84922e      - <expr>:26:1

pesterhazy08:02:11

For a test runner UX is important - you need to be able to see at a glance what the error is

pesterhazy08:02:48

Of course, cognitect's test runner is only 150 lines of codes or so.... so feel like I almost could copy the code and edit it to my liking

pesterhazy08:02:34

Hm, looking at the code I copied from the blog post, I'm actually calling cognitect.test-runner.api/test, not cognitect.test-runner/-main, which should explain the behavior

pesterhazy08:02:18

OK, so if I replace the snippet in the blog post with

{:paths ["src"]
 :tasks
 {test:bb {:extra-paths ["test"]
           :extra-deps {io.github.cognitect-labs/test-runner
                        {:git/sha "7284cda41fb9edc0f3bc6b6185cfb7138fc8a023"}}
           :task cognitect.test-runner/-main}}}
then I get clean test output with no extra stacktrace 🙂

pesterhazy08:02:09

Might be worth updating the blogpost in case future readers run into this (maybe cognitect.test-runner/-main wasn't supported by bb at the time of writing yet)

borkdude09:02:31

Yes, the "real" cognitect test runner is now compatible with bb

borkdude09:02:59

I think the bb bundled clojure.test could be improved to print the stack trace of the failing test better

pesterhazy12:02:51

Yeah, when I introduce a NullPointerException via (Long/parseLong nil) in my code, the test runner spits out an unreadable stacktrace starting with :type :sci/error, :line 16, :column 7, :message "null" ...

pesterhazy12:02:02

Full stacktrace

pesterhazy12:02:52

AFAICT, the stacktrace contains references to sci only, but not to locations in my code

geraldodev13:02:35

@U06F82LES @borkdude Do you use a watcher to run the tests on file changes ?

borkdude13:02:30

I usually don't, but you can do it using https://github.com/babashka/pod-babashka-fswatcher

👍 2
geraldodev13:02:20

Do you use repl style with bb ?

geraldodev13:02:22

Could you explain why the example watching project.clj returns (deref (promise)) ?

borkdude13:02:21

What example?

borkdude13:02:50

(deref (promise)) is usually done to block execution. If you wouldn't put it there, the script would terminate immediately

geraldodev13:02:58

{:pods {org.babashka/fswatcher {:version "0.0.3"}}
 :tasks {watch {:requires ([pod.babashka.fswatcher :as fw])
                :task (do (fw/watch "project.clj"
                                    (fn [event]
                                      (when (#{:write :write|chmod} (:type event))
                                        (println "hello!"))))
                          (deref (promise)))}}}

geraldodev13:02:44

Very nice embedding spec into bb

pesterhazy14:02:40

@U0516053R I use watchexec --project-origin "$PWD" -w test -w src bb test:bb

pesterhazy14:02:53

which works fine because bb startup is lightning fast

👍 2
sirwobin16:02:47

I've just tried to use the lanterna pod as per https://github.com/babashka/pod-registry/blob/master/examples/lanterna.clj but I get a file not found exception loading the pod. How should I remedy this?

sirwobin16:02:33

Specific error text is:

Downloading pod org.babashka/lanterna (0.0.1-SNAPSHOT)
----- Error --------------------------------------------------------------------
Type:     java.io.FileNotFoundException
Message:  
Location: /home/robin/Videos/./c2.clj:6:1

borkdude16:02:18

Let me fix this by uploading a non-SNAPSHOT...

borkdude19:02:04

I published 0.0.1

sirwobin19:02:18

Just tried with 0.0.1 and it downloaded a 26Mb pod to ~/.babashka but I'm getting a strange IOException 😕

Downloading pod org.babashka/lanterna (0.0.1)
Successfully installed pod org.babashka/lanterna (0.0.1)
----- Error --------------------------------------------------------------------
Type:     java.io.IOException
Message:  Cannot run program "/home/robin/.babashka/pods/repository/org.babashka/lanterna/0.0.1/linux/x86_64/pod-babashka-lanterna": error=2, No such file or directory
Location: /home/robin/Videos/./c2.clj:6:1
This makes no sense because the pod file is there at that location.

sirwobin19:02:54

I copied (load-pod 'org.babashka/lanterna "0.0.1") from your updated example

borkdude19:02:17

what bb version are you on?

borkdude19:02:33

can you do :

ldd /home/robin/.babashka/pods/repository/org.babashka/lanterna/0.0.1/linux/x86_64/pod-babashka-lanterna
and show the output?

borkdude19:02:55

I think it might e a dynamically linked libc problem. I should have gone with static linking but didn't have time to get that in today

sirwobin20:02:06

linux-vdso.so.1 (0x00007ffc660fa000)
	libstdc++.so.6 => not found
	libz.so.1 => not found
	libpthread.so.0 => /nix/store/c35hf8g5b9vksadym9dbjrd6p2y11m8h-glibc-2.35-224/lib/libpthread.so.0 (0x00007fa230c0b000)
	libdl.so.2 => /nix/store/c35hf8g5b9vksadym9dbjrd6p2y11m8h-glibc-2.35-224/lib/libdl.so.2 (0x00007fa230c06000)
	librt.so.1 => /nix/store/c35hf8g5b9vksadym9dbjrd6p2y11m8h-glibc-2.35-224/lib/librt.so.1 (0x00007fa230c01000)
	libc.so.6 => /nix/store/c35hf8g5b9vksadym9dbjrd6p2y11m8h-glibc-2.35-224/lib/libc.so.6 (0x00007fa22edf7000)
	/lib64/ld-linux-x86-64.so.2 => /nix/store/c35hf8g5b9vksadym9dbjrd6p2y11m8h-glibc-2.35-224/lib64/ld-linux-x86-64.so.2 (0x00007fa230c12000)

sirwobin20:02:17

bingo libc++ not found

borkdude20:02:37

are you normally running the statically compiled babashka?

sirwobin20:02:48

It's late. Please go enjoy your evening instead of spending more time on this. 🙂

borkdude20:02:00

ldd $(which bb)
will tell you if you're using the static bb

borkdude20:02:22

oooh, you're on nix :)

sirwobin20:02:33

I'm using the babashka that is packaged for nix (indeed!)

sirwobin20:02:35

it's dynamic

borkdude20:02:18

I can make a static compiled version of this pod tomorrow, but maybe you can get it working by adding libz and libstdc++ in your nix environment... not sure

sirwobin20:02:22

I'll have a play and let you know but please don't spend more time tonight. Thanks for the lanterna pod update and the pointers to missing libs

sirwobin20:02:37

fijne avond

borkdude20:02:58

Try the binary artifact from this build once it's finished: https://app.circleci.com/pipelines/github/babashka/pod-babashka-lanterna/19/workflows/6684fef3-4678-4e4a-8ec0-84c1dad30750/jobs/42 and copy that over the pod that was downloaded. This should work

borkdude21:02:52

I now re-uploaded this binary to the 0.0.1 release. If you do

rm -rf home/robin/.babashka/pods/repository/org.babashka/lanterna
and then try again, it should work. Have a nice evening :)

sirwobin10:02:04

Hi Michiel, thanks for the update. The pod now loads and begins executing but I get an exception in babashka.pods.impl/processor when I make the first call to (terminal/get-terminal). How can I diagnose a No reader function for tag object exception myself? You spent quite a bit of your evening last night and I don't want to be a pain

borkdude10:02:39

No worries :) Are you able to execute console tetris?

bb -Sdeps '{:deps {io.github.borkdude/console-tetris {:git/sha "2d3bee34ea93c84608c7cc5994ae70480b2df54c"}}}' -m tetris.core

sirwobin10:02:15

It required a JDK as well as bb but it started without exceptions. I'm using kitty on linux and it draws fine but the key press commands weren't quite working. That's a lanterna issue not bb though.

sirwobin10:02:32

I'll go check what you've done in tetris and get my script working that way

borkdude10:02:29

> It required a JDK That's only for fetching the dependency

👍 2
borkdude10:02:06

Feel free to provide a repro of your problem. Perhaps an exception is happening on the pod side

sirwobin10:02:48

it's the :resize-listener that chokes. Taking that out of the map to get-terminal gets it working.

borkdude10:02:20

ah yes, I think this is because you can't serialize functions across the pod border

sirwobin10:02:35

such a minor detail. It's not worth fussing about.

sirwobin10:02:58

That makes sense. I don't really need resizing

sirwobin10:02:46

Thanks again for an amazing scripting system and your help last night

🙇 2
borkdude19:02:51

Wanna play console tetris in bb? (mac + linux only for now)

bb -Sdeps '{:deps {io.github.borkdude/console-tetris {:git/sha "2d3bee34ea93c84608c7cc5994ae70480b2df54c"}}}' -m tetris.core

😮 4
🆒 4
borkdude19:02:07

Thanks, I'll have a look

👍 2
borkdude19:02:46

Btw any reason you're not going for a record here? That already gives you equality for free

Jakub Šťastný19:02:16

It has some methods.

Jakub Šťastný19:02:25

With that said it's more of a learning exercise.

Jakub Šťastný19:02:07

As I'm learning Clojure, I want to first implement it in a way I'm used to from OOP and then make it more idiomatic in order to be able to compare the advantages, reasons etc.