From c3211b85a7548a30fc36e91b91f317483bdf381e Mon Sep 17 00:00:00 2001 From: Eugene Platonov Date: Thu, 8 Aug 2024 10:03:45 -0400 Subject: [PATCH] Properly handle multiple exclude entries for Scala 3 --- src/main/scala/scoverage/ScoverageSbtPlugin.scala | 4 ++-- .../scoverage/scala3-coverage-excluded-files/build.sbt | 2 +- .../src/main/scala/three/GoodCoverage.scala | 9 +++++++++ .../scala3-coverage-excluded-packages/build.sbt | 2 +- .../src/main/scala/three/GoodCoverage.scala | 9 +++++++++ 5 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 src/sbt-test/scoverage/scala3-coverage-excluded-files/src/main/scala/three/GoodCoverage.scala create mode 100644 src/sbt-test/scoverage/scala3-coverage-excluded-packages/src/main/scala/three/GoodCoverage.scala diff --git a/src/main/scala/scoverage/ScoverageSbtPlugin.scala b/src/main/scala/scoverage/ScoverageSbtPlugin.scala index feba91ba..c48d3d88 100644 --- a/src/main/scala/scoverage/ScoverageSbtPlugin.scala +++ b/src/main/scala/scoverage/ScoverageSbtPlugin.scala @@ -197,7 +197,7 @@ object ScoverageSbtPlugin extends AutoPlugin { if isScala3SupportingFilePackageExclusion( scalaVersion.value ) => - s"-coverage-exclude-classlikes:$v" + s"-coverage-exclude-classlikes:${v.replace(';', ',')}" }, excludedFiles .collect { @@ -205,7 +205,7 @@ object ScoverageSbtPlugin extends AutoPlugin { if isScala3SupportingFilePackageExclusion( scalaVersion.value ) => - s"-coverage-exclude-files:$v" + s"-coverage-exclude-files:${v.replace(';', ',')}" } ).flatten } else if (coverageEnabled.value && !isScala2(scalaVersion.value)) { diff --git a/src/sbt-test/scoverage/scala3-coverage-excluded-files/build.sbt b/src/sbt-test/scoverage/scala3-coverage-excluded-files/build.sbt index fef0a139..1bf9ac1a 100644 --- a/src/sbt-test/scoverage/scala3-coverage-excluded-files/build.sbt +++ b/src/sbt-test/scoverage/scala3-coverage-excluded-files/build.sbt @@ -4,7 +4,7 @@ scalaVersion := "3.4.2" libraryDependencies += "org.scalameta" %% "munit" % "0.7.29" % Test -coverageExcludedFiles := ".*/two/GoodCoverage" +coverageExcludedFiles := ".*/two/GoodCoverage;.*/three/GoodCoverage" resolvers ++= { if (sys.props.get("plugin.version").exists(_.endsWith("-SNAPSHOT"))) diff --git a/src/sbt-test/scoverage/scala3-coverage-excluded-files/src/main/scala/three/GoodCoverage.scala b/src/sbt-test/scoverage/scala3-coverage-excluded-files/src/main/scala/three/GoodCoverage.scala new file mode 100644 index 00000000..260d15a4 --- /dev/null +++ b/src/sbt-test/scoverage/scala3-coverage-excluded-files/src/main/scala/three/GoodCoverage.scala @@ -0,0 +1,9 @@ +package three + +object GoodCoverage { + + def sum(num1: Int, num2: Int) = { + if (0 == num1) num2 else if (0 == num2) num1 else num1 + num2 + } + +} diff --git a/src/sbt-test/scoverage/scala3-coverage-excluded-packages/build.sbt b/src/sbt-test/scoverage/scala3-coverage-excluded-packages/build.sbt index 083a1e20..dfd5b302 100644 --- a/src/sbt-test/scoverage/scala3-coverage-excluded-packages/build.sbt +++ b/src/sbt-test/scoverage/scala3-coverage-excluded-packages/build.sbt @@ -4,7 +4,7 @@ scalaVersion := "3.4.2" libraryDependencies += "org.scalameta" %% "munit" % "0.7.29" % Test -coverageExcludedPackages := "two\\..*" +coverageExcludedPackages := "two\\..*;three\\..*" resolvers ++= { if (sys.props.get("plugin.version").exists(_.endsWith("-SNAPSHOT"))) diff --git a/src/sbt-test/scoverage/scala3-coverage-excluded-packages/src/main/scala/three/GoodCoverage.scala b/src/sbt-test/scoverage/scala3-coverage-excluded-packages/src/main/scala/three/GoodCoverage.scala new file mode 100644 index 00000000..260d15a4 --- /dev/null +++ b/src/sbt-test/scoverage/scala3-coverage-excluded-packages/src/main/scala/three/GoodCoverage.scala @@ -0,0 +1,9 @@ +package three + +object GoodCoverage { + + def sum(num1: Int, num2: Int) = { + if (0 == num1) num2 else if (0 == num2) num1 else num1 + num2 + } + +}