Skip to content

Commit

Permalink
bugfix: Ty to fix flaky Scala CLI suite
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Oct 24, 2023
1 parent 3bc135f commit 6338e75
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class BaseScalaCLIActionSuite(name: String)
expectError,
filterAction,
overrideLayout = layout,
isDiagnosticBased = true,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,16 @@ class ScalaCliActionsSuite
expectNoDiagnostics = false,
)

val newestCatsLib: String = coursierComplete
.complete("org.typelevel::cats-core:")
.headOption
.map(_.stripPrefix(":"))
.getOrElse("2.9.0")

checkScalaCLI(
"auto-import",
s"""|//> using scala "${BuildInfo.scala213}"
|//> using lib "org.typelevel::cats-core:2.9.0"
|//> using lib "org.typelevel::cats-core:$newestCatsLib"
|
|object A {
| <<Future>>.successful(2)
Expand All @@ -112,15 +118,14 @@ class ScalaCliActionsSuite
|${CreateNewSymbol.title("Future")}
|""".stripMargin,
s"""|//> using scala "${BuildInfo.scala213}"
|//> using lib "org.typelevel::cats-core:2.9.0"
|//> using lib "org.typelevel::cats-core:$newestCatsLib"
|import scala.concurrent.Future
|
|object A {
| Future.successful(2)
|}
|""".stripMargin,
scalaCliOptions = List("--actions", "-S", scalaVersion),
expectNoDiagnostics = false,
fileName = "A.sc",
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ abstract class BaseCodeActionLspSuite(
expectError: Boolean = false,
filterAction: CodeAction => Boolean = _ => true,
overrideLayout: Option[String] = None,
isDiagnosticBased: Boolean = false,
)(implicit loc: Location): Unit = {
val scalacOptionsJson =
if (scalacOptions.nonEmpty)
Expand Down Expand Up @@ -88,6 +89,7 @@ abstract class BaseCodeActionLspSuite(
changeFile,
expectError,
filterAction,
isDiagnosticBased,
)
}

Expand All @@ -105,6 +107,7 @@ abstract class BaseCodeActionLspSuite(
changeFile: String => String = identity,
expectError: Boolean = false,
filterAction: CodeAction => Boolean = _ => true,
isDiagnosticBased: Boolean = false,
)(implicit loc: Location): Unit = {
val files = FileLayout.mapFromString(layout)
val (path, input) = files
Expand Down Expand Up @@ -135,6 +138,9 @@ abstract class BaseCodeActionLspSuite(
path,
changeFile(input).replace("<<", "").replace(">>", ""),
)
_ <-
if (isDiagnosticBased) server.didSave(path)(identity)
else Future.successful(())
codeActions <-
server
.assertCodeAction(
Expand Down

0 comments on commit 6338e75

Please sign in to comment.