Merge pull request #6806 from eed3si9n/wip/test_framework

[1.6.x] Throw when test framework cannot be loaded due to MatchError or NoClassDefFoundError
This commit is contained in:
eugene yokota 2022-01-31 17:13:51 -05:00 committed by GitHub
commit ca0fd3db8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 10 deletions

View File

@ -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"

2
sbt
View File

@ -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

View File

@ -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
}
@ -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)