# Code Coverage Shard for Crystal

**URL:** <https://forum.crystal-lang.org/t/code-coverage-shard-for-crystal/3380>\
**Category:** Offtopic\
**Created:** [June 13, 2021, 9:36am UTC](https://forum.crystal-lang.org/t/code-coverage-shard-for-crystal/3380 "2021-06-13T09:36:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![drhuffman12](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/drhuffman12/32/715_2.png) [@drhuffman12](https://forum.crystal-lang.org/u/drhuffman12)\
**Post date:** [June 13, 2021, 9:36am UTC](https://forum.crystal-lang.org/t/code-coverage-shard-for-crystal/3380/1 "2021-06-13T09:36:29Z")

</div>

Anyone have a good idea of what to do to get [GitHub - anykeyh/crystal-coverage: Coverage tool for Crystal lang](https://github.com/anykeyh/crystal-coverage) 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?

---

<div class="post-metadata">

**Author:** ![drhuffman12](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/drhuffman12/32/715_2.png) [@drhuffman12](https://forum.crystal-lang.org/u/drhuffman12)\
**Post date:** [June 14, 2021, 7:20am UTC](https://forum.crystal-lang.org/t/code-coverage-shard-for-crystal/3380/2 "2021-06-14T07:20:00Z")

</div>

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](https://github.com/anykeyh/crystal-coverage)). PR at [Drhuffman12/update for crystal 1 0 0 by drhuffman12 · Pull Request #1 · drhuffman12/crystal-coverage · GitHub](https://github.com/drhuffman12/crystal-coverage/pull/1) 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](https://github.com/anykeyh/crystal-coverage/issues/17).

---

<div class="post-metadata">

**Author:** ![bcardiff](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/bcardiff/32/3_2.png) [@bcardiff](https://forum.crystal-lang.org/u/bcardiff)\
**Post date:** [June 14, 2021, 12:57pm UTC](https://forum.crystal-lang.org/t/code-coverage-shard-for-crystal/3380/3 "2021-06-14T12:57:11Z")

</div>

@drhuffman12 I don’t know `anykeyh/crystal-coverage` but in [bcardiff/crystal-tool-demo](https://github.com/bcardiff/crystal-tool-demo) I had a POC of a tool to identify [unused defs](https://github.com/bcardiff/crystal-tool-demo/blob/master/src/unused.cr) 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](https://llvm.org/docs/CommandGuide/llvm-cov.html), which I think might be a way to have [coverage reports](https://llvm.org/docs/CoverageMappingFormat.html), 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](https://github.com/crystal-lang/crystal/issues/1157)

---

<div class="post-metadata">

**Author:** ![asterite](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/asterite/32/60_2.png) [@asterite](https://forum.crystal-lang.org/u/asterite)\
**Post date:** [June 14, 2021, 1:25pm UTC](https://forum.crystal-lang.org/t/code-coverage-shard-for-crystal/3380/4 "2021-06-14T13:25:19Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![caspiano](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/caspiano/32/527_2.png) [@caspiano](https://forum.crystal-lang.org/u/caspiano)\
**Post date:** [June 14, 2021, 2:25pm UTC](https://forum.crystal-lang.org/t/code-coverage-shard-for-crystal/3380/5 "2021-06-14T14:25:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![asterite](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/asterite/32/60_2.png) [@asterite](https://forum.crystal-lang.org/u/asterite)\
**Post date:** [June 14, 2021, 2:40pm UTC](https://forum.crystal-lang.org/t/code-coverage-shard-for-crystal/3380/6 "2021-06-14T14:40:09Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![drhuffman12](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/drhuffman12/32/715_2.png) [@drhuffman12](https://forum.crystal-lang.org/u/drhuffman12)\
**Post date:** [June 14, 2021, 6:15pm UTC](https://forum.crystal-lang.org/t/code-coverage-shard-for-crystal/3380/7 "2021-06-14T18:15:45Z")

</div>

@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).

---

<div class="post-metadata">

**Author:** ![paulocoghi](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/paulocoghi/32/1429_2.png) [@paulocoghi](https://forum.crystal-lang.org/u/paulocoghi)\
**Post date:** [November 6, 2021, 7:06pm UTC](https://forum.crystal-lang.org/t/code-coverage-shard-for-crystal/3380/8 "2021-11-06T19:06:56Z")

</div>

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](https://github.com/crystal-lang/crystal/issues/1157), we look for all the different logical possibilities and ramifications:  
_(“statements”, “branch”, “functions”, “lines” and their logical ramifications)_

```auto
----------|---------|----------|---------|---------|-------------------
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.

```
