Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macro annotations exclude user generated code from coverage #356

Open
ollyw opened this issue Jun 24, 2021 · 0 comments
Open

Macro annotations exclude user generated code from coverage #356

ollyw opened this issue Jun 24, 2021 · 0 comments

Comments

@ollyw
Copy link

ollyw commented Jun 24, 2021

Summary

Scoverage fails to provide coverage for objects that use macro annotations. This example is based upon real life usage with the ZIO accessible macro with the ZIO 1.x module pattern. Methods that are added by the developer do not have code coverage created for them although they should as only macro generated code should be ignored without the object body. It is highly probable that this also affects other macros using macro annotations. The killer is that code written and tested by the developer is silently excluded from code coverage which can hide bugs/code without coverage.

This project contains two objects representing services, that are equivalent, except that one has the manually generated code and the other uses the accessible macro

The cause

Within the plugin.scala code in Scoverage there is some code that ignores macro expanded code, regardless of whether the code has original line positions available for parts of the macro expanded code:

def process(tree: Tree): Tree = {
    tree match {

        ...
        
        // ignore macro expanded code, do not send to super as we don't want any children to be instrumented
        case t
            if t.attachments.all
              .toString()
              .contains("MacroExpansionAttachment") =>
          t

Ideally this can recursively inspect the macro expanded code and instrument the parts of the tree that have pos different from the macro pos. I modified the code as an experiment, and it worked to a degree, but the output reports don't work correctly. A proper fix is required

How to recreate

A project recreating the issue can be found here
https://github.com/ollyw/scoverage-macro-issue-repoducer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant