-
Notifications
You must be signed in to change notification settings - Fork 126
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
Source-root confusion in presence of scalameta macro annotations #210
Comments
AST nodes have source == "<macro>" instead of real file path
First, I'm surprised nobody found this issue before. I've tried to learn meta macros quickly. Found simple example to test Scoverage. @ryan-williams, first please check your project with my PR branch of Scoverage to verify that it works properly. Thank you in advance. |
Thanks again @gslowikowski, sorry for the delay. I still see the error occurring with your PR branch. Here is a simple repro repo: git clone [email protected]:ryan-williams/scala-bugs.git
cd scala-bugs
git checkout scov
sbt clean coverage test coverageReport
…
[info] All tests passed.
[success] Total time: 12 s, completed Nov 19, 2017 8:20:02 PM
[info] Waiting for measurement data to sync...
[info] Reading scoverage instrumentation [/Users/ryan/c/scalac-bug/target/scala-2.11/scoverage-data/scoverage.coverage.xml]
[info] Reading scoverage measurements...
[info] Generating scoverage reports...
java.lang.RuntimeException: No source root found for '/Users/ryan/c/scalac-bug/<macro>' (source roots: '/Users/ryan/c/scalac-bug/src/main/scala/')
at scoverage.report.BaseReportWriter.relativeSource(BaseReportWriter.scala:28)
at scoverage.report.BaseReportWriter.relativeSource(BaseReportWriter.scala:16)
at scoverage.report.CoberturaXmlWriter.klass(CoberturaXmlWriter.scala:42)
at scoverage.report.CoberturaXmlWriter$$anonfun$pack$1.apply(CoberturaXmlWriter.scala:66)
at scoverage.report.CoberturaXmlWriter$$anonfun$pack$1.apply(CoberturaXmlWriter.scala:66)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
at scala.collection.immutable.List.foreach(List.scala:318) This uses my I'm not sure why your fix doesn't work yet; am hoping to dig in as well but haven't had time yet. I was looking at the same part of
Agreed that porting coverage/location information from code that gets moved/rearranged in a meta macro would be great; in particular in my case above it is important as all the interesting code I'd like coverage info about is in the body of a macro-tagged class, and gets wrapped in an extra Really appreciate your efforts here, hoping I can help more / more quickly if you continue to make progress! |
Thanks, I will check this tomorrow. |
You had to do something wrong. My fix works. After publishing locally Anyway, I have zero instrumented statements in your project. |
ah, I had not changed the Unfortunately, libraries that I've been using such macros in are mostly comprised of code contained in the macro-annotated classes, so dropping those lines limits the usefulness of coverage metrics. I'm guessing it's a significant project, but if you want to brainstorm how to measure macro-generated lines, I'm interested to try to help. It seems to me coverage-instrumentation has to happen on post-macro-expansion code, otherwise positions/coverage seem ill-defined (for example, what location would be reported/highlighted for a quasiquote-generated line that is covered in one generated class and not another)? I dug at it a bit tonight and the most interesting thing I came up with is this fork of scalameta/paradise that just hard-codes the original source path in place of the Compilation and
which seems promising! And the "statement list" at However, the "Code Grid" shows the pre-macro file, as does the Coveralls build. Not sure when I'll have time to keep pluggin on this but if you have any thoughts I'd love to hear them! |
Ryan, sorry for not responding, but I have no time for scoverage recently. What I can say now is:
Generally speaking generated code cannot be shown because it never had a source lines form. I will try to experiment more, when I will have more time. |
That sounds good, thanks @gslowikowski! I'm relatively optimistic about some of these ideas; in my case the macro annotates a class that is the only top-level declaration in the file, so replacing the file contents wholesale with the post-macro-expansion code – and displaying/using that throughout coverage reporting – seems reasonable. Additionally, the paradise hack I attempted at least convinced me that getting access to the post-macro code as a string isn't too hard. The fact that the "statement list" in the web UI seemed to have worked above is also encouraging. I'm hoping I can find some time to push on it again as well, thanks! |
Repro
Full stack trace here
Discussion
This repo has two modules,
core
andmacros
. The latter defines a scalameta macro annotation that causes implicit conversions into a class to be synthesized, and the former uses that annotation to generate some code.Some previous discussion at scoverage/sbt-coveralls#102
The text was updated successfully, but these errors were encountered: