Skip to content

Commit

Permalink
Merge pull request sbt#6806 from eed3si9n/wip/test_framework
Browse files Browse the repository at this point in the history
[1.6.x] Throw when test framework cannot be loaded due to MatchError or NoClassDefFoundError
  • Loading branch information
eed3si9n authored Jan 31, 2022
2 parents 0518ede + a549e79 commit ca0fd3d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import scala.util.Try
// ThisBuild settings take lower precedence,
// but can be shared across the multi projects.
ThisBuild / version := {
val v = "1.6.0-SNAPSHOT"
val v = "1.6.2-SNAPSHOT"
nightlyVersion.getOrElse(v)
}
ThisBuild / version2_13 := "2.0.0-SNAPSHOT"
Expand Down
2 changes: 1 addition & 1 deletion sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

set +e
declare builtin_sbt_version="1.6.0"
declare builtin_sbt_version="1.6.1"
declare -a residual_args
declare -a java_args
declare -a scalac_args
Expand Down
22 changes: 14 additions & 8 deletions testing/src/main/scala/sbt/TestFramework.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ final class TestFramework(val implClassNames: String*) extends Serializable {
): Option[Framework] = {
def logError(e: Throwable): Option[Framework] = {
log.error(
s"Error loading test framework ($e). This usually means that you are"
+ " using a layered class loader that cannot reach the sbt.testing.Framework class."
+ " The most likely cause is that your project has a runtime dependency on your"
+ " test framework, e.g. scalatest. To fix this, you can try to set\n"
+ "Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.ScalaLibrary\nor\n"
+ "Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Flat"
s"""Error loading test framework ($e).
|This often means that you are using a layered class loader that cannot reach the sbt.testing.Framework class.
|The most likely cause is that your project has a runtime dependency on your
|test framework, e.g. ScalaTest. To fix this, you can try to set
|
| Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.ScalaLibrary
|or
| Test / classLoaderLayeringStrategy := ClassLoaderLayeringStrategy.Flat""".stripMargin
)
None
}
Expand All @@ -66,8 +68,12 @@ final class TestFramework(val implClassNames: String*) extends Serializable {
case oldFramework: OldFramework => new FrameworkWrapper(oldFramework)
})
} catch {
case e: NoClassDefFoundError => logError(e)
case e: MatchError => logError(e)
case e: NoClassDefFoundError =>
logError(e)
throw e
case e: MatchError =>
logError(e)
throw e
case _: ClassNotFoundException =>
log.debug("Framework implementation '" + head + "' not present.")
createFramework(loader, log, tail)
Expand Down

0 comments on commit ca0fd3d

Please sign in to comment.