ihumanable / patch

Ergonomic Mocking for Elixir
MIT License
193 stars 11 forks source link

Patch seems to break (or is ignored by) testcoverage tooling? #68

Open DGollings opened 1 month ago

DGollings commented 1 month ago

First off, I really liked the API/implementation of Patch. Really enjoy using it so thanks for making it

But whilst experimenting with some code coverage tooling (mix test --cover) noticed that code that uses Patch.patch disappears from the reports.

So decided to clone this repo and noticed the same. Picked a test at random that uses patch(), refute_any_call_test.exs

❯ grep 'patch(' ./test/user/refute_any_call_test.exs
      patch(RefuteAnyCall, :function_with_multiple_arities, :patched)
      (..)
      patch(RefuteAnyCall, :other_function, :patched)
      patch(RefuteAnyCall, :function_with_multiple_arities, :patched)

but then:

mix test --cover 2>&1 | grep RefuteAny

outputs nothing, same for

grep RefuteAnyCall cover -r

which, seeing all the generated html files in cover/ seems unlikely

I assume this is known behaviour? I can imagine its a side-effect of how the 'super-powers' work but are you aware of a workaround or fix? Because its a bit ironic that the most well tested code in my codebase shows up as 0% or not at all :)

And a ps. Running the test directly mix test --cover ./test/user/refute_any_call_test.exs does show the User.Patch modules nearby but almost all of them as 0% coverage

ihumanable commented 2 days ago

@DGollings This is a known issue, I've got it on the roadmap to fix this. I'll see if I can figure it out soon ™️

DGollings commented 2 days ago

thanks @ihumanable , but you think its fixable? That's good to hear then, thanks

ihumanable commented 2 days ago

I think so, I've actually got some time today to take a look so 🤞