Skip to content

Commit

Permalink
Add scripted tests for Scala 3
Browse files Browse the repository at this point in the history
  • Loading branch information
eed3si9n committed Mar 20, 2024
1 parent 4a3b819 commit acf1a39
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ lazy val root = (project in file("."))
scriptedBufferLog := false,
(pluginCrossBuild / sbtVersion) := {
scalaBinaryVersion.value match {
case "2.12" => "1.2.8"
case "2.12" => "1.5.8"
}
}
)
Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/sbtbuildinfo/BuildInfo.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sbtbuildinfo

import scala.annotation.nowarn
import sbt._, Keys._

case class BuildInfoResult(identifier: String, value: Any, typeExpr: TypeExpression)
Expand Down Expand Up @@ -44,9 +45,10 @@ object BuildInfo {
distinctKeys.flatMap(entry(_)).join
}

@nowarn
private def scope(scoped: Scoped, project: ProjectReference) = {
val scope0 = scoped.scope
if (scope0.project == This) scope0 in project
if (scope0.project == This) scope0.in(project)
else scope0
}

Expand Down
77 changes: 77 additions & 0 deletions src/sbt-test/sbt-buildinfo/scala3/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
lazy val check = taskKey[Unit]("checks this plugin")

ThisBuild / version := "0.1"
ThisBuild / scalaVersion := "3.4.0"

lazy val root = (project in file("."))
.enablePlugins(BuildInfoPlugin)
.settings(
name := "helloworld",
buildInfoKeys := Seq(
name,
scalaVersion,
),
buildInfoPackage := "hello",
buildInfoOptions ++= Seq(
BuildInfoOption.ToJson,
),
homepage := Some(url("http://example.com")),
licenses := Seq("MIT License" -> url("https://github.com/sbt/sbt-buildinfo/blob/master/LICENSE")),
scalacOptions ++= Seq("-Xfatal-warnings"),
check := {
val f = (Compile / sourceManaged).value / "sbt-buildinfo" / ("%s.scala" format "BuildInfo")
val lines = scala.io.Source.fromFile(f).getLines.toList
val Expected = """// $COVERAGE-OFF$""" ::
"""package hello""" ::
"""""" ::
"""/** This object was generated by sbt-buildinfo. */""" ::
"""case object BuildInfo {""" ::
""" /** The value is "helloworld". */""" ::
""" val name: String = "helloworld"""" ::
""" /** The value is "3.4.0". */""" ::
""" val scalaVersion: String = "3.4.0"""" ::
""" override val toString: String = {""" ::
""" "name: %s, scalaVersion: %s".format(""" ::
""" name, scalaVersion""" ::
""" )""" ::
""" }""" ::
""" val toMap: Map[String, scala.Any] = Map[String, scala.Any](""" ::
""" "name" -> name,""" ::
""" "scalaVersion" -> scalaVersion)""" ::
"""""" ::
""" private def quote(x: scala.Any): String = "\"" + x + "\""""" ::
""" private def toJsonValue[T <: Matchable](value: T): String = {""" ::
""" value match {""" ::
""" case elem: scala.collection.Seq[? <: Matchable] => elem.map(toJsonValue).mkString("[", ",", "]")""" ::
""" case elem: scala.Option[? <: Matchable] => elem.map(toJsonValue).getOrElse("null")""" ::
""" case elem: scala.collection.Map[?, ? <: Matchable] => elem.map {""" ::
""" case (k, v) => toJsonValue(k.toString) + ":" + toJsonValue(v)""" ::
""" }.mkString("{", ", ", "}")""" ::
""" case d: scala.Double => d.toString""" ::
""" case f: scala.Float => f.toString""" ::
""" case l: scala.Long => l.toString""" ::
""" case i: scala.Int => i.toString""" ::
""" case s: scala.Short => s.toString""" ::
""" case bool: scala.Boolean => bool.toString""" ::
""" case str: String => quote(str)""" ::
""" case other => quote(other.toString)""" ::
""" }""" ::
""" }""" ::
"""""" ::
""" val toJson: String = toJsonValue(toMap)""" ::
"""}""" ::
"""// $COVERAGE-ON$""" ::
Nil
lines match {
case Expected => ()
case _ =>
(lines, Expected).zipped.toList.foreach { case (a, b) =>
if (a != b) {
println("- " + a)
}
}
sys.error("unexpected output: \n" + lines.mkString("\n"))
}
()
}
)
7 changes: 7 additions & 0 deletions src/sbt-test/sbt-buildinfo/scala3/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
val pluginVersion = System.getProperty("plugin.version")
if(pluginVersion == null)
throw new RuntimeException("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
else addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % pluginVersion)
}
4 changes: 4 additions & 0 deletions src/sbt-test/sbt-buildinfo/scala3/test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
> compile
> doc
$ exists target/scala-3.4.0/src_managed/main/sbt-buildinfo/BuildInfo.scala
> check

0 comments on commit acf1a39

Please sign in to comment.