Fork me on GitHub
#announcements
<
2023-11-16
>
Ela Nazari12:11:31

Xiana framework released a new version with swagger-ui available. https://github.com/Flexiana/framework

馃帀 3
jpmonettas13:11:57

Hi everybody! The https://github.com/flow-storm is happy to announce the first release of Clofidence, a test coverage tool for Clojure! https://github.com/flow-storm/clofidence The readme contains setup instructions and more. As an example find in the thread the test coverage report for the ClojureScript compiler tests for version 1.11.60 if you want to have a sense of what Clofidence is capable of. As usual feedback is welcome.

馃帀 27
awesome 8
馃憦 5
cljs 3
clj 4
2
Ben Sless13:11:49

What are the chances to emit reports in cobertura's format? https://cobertura.github.io/cobertura/

jpmonettas13:11:36

I never used that tool, is there a place to see what that format is about?

Ben Sless13:11:25

For some arcane reason gitlab CI can process coverage reports in that format, and only that format

jpmonettas13:11:50

do you have link to an example of a cobertura xml file? couldn't find one

imre14:11:09

Interesting! Two questions: 1. How does this compare to cloverage? 2. Is there a way to use this with the kaocha test runner?

Ben Sless14:11:41

I'm looking for examples, I remember there was a spec somewhere but obviously I can't find it now

jpmonettas14:11:51

@U08BJGV6E For 1. tbh I can't compare it with Cloverage because when I tried it on my projects it crashed with methods being too large to instrument, and I couldn't get any reports. So I'm not sure of what the Cloverage reports looks like. If you have some at hand to share, we can maybe compare. For 2. If you can run the tests by calling a function it should work. I guess the kaocha runner is just a function call with maybe some parameters, so I haven't try it but shouldn't be any problems.

imre14:11:04

Thank you, that's interesting - one problem we're having with Cloverage is exactly the method too large one

imre15:11:25

:exec-args {:report-name "my-app"
                            :test-fn kaocha.runner/exec-fn
                            :test-fn-args [{}]}
for anyone wondering Edit: doesn't work as exec-fn does a System/exit at the end

jpmonettas15:11:26

Clofidence can also hit the same issue, like any other instrumentation system since there is a limit on how big a JVM method can be, but since it is instrumenting at the compiler level I think the extra bytecode is as tight as it can. Also if it hits a method too large exception it will notify on the console and continue with the function uninstrumented

imre15:11:34

I just managed to hit that yes. With cloverage I have around 16 such methods, with clofidence I got notified about 2

jpmonettas15:11:31

@U08BJGV6E is there a way to make Cloverage work in those situations? last time I tried it was just crashing

imre15:11:08

For us it logs non-fatal errors to the console, somewhat less gracefully than clofidence, but it goes on and produces a report. It doesn't however state (unline clofidence) how it proceeds with the un-instrumentable form so that's a bit of an unknown to us at the moment, but tests results don't change between no instrumentation/instrumentation with said errors/instrumentation with exclusions set up for the difficult forms.

imre15:11:16

Right now we maintain a list of exclusions just so we are in better control of what happens

馃憤 1
imre15:11:28

tests seem to take a lot more time with clofidence than cloverage, at least in our case

jpmonettas15:11:51

Yeah, so I was able to run Cloverage on one of my projects and since you asked for differences, one I see is that Cloverage seems line based, while Clofidence is expression based, maybe that is why. Also I haven't done any perf passes yet

jpmonettas15:11:39

I'm not sure how Cloverage reports when you have a bunch of expressions on the same line but only some of them executed

imre15:11:51

Cloverage's output (at least in our case) has both form- and line based data

imre15:11:12

here's a sample

imre15:11:45

But I don't know any of its internals so wouldn't be able to comment on the tech differences

jpmonettas15:11:29

but I mean like this

jpmonettas15:11:52

here you can see that normalize-gensyms branch wasn't take

jpmonettas15:11:55

oh, I see that is has splited it in multiple lines, not sure if it always does that

imre15:11:02

Not sure about that

imre15:11:07

Okay, looks like my first kaocha approach didn't work as exec-fn does a system/exit at the very end so I end up with no coverage report 馃槢

jpmonettas16:11:08

same happened to me when I ran the ClojureScript tests, there was a System/exit as the last step, had to run all over again facepalm

