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

better test infrastructure for Scala 3 #1528

Merged
merged 2 commits into from
Apr 11, 2022
Merged

Conversation

bjaglin
Copy link
Collaborator

@bjaglin bjaglin commented Jan 23, 2022

Unlocks #1480
Should make testing #1583 easier
Exposed one bug #1594

See commit messages

sbt:scalafix> projects
[info] In file:/home/brice/git/opensource/scalafix/
[info] 	   cli2_11
[info] 	   cli2_12
[info] 	   cli2_13
[info] 	   core2_11
[info] 	   core2_12
[info] 	   core2_13
[info] 	   docs2_13
[info] 	   interfaces2_11
[info] 	   interfaces2_12
[info] 	   interfaces2_13
[info] 	   reflect2_11
[info] 	   reflect2_12
[info] 	   reflect2_13
[info] 	   rules2_11
[info] 	   rules2_12
[info] 	   rules2_13
[info] 	 * scalafix
[info] 	   testkit2_11
[info] 	   testkit2_12
[info] 	   testkit2_13
[info] 	   testsInput2_11
[info] 	   testsInput2_12
[info] 	   testsInput2_13
[info] 	   testsInput3
[info] 	   testsOutput2_11
[info] 	   testsOutput2_12
[info] 	   testsOutput2_13
[info] 	   testsOutput3
[info] 	   testsShared2_11
[info] 	   testsShared2_12
[info] 	   testsShared2_13
[info] 	   testsShared3
[info] 	   unit2_11Target2_11
[info] 	   unit2_12Target2_12
[info] 	   unit2_12Target3
[info] 	   unit2_13Target2_13

buildScalaVersions.map(VirtualAxis.scalaABIVersion) :+ VirtualAxis.jvm: _*
)
.customRow(
scalaVersions = Seq(scala212),
Copy link
Collaborator Author

@bjaglin bjaglin Apr 9, 2022

Choose a reason for hiding this comment

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

crossPublishLocalBinTransitive := {
val currentState = state.value
val ref = thisProjectRef.value
val versions = crossScalaVersions.value
Copy link
Collaborator Author

@bjaglin bjaglin Apr 9, 2022

Choose a reason for hiding this comment

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

https://github.com/sbt/sbt-projectmatrix/blob/e46c2e3c3a4eba186a204303834e5d01893455b7/src/main/scala/sbt/internal/ProjectMatrix.scala#L145 has exactly what we need to iterate over versions so we can get rid of this (which would have required some tweaks anyway since crossScalaVersions is not set anymore). Note that we do lose the optimization of not generating/publishing docs & src, but the removal in complexity is worth it IMHO.

@bjaglin bjaglin force-pushed the projectmatrix branch 3 times, most recently from 2367055 to 4d1b2fe Compare April 9, 2022 21:19
@@ -5,3 +5,4 @@ addSbtPlugin("ch.epfl.scala" % "sbt-version-policy" % "2.0.1")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.3.2")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.9.3")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.34")
addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % "0.9.0")
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

see scalacenter/scalafix.g8#19 for some prior discussions

