scouten
It’s been discussed a few times that code coverage tools do not see lines where a literal value are not flagged as executable lines. To wit:
I’m frustrated by this problem and I’m attempting to fix it in a library I’m building. (See Sign in to GitHub · GitHub)
I’ll start by saying I don’t like my fix, but I like even less the notion that I have to sacrifice insight into how well my library is covered.
I work that I’m doing in my day job, I have actually seen bugs get masked because we didn’t know the code was poorly covered.
I’m hoping that somebody can point me to a “better” solution that is less hacky, but doesn’t involve compromising on meaningful code coverage.
Trending in Discussions
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
New
Hey there,
It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Quite interesting article Google brought me. Didn’t find any mentions about it here.
What do you think in general? Would you use togethe...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Since we have deprecated our Erlang sections (as we have dedicated Erlang Forums now) let’s add this thread for those who’d like to post ...
New
What IDE or editor are you using for Elixir development?
Personally, I use Zed, and I really like it, but sometimes I wish there were a ...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 1 to 8- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
dimitarvp
Haven’t looked at your code yet. What is it that you don’t like about it currently?
scouten
What I don’t like is that I use a macro to translate a literal response into something more complicated in the
testenvironment. For example, what was:became:
In the
testenvironment, this evaluates to:(There are other variations depending on the value passed to
cover, but you get the point.)Not ideal, but it was the result of a lot of trial-and-error to make the compiler, Credo, and dialyzer all happy and still make the original
valid?/1function (and dozens more like it) show up as executable.Ultimately, I’d like to see the compiler change so that it is inherently marked as covered. But until / unless that happens, I’m looking for a less messy way to accomplish the goal of more accurate code coverage.
dimitarvp
Seems you got quite far though. I didn’t even know
defmacro cover(false = x) dois valid Elixir!Recommendation: first try and achieve the goals you want. Then you should probably make an announcement to the community and ask for code reviews.
NobbZ
Why not?
What does make you think it were different from
def foo(%Foo{} = foo) do … end?dimitarvp
I would assume that
defmacro cover(false) dois the way to go, same as when pattern-matching function heads assert on specific values.NobbZ
But they use the bound
xin the body.This is some heavy lifting to avoid problems in the coverage tools. So if they were just leaving off the binding of
xand would usefalseliterally, they might finaly have the same result of literals not beeing visible to the coverage tool or might cause warnings of unused variables.dimitarvp
I see. That’s why I said he actually got quite ahead. I would not have figured this out immediately.
scouten
Thanks for the props. So, in the process, I learned that pattern matching works with macros. (I hadn’t expected that, either.)
Basically, the
covermacro is an elaborate trick to prevent the compiler from inlining the literal value, which I think is the root cause for the lack of coverage.So, to @dimitarvp’s comment, when I first posted this a couple of weeks ago, it was initially this was a call for suggestions. I’ve since merged the PR in question, so we could now consider it a call for reviews.
To @NobbZ’s comment:
Thanks. As I said before, I wish there were a cleaner solution. If there is, I’d love to hear about it. If not, consider this a plea for help from the tool providers. I suspect this is an issue in the compiler itself, but it might be something in excoveralls.