From 6338e75a88d4dd9a45f66fbfeed4e39ef39c5bcb Mon Sep 17 00:00:00 2001 From: Tomasz Godzik Date: Tue, 24 Oct 2023 16:16:35 +0200 Subject: [PATCH] bugfix: Ty to fix flaky Scala CLI suite --- .../tests/scalacli/BaseScalaCLIActionSuite.scala | 1 + .../scala/tests/scalacli/ScalaCliActionsSuite.scala | 11 ++++++++--- .../tests/codeactions/BaseCodeActionLspSuite.scala | 6 ++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/slow/src/main/scala/tests/scalacli/BaseScalaCLIActionSuite.scala b/tests/slow/src/main/scala/tests/scalacli/BaseScalaCLIActionSuite.scala index 0a393090de0..3fd1e3b930e 100644 --- a/tests/slow/src/main/scala/tests/scalacli/BaseScalaCLIActionSuite.scala +++ b/tests/slow/src/main/scala/tests/scalacli/BaseScalaCLIActionSuite.scala @@ -96,6 +96,7 @@ class BaseScalaCLIActionSuite(name: String) expectError, filterAction, overrideLayout = layout, + isDiagnosticBased = true, ) } } diff --git a/tests/slow/src/test/scala/tests/scalacli/ScalaCliActionsSuite.scala b/tests/slow/src/test/scala/tests/scalacli/ScalaCliActionsSuite.scala index 6663593eb76..e63ebcef013 100644 --- a/tests/slow/src/test/scala/tests/scalacli/ScalaCliActionsSuite.scala +++ b/tests/slow/src/test/scala/tests/scalacli/ScalaCliActionsSuite.scala @@ -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 { | <>.successful(2) @@ -112,7 +118,7 @@ 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 { @@ -120,7 +126,6 @@ class ScalaCliActionsSuite |} |""".stripMargin, scalaCliOptions = List("--actions", "-S", scalaVersion), - expectNoDiagnostics = false, fileName = "A.sc", ) diff --git a/tests/unit/src/main/scala/tests/codeactions/BaseCodeActionLspSuite.scala b/tests/unit/src/main/scala/tests/codeactions/BaseCodeActionLspSuite.scala index 6350030fa41..bd47c68c07b 100644 --- a/tests/unit/src/main/scala/tests/codeactions/BaseCodeActionLspSuite.scala +++ b/tests/unit/src/main/scala/tests/codeactions/BaseCodeActionLspSuite.scala @@ -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) @@ -88,6 +89,7 @@ abstract class BaseCodeActionLspSuite( changeFile, expectError, filterAction, + isDiagnosticBased, ) } @@ -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 @@ -135,6 +138,9 @@ abstract class BaseCodeActionLspSuite( path, changeFile(input).replace("<<", "").replace(">>", ""), ) + _ <- + if (isDiagnosticBased) server.didSave(path)(identity) + else Future.successful(()) codeActions <- server .assertCodeAction(