Skip to content

Commit

Permalink
chore: adjust scala test suites to sbt's implementation. (#1699)
Browse files Browse the repository at this point in the history
Related PR can be found here scalacenter/scala-debug-adapter#198
  • Loading branch information
kpodsiad authored Mar 11, 2022
1 parent af59e70 commit 1b6633a
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 33 deletions.
6 changes: 3 additions & 3 deletions frontend/src/main/scala/bloop/bsp/BloopBspServices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

Expand Down
10 changes: 5 additions & 5 deletions frontend/src/main/scala/bloop/dap/BloopDebuggeeRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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],
Expand All @@ -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"
Expand All @@ -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(
Expand Down Expand Up @@ -155,7 +155,7 @@ object BloopDebuggeeRunner {

def forTestSuite(
projects: Seq[Project],
testClasses: ScalaTestClasses,
testClasses: ScalaTestSuites,
state: State,
ioScheduler: Scheduler
): Either[String, DebuggeeRunner] = {
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/main/scala/bloop/engine/Interpreter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -360,7 +360,7 @@ object Interpreter {
projectsToTest,
cmd.args,
testFilter,
ScalaTestClasses.empty,
ScalaTestSuites.empty,
handler,
cmd.parallel,
RunMode.Normal
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/main/scala/bloop/engine/tasks/Tasks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/main/scala/bloop/engine/tasks/TestTask.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -43,7 +43,7 @@ object TestTask {
cwd: AbsolutePath,
rawTestOptions: List[String],
testFilter: String => Boolean,
testClasses: ScalaTestClasses,
testClasses: ScalaTestSuites,
handler: LoggingEventHandler,
mode: RunMode
): Task[Int] = {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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) =>
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/test/scala/bloop/dap/DebugServerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -818,15 +818,15 @@ object DebugServerSpec extends DebugBspBaseSuite {

loadBspState(workspace, List(project), logger) { state =>
val testClasses =
ScalaTestClasses(
ScalaTestSuites(
List(
ScalaTestSuiteSelection(
"MySuite",
List("test1")
)
),
List("-Xmx512M"),
Map("ENV_KEY" -> "ENV_VALUE")
List("ENV_KEY=ENV_VALUE")
)
val runner = testRunner(project, state, testClasses)

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 1b6633a

Please sign in to comment.