-
Notifications
You must be signed in to change notification settings - Fork 43
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
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 = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
because there can be only one value per axis per project
we lookup the corresponding input/output project based on this value, that's where I am not too satisfied with the |
||
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") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
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 |
There was a problem hiding this comment.
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
andData
. Suggestions welcome!There was a problem hiding this comment.
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