Skip to content
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

ScalafixTestkitPlugin improvements #220

Merged
merged 2 commits into from
May 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
54 changes: 29 additions & 25 deletions src/main/scala-sbt-1.0/scalafix/sbt/ScalafixTestkitPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,42 @@ object ScalafixTestkitPlugin extends AutoPlugin {
override def requires: Plugins = JvmPlugin

object autoImport {
case class InputAxis(scalaVersion: String) extends VirtualAxis.WeakAxis {
case class TestkitTargetAxis(scalaVersion: String)
Copy link
Collaborator Author

@bjaglin bjaglin May 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not very happy about that name either... I also considered Sources, Fixtures and Data. Suggestions welcome!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already better! Don't have better propositions

extends VirtualAxis.WeakAxis {
private val scalaBinaryVersion =
CrossVersion.binaryScalaVersion(scalaVersion)

override val idSuffix = s"Input${scalaBinaryVersion.replace('.', '_')}"
override val directorySuffix = s"input$scalaBinaryVersion"
override val idSuffix = s"Target${scalaBinaryVersion.replace('.', '_')}"
override val directorySuffix = s"target$scalaBinaryVersion"
}

object InputAxis {
def inputScalaVersion(virtualAxes: Seq[VirtualAxis]): String =
virtualAxes.collectFirst { case a: InputAxis => a.scalaVersion }.get
}
object TestkitTargetAxis {

def resolveByInputAxis[T](
matrix: ProjectMatrix,
key: TaskKey[T]
): Def.Initialize[Task[T]] =
Def.taskDyn {
val sv = InputAxis.inputScalaVersion(virtualAxes.value)
val project = matrix.finder().apply(sv)
Def.task((project / key).value)
}
private def targetScalaVersion(virtualAxes: Seq[VirtualAxis]): String =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't completely get why we take the first scalaVersion that we find, and use it the resolve task

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we take the first scalaVersion that we find

because there can be only one value per axis per project

use it the resolve task

we lookup the corresponding input/output project based on this value, that's where I am not too satisfied with the Target naming: it's about tagging in tests* which input* or output* it should run against.

virtualAxes.collectFirst { case a: TestkitTargetAxis =>
a.scalaVersion
}.get

def resolveByInputAxis[T](
matrix: ProjectMatrix,
key: SettingKey[T]
): Def.Initialize[T] =
Def.settingDyn {
val sv = InputAxis.inputScalaVersion(virtualAxes.value)
val project = matrix.finder().apply(sv)
Def.setting((project / key).value)
}
def resolve[T](
matrix: ProjectMatrix,
key: TaskKey[T]
): Def.Initialize[Task[T]] =
Def.taskDyn {
val sv = targetScalaVersion(virtualAxes.value)
val project = matrix.finder().apply(sv)
Def.task((project / key).value)
}

def resolve[T](
matrix: ProjectMatrix,
key: SettingKey[T]
): Def.Initialize[T] =
Def.settingDyn {
val sv = targetScalaVersion(virtualAxes.value)
val project = matrix.finder().apply(sv)
Def.setting((project / key).value)
}
}

val scalafixTestkitInputClasspath =
taskKey[Classpath]("Classpath of input project")
Expand Down
25 changes: 13 additions & 12 deletions src/sbt-test/sbt-1.5/testkit/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -38,40 +38,41 @@ lazy val tests = projectMatrix
.settings(
libraryDependencies += "ch.epfl.scala" % "scalafix-testkit" % V.scalafixVersion % Test cross CrossVersion.full,
scalafixTestkitOutputSourceDirectories :=
resolveByInputAxis(output, Compile / unmanagedSourceDirectories).value,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestkitTargetAxis
.resolve(output, Compile / unmanagedSourceDirectories)
.value,
scalafixTestkitInputSourceDirectories :=
resolveByInputAxis(
input,
Compile / unmanagedSourceDirectories
).value,
TestkitTargetAxis
.resolve(input, Compile / unmanagedSourceDirectories)
.value,
scalafixTestkitInputClasspath :=
resolveByInputAxis(input, Compile / fullClasspath).value,
TestkitTargetAxis.resolve(input, Compile / fullClasspath).value,
scalafixTestkitInputScalacOptions :=
resolveByInputAxis(input, Compile / scalacOptions).value,
TestkitTargetAxis.resolve(input, Compile / scalacOptions).value,
scalafixTestkitInputScalaVersion :=
resolveByInputAxis(input, Compile / scalaVersion).value
TestkitTargetAxis.resolve(input, Compile / scalaVersion).value
)
.defaultAxes(
rulesCrossVersions.map(VirtualAxis.scalaABIVersion) :+ VirtualAxis.jvm: _*
)
.customRow(
scalaVersions = Seq(V.scala212),
axisValues = Seq(InputAxis(scala3Version), VirtualAxis.jvm),
axisValues = Seq(TestkitTargetAxis(scala3Version), VirtualAxis.jvm),
settings = Seq()
)
.customRow(
scalaVersions = Seq(V.scala213),
axisValues = Seq(InputAxis(V.scala213), VirtualAxis.jvm),
axisValues = Seq(TestkitTargetAxis(V.scala213), VirtualAxis.jvm),
settings = Seq()
)
.customRow(
scalaVersions = Seq(V.scala212),
axisValues = Seq(InputAxis(V.scala212), VirtualAxis.jvm),
axisValues = Seq(TestkitTargetAxis(V.scala212), VirtualAxis.jvm),
settings = Seq()
)
.customRow(
scalaVersions = Seq(V.scala211),
axisValues = Seq(InputAxis(V.scala211), VirtualAxis.jvm),
axisValues = Seq(TestkitTargetAxis(V.scala211), VirtualAxis.jvm),
settings = Seq()
)
.dependsOn(rules)
Expand Down
2 changes: 1 addition & 1 deletion src/sbt-test/sbt-1.5/testkit/test
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-> tests/test
> testsInput3/test:run --save-expect
> testsTarget3/test:run --save-expect
> tests/test