From 1b6633ae67ce0ba508caa947cf88b3daf459ee96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Podsiad=C5=82o?= <37124721+kpodsiad@users.noreply.github.com> Date: Fri, 11 Mar 2022 11:26:05 +0100 Subject: [PATCH] chore: adjust scala test suites to sbt's implementation. (#1699) Related PR can be found here https://github.com/scalacenter/scala-debug-adapter/pull/198 --- .../scala/bloop/bsp/BloopBspServices.scala | 6 ++--- ...estClasses.scala => ScalaTestSuites.scala} | 24 +++++++++---------- .../scala/bloop/dap/BloopDebuggeeRunner.scala | 10 ++++---- .../main/scala/bloop/engine/Interpreter.scala | 4 ++-- .../main/scala/bloop/engine/tasks/Tasks.scala | 4 ++-- .../scala/bloop/engine/tasks/TestTask.scala | 10 ++++---- .../scala/bloop/dap/DebugServerSpec.scala | 8 +++---- 7 files changed, 33 insertions(+), 33 deletions(-) rename frontend/src/main/scala/bloop/bsp/{ScalaTestClasses.scala => ScalaTestSuites.scala} (60%) diff --git a/frontend/src/main/scala/bloop/bsp/BloopBspServices.scala b/frontend/src/main/scala/bloop/bsp/BloopBspServices.scala index becf0afef7..1b39e678ff 100644 --- a/frontend/src/main/scala/bloop/bsp/BloopBspServices.scala +++ b/frontend/src/main/scala/bloop/bsp/BloopBspServices.scala @@ -593,12 +593,12 @@ final class BloopBspServices( case bsp.DebugSessionParamsDataKind.ScalaTestSuites => convert[List[String]]( classNames => { - val testClasses = ScalaTestClasses(classNames) + val testClasses = ScalaTestSuites(classNames) BloopDebuggeeRunner.forTestSuite(projects, testClasses, state, ioScheduler) } ) case "scala-test-selection" => - convert[ScalaTestClasses]( + convert[ScalaTestSuites]( testClasses => { BloopDebuggeeRunner.forTestSuite(projects, testClasses, state, ioScheduler) } @@ -668,7 +668,7 @@ final class BloopBspServices( ): Task[State] = { val testFilter = TestInternals.parseFilters(Nil) // Don't support test only for now val handler = new BspLoggingEventHandler(id, state.logger, client) - Tasks.test(state, List(project), Nil, testFilter, ScalaTestClasses.empty, handler, mode = RunMode.Normal) + Tasks.test(state, List(project), Nil, testFilter, ScalaTestSuites.empty, handler, mode = RunMode.Normal) } val originId = params.originId diff --git a/frontend/src/main/scala/bloop/bsp/ScalaTestClasses.scala b/frontend/src/main/scala/bloop/bsp/ScalaTestSuites.scala similarity index 60% rename from frontend/src/main/scala/bloop/bsp/ScalaTestClasses.scala rename to frontend/src/main/scala/bloop/bsp/ScalaTestSuites.scala index a053e21025..28232fa475 100644 --- a/frontend/src/main/scala/bloop/bsp/ScalaTestClasses.scala +++ b/frontend/src/main/scala/bloop/bsp/ScalaTestSuites.scala @@ -9,29 +9,29 @@ import io.circe.Encoder /** * Below datatypes are based on https://github.com/build-server-protocol/build-server-protocol/issues/249#issuecomment-983435766 */ -case class ScalaTestClasses( - classes: List[ScalaTestSuiteSelection], +case class ScalaTestSuites( + suites: List[ScalaTestSuiteSelection], jvmOptions: List[String], - env: Map[String, String], + environmentVariables: List[String], ) { - def classNames: List[String] = classes.map(_.className) + def classNames: List[String] = suites.map(_.className) } -object ScalaTestClasses { - implicit val decoder: Decoder[ScalaTestClasses] = deriveDecoder - implicit val encoder: Encoder[ScalaTestClasses] = deriveEncoder - val empty: ScalaTestClasses = ScalaTestClasses(Nil, Nil, Map.empty) +object ScalaTestSuites { + implicit val decoder: Decoder[ScalaTestSuites] = deriveDecoder + implicit val encoder: Encoder[ScalaTestSuites] = deriveEncoder + val empty: ScalaTestSuites = ScalaTestSuites(Nil, Nil, Nil) - def apply(classes: List[String]): ScalaTestClasses = ScalaTestClasses( + def apply(classes: List[String]): ScalaTestSuites = ScalaTestSuites( classes.map(className => ScalaTestSuiteSelection(className, Nil)), Nil, - Map.empty + Nil ) - def forSuiteSelection(classes: List[ScalaTestSuiteSelection]): ScalaTestClasses = ScalaTestClasses( + def forSuiteSelection(classes: List[ScalaTestSuiteSelection]): ScalaTestSuites = ScalaTestSuites( classes, Nil, - Map.empty + Nil ) } diff --git a/frontend/src/main/scala/bloop/dap/BloopDebuggeeRunner.scala b/frontend/src/main/scala/bloop/dap/BloopDebuggeeRunner.scala index c6eb1329f0..4f839713c7 100644 --- a/frontend/src/main/scala/bloop/dap/BloopDebuggeeRunner.scala +++ b/frontend/src/main/scala/bloop/dap/BloopDebuggeeRunner.scala @@ -16,7 +16,7 @@ import monix.execution.Scheduler import java.net.URLClassLoader import scala.collection.mutable import java.nio.file.Path -import bloop.bsp.ScalaTestClasses +import bloop.bsp.ScalaTestSuites abstract class BloopDebuggeeRunner(initialState: State, ioScheduler: Scheduler) extends DebuggeeRunner { @@ -69,7 +69,7 @@ private final class MainClassDebugAdapter( private final class TestSuiteDebugAdapter( projects: Seq[Project], - testClasses: ScalaTestClasses, + testClasses: ScalaTestSuites, val classPathEntries: Seq[ClassPathEntry], val javaRuntime: Option[JavaRuntime], val evaluationClassLoader: Option[ClassLoader], @@ -79,7 +79,7 @@ private final class TestSuiteDebugAdapter( ) extends BloopDebuggeeRunner(initialState, ioScheduler) { override def name: String = { val projectsStr = projects.map(_.bspUri).mkString("[", ", ", "]") - val selectedTests = testClasses.classes + val selectedTests = testClasses.suites .map { suite => val tests = suite.tests.mkString("(", ",", ")") s"${suite.className}$tests" @@ -88,7 +88,7 @@ private final class TestSuiteDebugAdapter( s"${getClass.getSimpleName}($projectsStr, $selectedTests)" } override def start(state: State, listener: DebuggeeListener): Task[ExitStatus] = { - val filter = TestInternals.parseFilters(testClasses.classes.map(_.className)) + val filter = TestInternals.parseFilters(testClasses.suites.map(_.className)) val handler = new DebugLoggingEventHandler(state.logger, listener) val task = Tasks.test( @@ -155,7 +155,7 @@ object BloopDebuggeeRunner { def forTestSuite( projects: Seq[Project], - testClasses: ScalaTestClasses, + testClasses: ScalaTestSuites, state: State, ioScheduler: Scheduler ): Either[String, DebuggeeRunner] = { diff --git a/frontend/src/main/scala/bloop/engine/Interpreter.scala b/frontend/src/main/scala/bloop/engine/Interpreter.scala index 94aa20bb78..4d38ec34d0 100644 --- a/frontend/src/main/scala/bloop/engine/Interpreter.scala +++ b/frontend/src/main/scala/bloop/engine/Interpreter.scala @@ -25,7 +25,7 @@ import bloop.ScalaInstance import scala.collection.immutable.Nil import scala.annotation.tailrec import java.io.IOException -import bloop.bsp.ScalaTestClasses +import bloop.bsp.ScalaTestSuites object Interpreter { // This is stack-safe because of Monix's trampolined execution @@ -360,7 +360,7 @@ object Interpreter { projectsToTest, cmd.args, testFilter, - ScalaTestClasses.empty, + ScalaTestSuites.empty, handler, cmd.parallel, RunMode.Normal diff --git a/frontend/src/main/scala/bloop/engine/tasks/Tasks.scala b/frontend/src/main/scala/bloop/engine/tasks/Tasks.scala index a81fb93d82..0d96aa49bd 100644 --- a/frontend/src/main/scala/bloop/engine/tasks/Tasks.scala +++ b/frontend/src/main/scala/bloop/engine/tasks/Tasks.scala @@ -17,7 +17,7 @@ import sbt.internal.inc.{Analysis, AnalyzingCompiler, ConcreteAnalysisContents, import sbt.internal.inc.classpath.ClasspathUtilities import sbt.testing._ import xsbti.compile.{ClasspathOptionsUtil, CompileAnalysis, MiniSetup, PreviousResult} -import bloop.bsp.ScalaTestClasses +import bloop.bsp.ScalaTestSuites import sbt.internal.inc.PlainVirtualFileConverter import sbt.internal.inc.classpath.ClasspathUtil @@ -105,7 +105,7 @@ object Tasks { projectsToTest: List[Project], userTestOptions: List[String], testFilter: String => Boolean, - testClasses: ScalaTestClasses, + testClasses: ScalaTestSuites, testEventHandler: BloopTestSuiteEventHandler, runInParallel: Boolean = false, mode: RunMode diff --git a/frontend/src/main/scala/bloop/engine/tasks/TestTask.scala b/frontend/src/main/scala/bloop/engine/tasks/TestTask.scala index aaba4fe086..6023ced852 100644 --- a/frontend/src/main/scala/bloop/engine/tasks/TestTask.scala +++ b/frontend/src/main/scala/bloop/engine/tasks/TestTask.scala @@ -19,7 +19,7 @@ import xsbti.compile.CompileAnalysis import scala.util.control.NonFatal import scala.util.{Failure, Success} -import bloop.bsp.ScalaTestClasses +import bloop.bsp.ScalaTestSuites object TestTask { implicit private val logContext: DebugFilter = DebugFilter.Test @@ -43,7 +43,7 @@ object TestTask { cwd: AbsolutePath, rawTestOptions: List[String], testFilter: String => Boolean, - testClasses: ScalaTestClasses, + testClasses: ScalaTestSuites, handler: LoggingEventHandler, mode: RunMode ): Task[Int] = { @@ -95,7 +95,7 @@ object TestTask { val discoveredFrameworks = suites.iterator.filterNot(_._2.isEmpty).map(_._1).toList val (userJvmOptions, userTestOptions) = rawTestOptions.partition(_.startsWith("-J")) val jvmOptions = userJvmOptions.map(_.stripPrefix("-J")) ++ testClasses.jvmOptions - val envOptions = testClasses.env.map { case (key, value) => s"$key=$value" }.toList + val envOptions = testClasses.environmentVariables val frameworkArgs = considerFrameworkArgs(discoveredFrameworks, userTestOptions, logger) val args = project.testOptions.arguments ++ frameworkArgs logger.debug(s"Running test suites with arguments: $args") @@ -263,7 +263,7 @@ object TestTask { frameworks: List[Framework], analysis: CompileAnalysis, testFilter: String => Boolean, - testClasses: ScalaTestClasses + testClasses: ScalaTestSuites ): Map[Framework, List[TaskDef]] = { import state.logger val tests = discoverTests(analysis, frameworks) @@ -290,7 +290,7 @@ object TestTask { // selectors is a possibly empty array of selectors which determines suites and tests to run // usually it is a Array(new SuiteSelector). However, if only subset of test are supposed to // be run, then it can be altered to Array[TestSelector] - val selectedTests = testClasses.classes.map(entry => (entry.className, entry.tests)).toMap + val selectedTests = testClasses.suites.map(entry => (entry.className, entry.tests)).toMap includedTests.groupBy(_.framework).mapValues { taskDefs => taskDefs.map { case TaskDefWithFramework(taskDef, framework) => diff --git a/frontend/src/test/scala/bloop/dap/DebugServerSpec.scala b/frontend/src/test/scala/bloop/dap/DebugServerSpec.scala index e6212e6aa4..d228162394 100644 --- a/frontend/src/test/scala/bloop/dap/DebugServerSpec.scala +++ b/frontend/src/test/scala/bloop/dap/DebugServerSpec.scala @@ -27,7 +27,7 @@ import java.util.concurrent.TimeUnit.{MILLISECONDS, SECONDS} import scala.collection.mutable import scala.concurrent.duration.{Duration, FiniteDuration} import scala.concurrent.{Future, Promise, TimeoutException} -import bloop.bsp.ScalaTestClasses +import bloop.bsp.ScalaTestSuites import bloop.bsp.ScalaTestSuiteSelection object DebugServerSpec extends DebugBspBaseSuite { @@ -818,7 +818,7 @@ object DebugServerSpec extends DebugBspBaseSuite { loadBspState(workspace, List(project), logger) { state => val testClasses = - ScalaTestClasses( + ScalaTestSuites( List( ScalaTestSuiteSelection( "MySuite", @@ -826,7 +826,7 @@ object DebugServerSpec extends DebugBspBaseSuite { ) ), List("-Xmx512M"), - Map("ENV_KEY" -> "ENV_VALUE") + List("ENV_KEY=ENV_VALUE") ) val runner = testRunner(project, state, testClasses) @@ -954,7 +954,7 @@ object DebugServerSpec extends DebugBspBaseSuite { private def testRunner( project: TestProject, state: ManagedBspTestState, - testClasses: ScalaTestClasses = ScalaTestClasses(List("MySuite")) + testClasses: ScalaTestSuites = ScalaTestSuites(List("MySuite")) ): DebuggeeRunner = { val testState = state.compile(project).toTestState BloopDebuggeeRunner.forTestSuite(