Skip to content

Add support for Scala 3 #428

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions src/main/scala/scoverage/ScoverageSbtPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,9 @@ object ScoverageSbtPlugin extends AutoPlugin {
// rangepos is broken in some releases of scala so option to turn it off
if (coverageHighlighting.value) Some("-Yrangepos") else None
).flatten
} else if (
// TODO this is very temporary until support for this gets merged in.
// For now we restrict this to this exact SNAPSHOT version which needs
// to be published localled in order to test
coverageEnabled.value && scalaVersion.value == "3.1.2-RC1-bin-SNAPSHOT"
) {
} else if (coverageEnabled.value) {
Seq(
"-coverage",
s"${coverageDataDir.value.getAbsolutePath()}/scoverage-data"
s"-coverage-out:${coverageDataDir.value.getAbsolutePath()}/scoverage-data"
)
} else {
Nil
Expand Down
17 changes: 17 additions & 0 deletions src/sbt-test/scoverage/scala3-bad/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version := "0.1"

scalaVersion := "3.2.0-RC1-bin-20220517-e5abec0-NIGHTLY" // TODO: Should be updated to stable version on 3.2.0-RC1 release

libraryDependencies += "org.scalameta" %% "munit" % "0.7.25" % Test

coverageMinimum := 80

coverageFailOnMinimum := true

coverageEnabled := true

resolvers ++= {
if (sys.props.get("plugin.version").exists(_.endsWith("-SNAPSHOT")))
Seq(Resolver.sonatypeRepo("snapshots"))
else Seq.empty
}
16 changes: 16 additions & 0 deletions src/sbt-test/scoverage/scala3-bad/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
val pluginVersion = sys.props.getOrElse(
"plugin.version",
throw new RuntimeException(
"""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin
)
)

addSbtPlugin("org.scoverage" % "sbt-scoverage" % pluginVersion)

resolvers ++= {
if (pluginVersion.endsWith("-SNAPSHOT"))
Seq(Resolver.sonatypeRepo("snapshots"))
else
Seq.empty
}
10 changes: 10 additions & 0 deletions src/sbt-test/scoverage/scala3-bad/src/main/scala/BadCoverage.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
object BadCoverage {

def sum(num1: Int, num2: Int) = {
num1 + num2
}

def mult(num1: Int, num2: Int) = {
num1 * num2
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import munit.FunSuite

/** Created by tbarke001c on 7/8/14.
*/
class BadCoverageSpec extends FunSuite {

test("BadCoverage should sum two numbers") {
assertEquals(BadCoverage.sum(1, 2), 3)
}
}
5 changes: 5 additions & 0 deletions src/sbt-test/scoverage/scala3-bad/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# run scoverage
> clean
> coverage
> test
-> coverageReport
21 changes: 21 additions & 0 deletions src/sbt-test/scoverage/scala3-good/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version := "0.1"

scalaVersion := "3.2.0-RC1-bin-20220517-e5abec0-NIGHTLY" // TODO: Should be updated to stable version on 3.2.0-RC1 release

libraryDependencies += "org.scalameta" %% "munit" % "0.7.25" % Test

coverageMinimum := 80
coverageMinimumStmtTotal := 100
coverageMinimumBranchTotal := 100
coverageMinimumStmtPerPackage := 100
coverageMinimumBranchPerPackage := 100
coverageMinimumStmtPerFile := 100
coverageMinimumBranchPerFile := 100

coverageFailOnMinimum := true

resolvers ++= {
if (sys.props.get("plugin.version").exists(_.endsWith("-SNAPSHOT")))
Seq(Resolver.sonatypeRepo("snapshots"))
else Seq.empty
}
16 changes: 16 additions & 0 deletions src/sbt-test/scoverage/scala3-good/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
val pluginVersion = sys.props.getOrElse(
"plugin.version",
throw new RuntimeException(
"""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin
)
)

addSbtPlugin("org.scoverage" % "sbt-scoverage" % pluginVersion)

resolvers ++= {
if (pluginVersion.endsWith("-SNAPSHOT"))
Seq(Resolver.sonatypeRepo("snapshots"))
else
Seq.empty
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object GoodCoverage {

def sum(num1: Int, num2: Int) = {
if (0 == num1) num2 else if (0 == num2) num1 else num1 + num2
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package two

object GoodCoverage {

def sum(num1: Int, num2: Int) = {
if (0 == num1) num2 else if (0 == num2) num1 else num1 + num2
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import munit.FunSuite

/** Created by tbarke001c on 7/8/14.
*/
class GoodCoverageSpec extends FunSuite {

test("GoodCoverage should sum two numbers") {
assertEquals(GoodCoverage.sum(1, 2), 3)
assertEquals(GoodCoverage.sum(0, 3), 3)
assertEquals(GoodCoverage.sum(3, 0), 3)
}

test("two.GoodCoverage should sum two numbers") {
assertEquals(two.GoodCoverage.sum(1, 2), 3)
assertEquals(two.GoodCoverage.sum(0, 3), 3)
assertEquals(two.GoodCoverage.sum(3, 0), 3)
}

}
5 changes: 5 additions & 0 deletions src/sbt-test/scoverage/scala3-good/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# run scoverage
> clean
> coverage
> test
> coverageReport