@bjaglin bjaglin force-pushed the projectmatrix branch 5 times, most recently from b307242 to 1d42d5d Compare April 10, 2022 10:17
@bjaglin bjaglin changed the title WIP switch build to projectmatrix WIP switch build to projectmatrix & run more tests against Scala 3 Apr 10, 2022
@bjaglin bjaglin changed the title WIP switch build to projectmatrix & run more tests against Scala 3 WIP switch build to sbt-projectmatrix Apr 10, 2022
@bjaglin bjaglin force-pushed the projectmatrix branch 3 times, most recently from 620d6f1 to b375137 Compare April 10, 2022 11:39
@bjaglin bjaglin changed the title WIP switch build to sbt-projectmatrix better test infrastructure for Scala 3 Apr 10, 2022
@@ -93,7 +93,6 @@ object Test {
val annType1: T @ann(42) = ???
val annType2: T @ann1 @ann2 = ???

val existentialType1: T forSome { type T } = ???
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Existential types are longer supported in Scala 3 and rarely used in Scala 2 so for the sake of simplicity, I dropped this completely.

@@ -63,7 +63,7 @@
[59:9..59:10]: test/Test.M#m(). => method m: Int
[62:9..62:10]: test/Test.N# => trait N extends AnyRef { +1 decls }
[63:9..63:10]: test/Test.N#n(). => method n: Int
[66:9..66:10]: test/Test.C# => class C extends M { +36 decls }
[66:9..66:10]: test/Test.C# => class C extends M { +35 decls }
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sbt save-expect

Comment on lines +25 to +27
// 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
Copy link
Collaborator Author

@bjaglin bjaglin Apr 10, 2022

Choose a reason for hiding this comment

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

I am not familiar with changes in Scala 3, but I know there has been changes to the infix behavior. Where should we report this mismatch between scalameta's parser and dotty's semanticdb output? Is it something that should be addressed in Dotty, in scalameta, or here?

Opening a ticket for tracking as it's a bug that this PR exposes #1594

Comment on lines +287 to +302
sourceDir / s"scala-target$n",
sourceDir / s"scala-target$n.$m"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this allows to restrict execution of certain tests based on what the unit combination is testing against

@bjaglin bjaglin force-pushed the projectmatrix branch 2 times, most recently from 8ed62a7 to ae82a10 Compare April 10, 2022 15:12
Comment on lines +42 to +46
[sbt-projectmatrix](https://github.com/sbt/sbt-projectmatrix) is used to
generate several sbt projects `unitXTargetY` with the same source code,
but for a combination of Scala versions:
- used for compiling the framework and rules (`X`)
- used for compiling and generating SemanticDB files for the test input (`Y`)
Copy link
Collaborator Author

@bjaglin bjaglin Apr 10, 2022

Choose a reason for hiding this comment

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

This is not ideal given the tests currently located in unit: most of them are NOT related to the target, so we end up running twice these "truely unit" tests (unit2_12Target2_12 & unit2_12Target3).

#1593

Comment on lines +162 to +166
// 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.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

only one user of this helper is actively relying on defaults and fails on Scala 3 targets, but I moved all of them for consistency

@@ -0,0 +1,44 @@
package scalafix.tests.cli
Copy link
Collaborator Author

@bjaglin bjaglin Apr 10, 2022

Choose a reason for hiding this comment

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

These rules extracted from CliSyntacticSuite were referenced in

scalafix.tests.cli.CrashingRule
scalafix.tests.cli.NoOpRule
scalafix.tests.cli.DeprecatedName
scalafix.tests.cli.Scala2_9
scalafix.tests.cli.AvailableRule
scalafix.tests.cli.Disable
so they cannot be in test/scala-2

s"++$scala213" ::
"cli/crossPublishLocalBinTransitive" :: // scalafix.tests.interfaces.ScalafixSuite
s"unit/testOnly -- -l scalafix.internal.tests.utils.SkipWindows" ::
"publishLocalTransitive" :: // scalafix.tests.interfaces.ScalafixSuite
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

publishLocalTransitive is only defined in cli* projects so running this at the root triggers them through aggregation

@bjaglin bjaglin marked this pull request as ready for review April 10, 2022 16:18
@bjaglin bjaglin requested a review from mlachkar April 10, 2022 16:18
Comment on lines +33 to +34
// As of scalameta 4.5.3, this relies on scalap (and not on TASTy), so it
// cannot work against classes compiled with Scala 3
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@@ -0,0 +1,50 @@
import sbt._
Copy link
Collaborator Author

@bjaglin bjaglin Apr 10, 2022

Choose a reason for hiding this comment

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

bjaglin added 2 commits April 11, 2022 12:05
Goals:
- make it easier to understand we use 2.12 to run/test against 3
- allow more parallel building/testing
s"""set testsInput/scalaVersion := "$scala3"""" ::
s"""set testsOutput/scalaVersion := "$scala3"""" ::
"unit/testOnly scalafix.tests.rule.RuleSuite" :: s
"unit2_12Target3/test" ::
Copy link
Collaborator

Choose a reason for hiding this comment

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

or unit_213Target3: Both should work no ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

unit2_13Target3 does not exist for the moment, see #1528 (comment). We could add it though, but I am not sure it brings a lot of value until/unless scalafixScalaBinaryVersion is updated.

@@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

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

One day we would need to clean these old interfaces

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Definitely. I had a quick look at it, but I am not familiar enough with the API to know what is still relevant, so I decided to limit the number of changes...

@bjaglin bjaglin merged commit c5633c6 into scalacenter:main Apr 11, 2022
@rvacaru
Copy link
Contributor

rvacaru commented Apr 11, 2022

Thanks a lot for making #1583 easier to test!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants