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

Add support for BSP TestParamsData kinds #2360

Merged
merged 3 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 43 additions & 2 deletions frontend/src/main/scala/bloop/bsp/BloopBspServices.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ import bloop.util.JavaRuntime

import com.github.plokhotnyuk.jsoniter_scala.core._
import com.github.plokhotnyuk.jsoniter_scala.macros.JsonCodecMaker
import com.github.plokhotnyuk.jsoniter_scala.core.JsonValueCodec
import jsonrpc4s._
import com.github.plokhotnyuk.jsoniter_scala.core.readFromArray
import monix.execution.Cancelable
import monix.execution.CancelablePromise
import monix.execution.Scheduler
Expand Down Expand Up @@ -711,15 +713,54 @@ final class BloopBspServices(
}

def test(params: bsp.TestParams): BspEndpointResponse[bsp.TestResult] = {
def scalaTestSuitesByKind(kind: String): bsp.ScalaTestSuites =
kind match {
case bsp.TestParamsDataKind.ScalaTest =>
val scalaTestParams: Option[bsp.ScalaTestParams] =
params.data.map(raw => readFromArray[bsp.ScalaTestParams](raw.value))

val suites: List[bsp.ScalaTestSuiteSelection] =
scalaTestParams
.flatMap(
_.testClasses
.map(_.flatMap(item => item.classes))
.map(_.map(cls => bsp.ScalaTestSuiteSelection.apply(cls, Nil)))
)
.getOrElse(Nil)
bsp.ScalaTestSuites(suites, Nil, Nil)

case bsp.TestParamsDataKind.ScalaTestSuites =>
val scalaTestSuites: Option[List[bsp.ScalaTestSuiteSelection]] = params.data
.map { raw =>
readFromArray[List[String]](raw.value)(JsonCodecMaker.make[List[String]])
}
.map(_.map(className => bsp.ScalaTestSuiteSelection(className, Nil)))
bsp.ScalaTestSuites(scalaTestSuites.getOrElse(Nil), Nil, Nil)

case bsp.TestParamsDataKind.ScalaTestSuitesSelection =>
params.data
.map(raw => readFromArray[bsp.ScalaTestSuites](raw.value))
.getOrElse(bsp.ScalaTestSuites(Nil, Nil, Nil))

case _ => bsp.ScalaTestSuites(Nil, Nil, Nil)
}

def test(project: Project, state: State): Task[Tasks.TestRuns] = {
val testFilter = TestInternals.parseFilters(Nil) // Don't support test only for now
val scalaTestSuites: bsp.ScalaTestSuites = params.dataKind match {
case None => bsp.ScalaTestSuites(Nil, Nil, Nil)
case Some(kind) => scalaTestSuitesByKind(kind)
}

val testFilter =
TestInternals.parseFilters(Nil) // Does not handle filtering of tests, yet

val handler = new LoggingEventHandler(state.logger)
Tasks.test(
state,
List(project),
Nil,
testFilter,
bsp.ScalaTestSuites(Nil, Nil, Nil),
scalaTestSuites,
handler,
mode = RunMode.Normal
)
Expand Down
41 changes: 27 additions & 14 deletions frontend/src/main/scala/bloop/engine/tasks/TestTask.scala
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ object TestTask {
val fqn = taskDef.fullyQualifiedName()
!excluded(fqn) && testFilter(fqn)
}

if (logger.isVerbose) {
val allNames = ungroupedTests.map(_.taskDef.fullyQualifiedName).mkString(", ")
val includedNames = includedTests.map(_.taskDef.fullyQualifiedName).mkString(", ")
Expand All @@ -321,21 +322,33 @@ object TestTask {
// 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.suites.map(entry => (entry.className, entry.tests)).toMap
includedTests.groupBy(_.framework).mapValues { taskDefs =>
taskDefs.map {
case TaskDefWithFramework(taskDef, _) =>
selectedTests.get(taskDef.fullyQualifiedName()).getOrElse(Nil) match {
case Nil => taskDef
case selectedTests =>
new TaskDef(
taskDef.fullyQualifiedName(),
taskDef.fingerprint(),
false,
selectedTests.map(test => new TestSelector(test)).toList.toArray
)
}

val testsToRun =
if (testClasses.suites.nonEmpty) {
includedTests
.filter(t => testClasses.suites.map(_.className).contains(t.taskDef.fullyQualifiedName))
} else {
includedTests
}

testsToRun
.groupBy(_.framework)
.mapValues { taskDefs =>
taskDefs.map {
case TaskDefWithFramework(taskDef, _) =>
selectedTests.get(taskDef.fullyQualifiedName()) match {
case None =>
taskDef
case Some(value) =>
new TaskDef(
taskDef.fullyQualifiedName(),
taskDef.fingerprint(),
false,
value.map(test => new TestSelector(test)).toList.toArray
)
}
}
}
}
}

private[bloop] def discoverTests(
Expand Down
Loading
Loading