Fork me on GitHub
#babashka
<
2021-01-23
>
Marco Pas07:01:48

Question about running tests again 🙂

.
├── run-test.sh
├── src
│   └── cap
└── test
    └── cap
        ├── test_a.clj
        └── test_b.clj
#test_a.clj
(ns cap.test-a (:require [clojure.test :as t :refer [deftest, is]]))

(deftest test-simple-pass
  (is (= 2 (+ 1 1))))
#test_b.clj
(ns cap.test-b (:require [clojure.test :as t :refer [deftest, is]]))

(deftest test-simple-fail
  (is (= 3 (+ 1 1))))
I can run a single test file with the recipe like:
#!/usr/bin/env bash
bb -cp "src:test:resources" \
   -e "(require '[clojure.test :as t] '[cap.test-a])
       (let [{:keys [:fail :error]} (t/run-tests 'cap.test-a)]
         (System/exit (+ fail error)))"
But how can i run all tests? Also the tests from test_b.clj

borkdude08:01:07

@marco.pasopas you should also require the b namespace and you can use run-all-tests from Clojure.test

Marco Pas08:01:43

@borkdude something like this??

#!/usr/bin/env bash
bb -cp "src:test:resources" \
   -e "(require '[clojure.test :as t] '[cap.test-a] '[cap.test-b])
       (let [{:keys [:fail :error]} (t/run-all-tests)]
         (System/exit (+ fail error)))"
This also runs the tests like
Testing cap.test-a
Testing bencode.core
Testing clj-yaml.core
Testing clojure.java.browse

Marco Pas08:01:07

Would it be more idiomatic to create somekind of test runner namespace or something?

borkdude08:01:33

Yes, you can just add the name to run-tests. You can add multiple namespaces there. I updated the book to make this a test runner script instead of a command line expression

👍 3
borkdude08:01:32

I’ll update it with multiple namespaces and also with add-classpath

👍 6
Felipe Marques16:01:16

Awesome! I was just going to add tests to the internal CLI of the company that I work for. Btw, do you have any suggestion for easy mocking in Babashaka for tests? I've being using match which gives me a easy way to mach cases for sh calls like this:

(match args
             ["aws" "s3" "cp" "" _] (spit (nth args 4) new-features-config)
             ["aws" "s3" "cp" _ ""] nil
             ["rm" _] (io/delete-file (second args))
             :else (throw (ex-info "unexpected sh call: " args)))))
But as I'm not sure this will work on babashka, I'm running the tests in Clojure

borkdude16:01:00

@URUTKFS0H is this core.match?

borkdude16:01:14

core.match is now merged to master

❤️ 3
borkdude16:01:29

will be included in the next release

❤️ 3
Felipe Marques16:01:50

wow! awesome! thanks!

borkdude16:01:23

you can already try it out by downloading a binary from the builds

👍 3
borkdude21:01:19

@URUTKFS0H now released as 0.2.8

Felipe Marques23:01:57

Just set up the test runner and the CI using babashka 0.2.8! It worked great including the tests with core.match! Thanks!

🎉 3
Marco Pas08:01:03

Apologies for asking dumb questions 🙂 , still need to get used to the Clojure / BB ecosystem

borkdude08:01:26

No problem!

borkdude13:01:41

I am looking into including hiccup in babashka for static site generation, but the standard hiccup library doesn't work with GraalVM, since it's based on ... eval 😲

😮 3
4
polymeris13:01:06

Does anyone know of a less "minimal" babashka docker image to use in CI (one that includes e.g. git)

borkdude13:01:06

@polymeris There is now a babashka/babashka image and also a babashka-alpine image. The first one is based on ubuntu and the second one on alpine. Both come with curl (for babashka.curl) but nothing more than that. Just derive another image from it.

👍 3
❤️ 3
Jakub Holý (HolyJak)14:01:26

Where can I download a pre-built sql pod binary?

borkdude14:01:43

@holyjak do you mean the oracle one?

✔️ 3
borkdude14:01:47

Do you mean, for third parties, other than you?

Jakub Holý (HolyJak)14:01:54

No, for me. I supposed that once merged, a binary for each DB and linux/Mac is built and published somewhere. Or do I always need to build pods myself? (for Linux)

borkdude14:01:22

But it seems their site is under maintenance 😠

borkdude14:01:35

Btw, I now see only 4 jobs, the postgres jobs disappeared?

Jakub Holý (HolyJak)15:01:56

(I want to include it in my aws lambda on Monday and would be happy not to need adding a build stage for it)

borkdude15:01:49

I get that. We can distribute it on the pod registry, but I need to know absolutely sure we are not offending any licenses

👍 3
Jakub Holý (HolyJak)15:01:05

Will verify the license

Jakub Holý (HolyJak)16:01:46

I hate Oracle. I will need to try to check this with our legal department. Signals from the internet are ambiguous.

borkdude16:01:45

so which license has the helidon driver?

Jakub Holý (HolyJak)16:01:05

Helidon itself has Apache but their driver is literally wrapped ojdbc + reflection json

borkdude16:01:17

Maybe post an issue on the Helidon issue tracker to ask how this should be considered?

👍 3
borkdude16:01:45

As for the pod-registry, I will not distribute it in case of doubt, don't want the legal department of Oracle on my back

💯 3
borkdude16:01:21

So you could maybe build it yourself locally and send it along with your AWS Lambda image

👍 3
Jakub Holý (HolyJak)21:01:32

Thank you very much!

borkdude22:01:27

@holyjak One issue, I think the postgres jobs now disappeared

borkdude22:01:54

hmm, no sorry. they are there

borkdude22:01:26

it was a UI glitch, all good!

borkdude14:01:30

Ah, found the issue with hiccup. You have to take care to not map the html macro inside the sci interpreter, but a function, wrapping the macro call, to avoid hiccup to go into "compilation" mode which uses eval 😅

👍 3
lread15:01:10

Was that a sci of relief I just heard? 🙂

😎 6
Bret Horne21:01:04

Is there a way to interactively develop something with the lanterna pod? This fork doesnt make use of the swing terminal so I was wondering what others have done. (Just remembered that prepl exists so will look further into that)

borkdude21:01:25

@bret.horne I read that GraalVM 21 has support now for Swing on linux (https://medium.com/graalvm/graalvm-21-0-introducing-a-new-way-to-run-java-df894256de28) but it's experimental, this is why the lanterna pod doesn't have Swing yet. As for interactive development, there is a socket REPL, pREPL and nREPL in bb

Bret Horne21:01:52

Also, thank you for your work on this btw. I love being able to run clojure in production now for tooling 🙂

❤️ 3
Bret Horne21:01:40

I tried using nrepl first and connecting to that way, in emacs via cider-connect, but im not entirely sure how its supposed to work. The terminal seems to blend in with the repl and I lose all connection to it despite shutting down the terminal.

borkdude21:01:09

ah that's tricky, yeah, not sure

borkdude21:01:44

fwiw, a lot of the times, I just re-run the scripts I'm developing until it works, since the startup is so fast, the difference with a REPL isn't that big

Bret Horne21:01:45

true. I tried using your clojure-lanterna fork directly and using javac to compile it as im not a lein user but use clj instead.

Bret Horne21:01:33

so Ill continue down that path to run it on the jvm.

borkdude21:01:33

yeah, that's also an option

Bret Horne21:01:45

nrepl > /dev/tty seems to work well enough