Code Coverage Shard for Crystal

Anyone have a good idea of what to do to get GitHub - anykeyh/crystal-coverage: Coverage tool for Crystal lang updated and into a usable state? (Last commit to master was 2020-04-20, more than a year ago. I ran the non-standard specs and got no output. I didn’t dig much deeper into it.) Or, is there an alternative Code Coverage tool for Crystal?

My bad. I read the doc’s a bit more. But, still had issues, so I worked on updating via a PR of my old fork of the repo (forked off the e781f8c on Apr 20, 2020 commit, which is the latest commit on the master branch of GitHub - anykeyh/crystal-coverage: Coverage tool for Crystal lang). PR at Drhuffman12/update for crystal 1 0 0 by drhuffman12 · Pull Request #1 · drhuffman12/crystal-coverage · GitHub is kinda working, but still has issues; maybe I didn’t fix enough of the code? I logged an issue here: Update repo for Crystal 1+ and document how to run the tests; maybe add an example shard that uses it · Issue #17 · anykeyh/crystal-coverage · GitHub.

1 Like

@drhuffman12 I don’t know anykeyh/crystal-coverage but in bcardiff/crystal-tool-demo I had a POC of a tool to identify unused defs that I’ve used in real apps to do some cleanup.

It is not a whole coverage tool but it covers some stories there.

LLVM has llvm-cov, which I think might be a way to have coverage reports, but for that the compiler needs to emit some additional information (via some opt-in flag probably). This is not done neither has been attempted AFAIK.

Ref: Code coverage tool anytime soon? · Issue #1157 · crystal-lang/crystal · GitHub

5 Likes

I’m pretty sure one day something will happen that will allow us to write our own coverage tool in a much easier way ;-)

(no promises, though)

4 Likes

care to elaborate? that sounds very intriguing! even without the prospect of a promise :stuck_out_tongue_winking_eye:

It’s a tool I’m working on which might enable code coverage and some other things. But I will reveal it in the upcoming Crystal Conference. So you’ll know then, or shortly afterwards. Sorry, I can’t reveal much more right now. Plus it’s not sure it will work!

8 Likes

@bcardiff , Thanks! I’ll check those out!

@asterite , I look forward to your announcement!

I’ll probably shelf my PR for now and see what you two have and come up with.

I know some dev teams have a minimum code coverage percentage policy for all PR merges into their codebases. So, having a working Code Coverage tool for Crystal could be another selling point for adoption of Crystal (or killing point while still missing).

3 Likes

Exactly. Being able to produce detailed coverage is important for us, and we would love to use Crystal as our new language.

As I explained on issue #1157, we look for all the different logical possibilities and ramifications:
(“statements”, “branch”, “functions”, “lines” and their logical ramifications)

----------|---------|----------|---------|---------|-------------------
File      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
----------|---------|----------|---------|---------|-------------------
All files |     100 |      100 |     100 |     100 |                   
 index.cr |     100 |      100 |     100 |     100 |                   
----------|---------|----------|---------|---------|-------------------
Test Suites: 1 passed, 1 total
Tests:       11 passed, 11 total
Snapshots:   0 total
Time:        3.735 s, estimated 5 s
Ran all test suites.
2 Likes