tests for standard library unfreezing

This commit is contained in:
Lukas Rytz 2024-01-23 17:09:20 +01:00
parent f0afeff4d9
commit 4a1ba0c970
8 changed files with 123 additions and 0 deletions

View File

@ -0,0 +1,4 @@
lazy val a = project.settings(
scalaVersion := "2.13.4",
libraryDependencies += "org.scala-lang.modules" %% "scala-parallel-collections" % "1.0.4", // depends on library 2.13.6
)

View File

@ -0,0 +1,3 @@
-> a/scalaInstance
> set a/scalaVersion := "2.13.6"
> a/scalaInstance

View File

@ -0,0 +1,20 @@
import scala.language.reflectiveCalls
object A extends App {
println(scala.util.Properties.versionString)
}
object AMacro {
import scala.language.experimental.macros
import scala.reflect.macros.blackbox.Context
def m(x: Int): Int = macro impl
def impl(c: Context)(x: c.Expr[Int]): c.Expr[Int] = {
import c.universe._
// added in 2.13.4
val ec = (scala.concurrent.ExecutionContext: {def opportunistic: scala.concurrent.ExecutionContextExecutor}).opportunistic
println(ec)
c.Expr(q"2 + $x")
}
}

View File

@ -0,0 +1,17 @@
import scala.quoted.* // imports Quotes, Expr
package scala.collection {
object Exp:
// added in 2.13.10, not available in 2.13.8
def m(i: Int) = IterableOnce.checkArraySizeWithinVMLimit(i)
}
object Mac:
inline def inspect(inline x: Any): Any = ${ inspectCode('x) }
def inspectCode(x: Expr[Any])(using Quotes): Expr[Any] =
scala.collection.Exp.m(42)
println(x.show)
x
@main def huhu = println(scala.util.Properties.versionString)

View File

@ -0,0 +1,7 @@
import java.nio.file.{Paths, Files}
import java.nio.charset.StandardCharsets
object B extends App {
println(AMacro.m(33))
Files.write(Paths.get(s"s${scala.util.Properties.versionNumberString}.txt"), "nix".getBytes)
}

View File

@ -0,0 +1,6 @@
import java.nio.file.{Paths, Files}
import java.nio.charset.StandardCharsets
@main def hubu =
Mac.inspect(println("hai"))
Files.write(Paths.get(s"s${scala.util.Properties.versionNumberString}.txt"), "nix".getBytes)

View File

@ -0,0 +1,46 @@
import sbt.librarymanagement.InclExclRule
lazy val a = project.settings(
scalaVersion := "2.13.6",
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value,
TaskKey[Unit]("checkLibs") := checkLibs("2.13.6", (Compile/dependencyClasspath).value, ".*scala-(library|reflect).*"),
)
lazy val b = project.dependsOn(a).settings(
scalaVersion := "2.13.8",
TaskKey[Unit]("checkLibs") := checkLibs("2.13.8", (Compile/dependencyClasspath).value, ".*scala-(library|reflect).*"),
)
lazy val a3 = project.settings(
scalaVersion := "3.2.2", // 2.13.10 library
)
lazy val b3 = project.dependsOn(a3).settings(
scalaVersion := "3.2.0", // 2.13.8 library
TaskKey[Unit]("checkScala") := {
val i = scalaInstance.value
i.libraryJars.filter(_.toString.contains("scala-library")).toList match {
case List(l) => assert(l.toString.contains("2.13.10"), i.toString)
}
assert(i.compilerJars.filter(_.toString.contains("scala-library")).isEmpty, i.toString)
assert(i.otherJars.filter(_.toString.contains("scala-library")).isEmpty, i.toString)
},
)
lazy val ak = project.settings(
scalaVersion := "2.13.12",
csrSameVersions += Set[InclExclRule]("com.typesafe.akka" % "akka-*"),
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-remote" % "2.6.5",
"com.typesafe.akka" %% "akka-actor" % "2.6.2",
),
TaskKey[Unit]("checkLibs") := checkLibs("2.6.5", (Compile/dependencyClasspath).value, ".*akka-.*"),
)
def checkLibs(v: String, cp: Classpath, filter: String): Unit = {
for (p <- cp)
if (p.toString.matches(filter)) {
println(s"$p -- $v")
assert(p.toString.contains(v), p)
}
}

View File

@ -0,0 +1,20 @@
> a/checkLibs
> b/checkLibs
> b/run
$ exists s2.13.8.txt
$ delete s2.13.8.txt
# don't crash when expanding the macro
> b3/run
$ exists s2.13.10.txt
$ delete s2.13.10.txt
> b3/checkScala
# without the default `csrSameVersions`, scala-reflect in b stays at 2.13.6
> set b/csrSameVersions := Nil
> b/update
-> b/checkLibs
> ak/checkLibs