Help me reach 100% test coverage 😬

I usually don’t bother with perfect test coverage, but I’m one line away of getting 100% :white_check_mark:

This single line of code is not covered (l225)

How would you code a test for this ?
This test would actually be useful because I had a bug by mis-using Code.ensure_compile/1

Thanks for your help!

Code.ensure_compiled isn’t generally code you want to have occur at runtime at all anyway. Is this code called at compile time? If not I’d just do @json_library.encode! and if the module isn’t there it’ll just raise the normal error.

5 Likes

Good point and quite pragmatic solution :+1:
There are always two ways to improve test coverage:

  • write more tests
  • remove code :grin:

why that?

Well I thought it was slow, but local benchmarking indicates it’s about ~6us which isn’t bad. I think it used to be slow, and now it seems it is not!

Beyond that though, it’s generally better to morph your code for conditional dependencies at compile time because it’s really a compile time concern. In your case you aren’t even morphing your code based on deps, it’s basically just a hard dep, so the ensure_compiled call isn’t adding anything.

1 Like

Got it, thanks!

Mission accomplished :white_check_mark:
I will be able to sleep now, thank you @benwilson512 :wink:

5 Likes