question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`-coverage-out` generates coverage information for macro code coming from referenced libraries

See original GitHub issue

Compiler version

3.2.0-RC1

If you’re not sure what version you’re using, run print scalaVersion from sbt (if you’re running scalac manually, use scalac -version instead).

Minimized code

Macro.scala

package excludeme

import scala.quoted.*

object Macro {

  inline def toUpperS(s: String): String = ${ Macro.toUpperSImpl('s) }

  def toUpperSImpl(s: Expr[String])(using q: Quotes): Expr[String] = '{ ($s.toUpperCase) } // will add coverage info
}

Main.scala

import excludeme.*

@main def main: Unit =
  println(Macro.toUpperS("test"))

Minimized code (using third party library)

Keeping this for the sake of history how it was originally reported.

import io.circe.*
import io.circe.generic.semiauto.*
import io.circe.syntax.*

implicit val basicCodec: Codec[Tuple1[String]] = deriveCodec[Tuple1[String]]

@main def main: Unit =
  println(Tuple1("value").asJson.noSpaces)

Full project is here https://github.com/arixmkii/macro_cov_3.2.0-RC1 I will think about a better minimal example, because circe-generic is a heavy one. May be with 2 source files and using one with macro as pre-compiled class.

Output

scoverage.coverage file contains records of

modules/core/shared/src/main/scala-3/io/circe/Derivation.scala

Expectation

No coverage data for third party libraries as source might not be provided for them.

Originally posted here https://github.com/scoverage/scalac-scoverage-plugin/issues/474 I think that workarounds could be added to report generation to handle such cases (probably giving out a warning by default), but I’m not sure if this is the right approach for dealing with macros from referenced libraries.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
lefoucommented, Oct 20, 2022

I think, generating coverage data for code that comes from macros is a nice thing. In scoverage 1.x, it was not possible at all to get coverage for macro code. (E.g. is was not easily possible, to get coverage data for Mill targets which are written with the help of a surrounding T{ } macro). But the reporter should be a) able to gracefully handle missing source files and b) only count those macros into metrics which are part of the actual code base. As a consequence, we need to distinguish between own and foreign macro code, otherwise we might generate incorrect coverage metrics.

1reaction
arixmkiicommented, Jun 22, 2022

Optionally it could generate coverage info with source erased. Giving it another thought I can see how this could end up in source collision between third party library and own sources and will give (at best) useless output.

/shared/src/main/scala-3/Utils.scala in a library sources defining a macro and any file /shared/src/main/scala-3/Utils.scala in local sources for some random utilities. If library macro will be used anywhere in code it will create data linked to unrelated sources.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Libraries and Packages of the Code Coverage Ecosystem
Part I of a two-part series looking at code coverage tools steps through tools for five of the most popular languages: PHP.
Read more >
EMMA User Guide
EMMA is a tool for measuring coverage of Java software. Such a tool is essential for detecting dead code and verifying which parts...
Read more >
Code Coverage for Embedded Target with Eclipse, gcc and ...
gcov is an open source program which can generate code coverage information. It tells me how often each line of a program is...
Read more >
Getting useful GCov results for header-only libraries-C++
This will generate code for every method in that template class making the ... -b ${ROOT} -o Coverage.out lcov -a Coverage.baseline -a Coverage.out...
Read more >
Untitled
Lakewood analomink pa, Formones mifer, The librarian full cast! Dim 2014 segundo semestre, Maniacal genius definition, Disneyland rides matterhorn 2015, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found