Skip to content

Commit

Permalink
Instantiate suites eagerly in SBT Framework - just as in Runner
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-kai committed Jan 22, 2024
1 parent 310197b commit 0599cf4
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions jvm/core/src/main/scala/org/scalatest/tools/Framework.scala
Expand Up @@ -413,12 +413,30 @@ class Framework extends SbtFramework {
}
}

lazy val suiteClass = loadSuiteClass
lazy val accessible = isAccessibleSuite(suiteClass)
lazy val runnable = isRunnable(suiteClass)
lazy val shouldDiscover =
val suiteClass = loadSuiteClass
val accessible = isAccessibleSuite(suiteClass)
val runnable = isRunnable(suiteClass)
val shouldDiscover =
taskDefinition.explicitlySpecified || ((accessible || runnable) && isDiscoverableSuite(suiteClass))

val suite =
try {
if (runnable) { // When it is runnable WrapWith is available, this will take precedence and this behavior will be consistent with Runner and the old ScalaTestFramework.
val wrapWithAnnotation = suiteClass.getAnnotation(classOf[WrapWith])
val suiteClazz = wrapWithAnnotation.value
val constructorList = suiteClazz.getDeclaredConstructors()
val constructor = constructorList.find { c =>
val types = c.getParameterTypes
types.length == 1 && types(0) == classOf[java.lang.Class[_]]
}
constructor.get.newInstance(suiteClass).asInstanceOf[Suite]
}
else
suiteClass.newInstance.asInstanceOf[Suite]
} catch {
case t: Throwable => new DeferredAbortedSuite(suiteClass.getName, suiteClass.getName, t)
}

def tags =
for {
a <- suiteClass.getAnnotations
Expand All @@ -438,24 +456,6 @@ class Framework extends SbtFramework {

def execute(eventHandler: EventHandler, loggers: Array[Logger]) = {
if (accessible || runnable) {
val suite =
try {
if (runnable) { // When it is runnable WrapWith is available, this will take precedence and this behavior will be consistent with Runner and the old ScalaTestFramework.
val wrapWithAnnotation = suiteClass.getAnnotation(classOf[WrapWith])
val suiteClazz = wrapWithAnnotation.value
val constructorList = suiteClazz.getDeclaredConstructors()
val constructor = constructorList.find { c =>
val types = c.getParameterTypes
types.length == 1 && types(0) == classOf[java.lang.Class[_]]
}
constructor.get.newInstance(suiteClass).asInstanceOf[Suite]
}
else
suiteClass.newInstance.asInstanceOf[Suite]
} catch {
case t: Throwable => new DeferredAbortedSuite(suiteClass.getName, suiteClass.getName, t)
}

if (useSbtLogInfoReporter) {
val sbtLogInfoReporter =
new FilterReporter(
Expand Down

0 comments on commit 0599cf4

Please sign in to comment.