Skip to content

Commit

Permalink
run more tests against scala 3 targets
Browse files Browse the repository at this point in the history
  • Loading branch information
bjaglin committed Apr 10, 2022
1 parent 21b9f6e commit ae82a10
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 10 deletions.
17 changes: 16 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,22 @@ lazy val unit = projectMatrix
),
Test / test := (Test / test)
.dependsOn(cli.projectRefs.map(_ / publishLocalTransitive): _*)
.value
.value,
Test / unmanagedSourceDirectories ++= {
val sourceDir = (Test / sourceDirectory).value
val maybeTargetScalaVersion =
TargetAxis
.targetScalaVersion(virtualAxes.value)
.flatMap(CrossVersion.partialVersion(_))
maybeTargetScalaVersion match {
case Some((n, m)) =>
Seq(
sourceDir / s"scala-target$n",
sourceDir / s"scala-target$n.$m"
)
case _ => Seq()
}
}
)
.defaultAxes(VirtualAxis.jvm)
.jvmPlatform(
Expand Down
2 changes: 1 addition & 1 deletion project/ScalafixBuild.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ object ScalafixBuild extends AutoPlugin with GhpagesKeys {
s
},
commands += Command.command("ci-3") { s =>
"unit2_12Target3/testOnly scalafix.tests.rule.RuleSuite" ::
"unit2_12Target3/test" ::
s
},
commands += Command.command("ci-213") { s =>
Expand Down
8 changes: 4 additions & 4 deletions project/TargetAxis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ case class TargetAxis(scalaVersion: String) extends VirtualAxis.WeakAxis {

object TargetAxis {

private def targetScalaVersion(virtualAxes: Seq[VirtualAxis]): String =
virtualAxes.collectFirst { case a: TargetAxis => a.scalaVersion }.get
def targetScalaVersion(virtualAxes: Seq[VirtualAxis]): Option[String] =
virtualAxes.collectFirst { case a: TargetAxis => a.scalaVersion }

/**
* When invoked on a ProjectMatrix with a TargetAxis, lookup the project
Expand All @@ -27,7 +27,7 @@ object TargetAxis {
key: TaskKey[T]
): Def.Initialize[Task[T]] =
Def.taskDyn {
val sv = targetScalaVersion(virtualAxes.value)
val sv = targetScalaVersion(virtualAxes.value).get
val project = matrix.finder().apply(sv)
Def.task((project / key).value)
}
Expand All @@ -42,7 +42,7 @@ object TargetAxis {
key: SettingKey[T]
): Def.Initialize[T] =
Def.settingDyn {
val sv = targetScalaVersion(virtualAxes.value)
val sv = targetScalaVersion(virtualAxes.value).get
val project = matrix.finder().apply(sv)
Def.setting((project / key).value)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package scalafix.tests.v0
import scala.meta._
import scalafix.tests.core.BaseSemanticSuite

// LegacySyntheticsTest cannot be compiled with Scala 2.13 or Scala 3
class LegacySyntheticsSuite extends BaseSemanticSuite("LegacySyntheticsTest") {

test("text") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,16 @@ trait BaseCliSuite extends AnyFunSuite with DiffAssertions {
)
}

// The defaults of this helper expect to find test input which is currently
// built only on scala 2.x since building them for Scala 3 would trigger
// test failures as the rules they exercise are not supported on Scala 3.
// TODO: switch defaults to rely on much more simple test input/rules so
// that we don't need to hardcode a scala version here.
val sourceDir = "scalafix-tests/input/src/main/scala-2"

def sourceDirectory: AbsolutePath =
props.inputSourceDirectories
// TODO: This test won't work for scala 3. The path is hardcoded
.find(dir => dir.toNIO.endsWith("scala-2")) // Skip scala-2.12
.find(dir => dir.toNIO.endsWith(sourceDir))
.getOrElse {
throw new IllegalArgumentException(
props.inputSourceDirectories.toString()
Expand Down Expand Up @@ -195,8 +201,7 @@ trait BaseCliSuite extends AnyFunSuite with DiffAssertions {
test(name, SkipWindows) {
val fileIsFixed = expectedExit.isOk
val cwd = Files.createTempDirectory("scalafix")
val inputSourceDirectory =
cwd.resolve("scalafix-tests/input/src/main/scala-2/")
val inputSourceDirectory = cwd.resolve(sourceDir)
Files.createDirectories(inputSourceDirectory)
val root = AbsolutePath(inputSourceDirectory)
val out = new ByteArrayOutputStream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ class BasePrettyTypeSuite extends BaseSemanticSuite("TypeToTreeInput") {

val classpath: Classpath =
Classpaths.withDirectories(semanticdbTargetRoots :+ classDir)

// As of scalameta 4.5.3, this relies on scalap (and not on TASTy), so it
// cannot work against classes compiled with Scala 3
val table: GlobalSymbolTable = GlobalSymbolTable(classpath, includeJdk = true)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class SymbolSuite extends munit.FunSuite {
case Term.ApplyInfix(_, Term.Name("shouldBe"), _, arg :: Nil) => arg
}

// The symbol lookup fails against Scala 3.1.1 SemanticDB as the position
// there excludes surrounding parentheses while 2.x (scalac-semanticdb) and
// the parser include them
assertNotEquals(arg.symbol, Symbol.None)
}

Expand Down

0 comments on commit ae82a10

Please sign in to comment.