Skip to content

Commit

Permalink
Updated test-only functionality for no matching tests
Browse files Browse the repository at this point in the history
If no tests-suites in the project match the specified test suites
provided by the user no tests will run at all. If any of the tests
match, but not all the matching tests will run.
  • Loading branch information
KristianAN committed Aug 7, 2024
1 parent f136253 commit 8a94a46
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
46 changes: 28 additions & 18 deletions bleep-core/src/scala/bleep/commands/Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import scala.jdk.CollectionConverters.*

import bloop.rifle.BuildServer
import cats.data.NonEmptyList
import bleep.BleepException.TestSuitesNotFound

case class Test(watch: Boolean, projects: Array[model.CrossProjectName], testSuites: Option[NonEmptyList[String]])
extends BleepCommandRemote(watch)
Expand Down Expand Up @@ -36,26 +37,35 @@ case class Test(watch: Boolean, projects: Array[model.CrossProjectName], testSui

val testParams = new bsp4j.TestParams(targets)

testSuites.foreach { classes =>
val testClassesData = new bsp4j.ScalaTestSuites(
intersectTestSuites(testClasses, classes.toList)
.map(cls => new bsp4j.ScalaTestSuiteSelection(cls, List.empty[String].asJava))
.asJava,
List.empty[String].asJava,
List.empty[String].asJava
)
testParams.setData(testClassesData)
testParams.setDataKind(bsp4j.TestParamsDataKind.SCALA_TEST_SUITES_SELECTION)
}
val hasSuites: Boolean = testSuites
.map { classes =>
val testClassesData = new bsp4j.ScalaTestSuites(
intersectTestSuites(testClasses, classes.toList)
.map(cls => new bsp4j.ScalaTestSuiteSelection(cls, List.empty[String].asJava))
.asJava,
List.empty[String].asJava,
List.empty[String].asJava
)
testParams.setData(testClassesData)
testParams.setDataKind(bsp4j.TestParamsDataKind.SCALA_TEST_SUITES_SELECTION)

!testClassesData.getSuites().isEmpty
}
.getOrElse(true)

val result = bloop.buildTargetTest(testParams).get()
if (hasSuites) {
val result = bloop.buildTargetTest(testParams).get()

result.getStatusCode match {
case bsp4j.StatusCode.OK =>
started.logger.info("Tests succeeded")
Right(())
case errorCode =>
Left(new BspCommandFailed("tests", projects, BspCommandFailed.StatusCode(errorCode)))
result.getStatusCode match {
case bsp4j.StatusCode.OK =>
started.logger.info("Tests succeeded")
Right(())
case errorCode =>
println(errorCode)
Left(new BspCommandFailed("tests", projects, BspCommandFailed.StatusCode(errorCode)))
}
} else {
Left(new TestSuitesNotFound(testSuites.map(_.toList).getOrElse(List.empty[String])))
}
}
}
2 changes: 2 additions & 0 deletions bleep-model/src/scala/bleep/BleepException.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ abstract class BleepException(
object BleepException {
class BuildNotFound(cwd: Path) extends BleepException(s"Couldn't find ${BuildLoader.BuildFileName} in directories in or above $cwd")

class TestSuitesNotFound(suites: List[String]) extends BleepException(s"None of the given test suites: ${suites.mkString(", ")} were found in the project")

class TargetFolderNotDetermined(projectName: model.CrossProjectName)
extends BleepException(s"Couldn't determine original output directory of project ${projectName.name}")

Expand Down

0 comments on commit 8a94a46

Please sign in to comment.