imre16:11:13

probably need a kaocha plugin to make that work as kaocha likes to be on the outside https://github.com/lambdaisland/kaocha-cloverage/blob/main/src/kaocha/plugin/cloverage.clj

馃憤 2
jpmonettas16:11:11

yeah, there lots of things to work on, stuff like that, and also there is room for many features. Another nice thing is the entire project is like 200 LOC, with another 200 I copied from FlowStorm to pprint the forms that I'll be moving to a lib soon

imre16:11:14

I have managed to do kaocha inside the polylith test runner but it took sigificant work

imre16:11:52

I noticed that clofidence uses a custom clojure compiler underneath. How closely does that follow the official one? How clofident I can be that if I run tests through that, my system will work the same way when it is executed in production using the official compiler?

jpmonettas16:11:43

yeah, so ClojureStorm is tracking the official Clojure compiler, just adding some extra bytecode for tracing expressions, fn calls, etc. So it is the same compiler. Of course there could be bugs, but it has been in use for some time with FlowStorm

jpmonettas16:11:48

Also I'm not using it for running tests, I think the tests should be run with the official compiler, this is low risk only, just for dev stuff like debugging, coverage, etc

imre16:11:02

Hmm so in CI you recommend executing tests twice, once with coverage off, using the official compiler and once with coverage on?

jpmonettas16:11:53

I mean, you choose, but same thing happens with cloverage, it is changing your code by an instrumented one, so how confident can you be that it doesn't change code's behavior

imre16:11:11

Yeah, true that

imre16:11:57

This bit is interesting:

Which forms are included in the report?
By default only forms with the first symbol name being one of : defn, defn-, defmethod, extend-type, extend-protocol, deftype and defrecord.

If you have other types of forms like the ones defined by some macros, you can include them by using :extra-forms in the configuration parameters. It takes a set of symbols like :extra-forms #{defroutes my-macro}.
So the methods that were found too large by clofidence in my code are defined by a custom macro, which is somewhat surprising as I haven't specified :extra-forms for the run. The custom macro expands to a couple of defns however, could this have something to do with it?

jpmonettas16:11:51

so, it is instrumenting all of them, just not including them on the report

imre16:11:44

Oh. There must be a reason for that. Also, is there a way to include everything instrumented in the report and perhaps have a blocklist instead of an allowlist?

jpmonettas16:11:18

currently there isn't but sure, it can be added pretty easily

jpmonettas16:11:59

this is so the report doesn't include things like deftest forms if you weren't able to skip them with the ns prefix instrumentation

jpmonettas16:11:52

maybe it is also slower because it is currently instrumenting the tests forms probably, unless you have all your tests under my-app.tests. so you can skip

jpmonettas16:11:14

there is a ton of room for improvements in all this aspects for sure

1
imre16:11:08

I normally have a namespace suffix for tests, I think that's more or less standard in clojure

jpmonettas16:11:13

yeah, I should improve ClojureStorm ns instrumentation by regex instead of prefix as it is now, which is much more powerful

imre16:11:15

I'll be following this project with great interest. Thank you!

馃檹 1
jpmonettas16:11:52

if you have any ideas also, feel free to open issues or show up in #C03KZ3XT0CF to discuss them

imre16:11:05

I can open one about this filtering thing for sure just for the sake of documentation

馃憤 2
Ben Sless17:11:49

What about cases where users use add-test or with-test?

Ben Sless17:11:10

I wonder if anyone uses those

jpmonettas18:11:04

@UK0810AQ2 sorry, what is add-test and how do you think it could be affected?

Ben Sless18:11:27

you mentioned:

this is so the report doesn't include things like deftest forms if you weren't able to skip them with the ns prefix instrumentation
So I was wondering about code in forms like add-test or with-test that add the test metadata to an existing var, how they'd interact with the system

jpmonettas18:11:31

so, this will instrument all the code that matches the instrumentOnlyPrefixes and then run whatever your test-fn runs, and collect the coordinates that were hit per form.. The thing you mention there is what forms should be displayed on the final report. That is so you don't display forms like (deftest ....) which you are probably not interested in. If a form starts with (add-test ...) for example, it wont be displayed in the report, but you can add them using the :extra-forms key

馃憤 1