mirror of
https://github.com/sbt/sbt.git
synced 2026-08-22 14:17:13 +02:00
Improve TestFramework error reporting
It is possible for the test task to fail because of issues with the layered ClassLoaders. When this occurs and is detectable, I try to provide a useful error message that will help the user fix the issue.
This commit is contained in:
@@ -46,6 +46,17 @@ final class TestFramework(val implClassNames: String*) extends Serializable {
|
|||||||
log: ManagedLogger,
|
log: ManagedLogger,
|
||||||
frameworkClassNames: List[String]
|
frameworkClassNames: List[String]
|
||||||
): Option[Framework] = {
|
): 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 / layeringStrategy := new LayeringStrategy.Test(false, true)\nor\n"
|
||||||
|
+ "Test / layeringStrategy := LayeringStrategy.Flat"
|
||||||
|
)
|
||||||
|
None
|
||||||
|
}
|
||||||
frameworkClassNames match {
|
frameworkClassNames match {
|
||||||
case head :: tail =>
|
case head :: tail =>
|
||||||
try {
|
try {
|
||||||
@@ -54,6 +65,8 @@ final class TestFramework(val implClassNames: String*) extends Serializable {
|
|||||||
case oldFramework: OldFramework => new FrameworkWrapper(oldFramework)
|
case oldFramework: OldFramework => new FrameworkWrapper(oldFramework)
|
||||||
})
|
})
|
||||||
} catch {
|
} catch {
|
||||||
|
case e: NoClassDefFoundError => logError(e)
|
||||||
|
case e: MatchError => logError(e)
|
||||||
case _: ClassNotFoundException =>
|
case _: ClassNotFoundException =>
|
||||||
log.debug("Framework implementation '" + head + "' not present.")
|
log.debug("Framework implementation '" + head + "' not present.")
|
||||||
createFramework(loader, log, tail)
|
createFramework(loader, log, tail)
|
||||||
|
|||||||
Reference in New Issue
Block a user