Skip to content

Commit

Permalink
Convert relative path to absolute for coverage options
Browse files Browse the repository at this point in the history
  • Loading branch information
lwronski committed Jun 7, 2022
1 parent fbb1d30 commit f1bb055
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,27 @@ abstract class CompileTestDefinitions(val scalaVersionOpt: Option[String])
)
}
}

if (actualScalaVersion.startsWith("3"))
test("generate scoverage.coverage file") {
val fileName = "Hello.scala"
val inputs = TestInputs(
Seq(
os.rel / fileName -> // scala version should updated to 3.3 after release
s"""//> using scala "3.2.0-RC1-bin-20220604-13ce496-NIGHTLY"
|//> using options "-coverage-out:."
|
|@main def main = ()
|""".stripMargin
)
)
inputs.fromRoot { root =>
os.proc(TestUtil.cli, "compile", extraOptions, fileName)
.call(cwd = root)
.out.text().trim

val expectedCoverageFilePath = root / "scoverage.coverage"
expect(os.exists(expectedCoverageFilePath))
}
}
}
29 changes: 25 additions & 4 deletions modules/options/src/main/scala/scala/build/options/ScalacOpt.scala
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
package scala.build.options
import scala.build.Os

final case class ScalacOpt(value: String) {
final case class ScalacOpt(scalacOption: String) {
def key: Option[String] =
if (value.startsWith("-"))
Some(value.takeWhile(_ != ':'))
if (scalacOption.startsWith("-"))
Some(scalacOption.takeWhile(_ != ':'))
.filterNot(key => ScalacOpt.repeatingKeys.exists(_.startsWith(key)))
else if (value.startsWith("@"))
else if (scalacOption.startsWith("@"))
Some("@")
else
None

lazy val value: String = {
val updatedScalacOpt = for {
scalacKey <- key
if ScalacOpt.keysWhichAcceptRelativePath.contains(scalacKey)
} yield ScalacOpt.convertRelativePathToAbsolute(scalacKey, scalacOption)

updatedScalacOpt.getOrElse(scalacOption)
}
}

object ScalacOpt {

private val keysWhichAcceptRelativePath = Seq(
"-coverage-out"
)

private val repeatingKeys = Set(
"-Xplugin:",
"-P" // plugin options
Expand All @@ -34,4 +49,10 @@ object ScalacOpt {
case (opt, idx) if opt.startsWith("-") || opt.startsWith("@") =>
idx
}

private def convertRelativePathToAbsolute(scalacKey: String, scalacOption: String): String = {
val relativePath = scalacOption.stripPrefix(s"$scalacKey:")
val absolutePath = os.Path(relativePath, Os.pwd)
s"$scalacKey:$absolutePath"
}
}

0 comments on commit f1bb055

Please sign in to comment.