Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit df59dc6

Browse files
authoredJan 20, 2022
use composition in runner to avoid double lazy initialization when ru… (#1336)
* use composition in runner to avoid double lazy initialization when running certain tests
1 parent 9d0d4f9 commit df59dc6

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed
 

‎src/java/io/bazel/rulesscala/specs2/Specs2RunnerBuilder.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import org.specs2.control.Action
1111
import org.specs2.fp.Tree.Node
1212
import org.specs2.fp.{Tree, TreeLoc}
1313
import org.specs2.main.{Arguments, CommandLine, Select}
14-
import org.specs2.specification.core.{Env, Fragment, SpecStructure}
14+
import org.specs2.specification.core.{Env, Fragment, SpecStructure, SpecificationStructure}
1515
import org.specs2.specification.process.Stats
1616

1717
import java.util
@@ -48,14 +48,17 @@ class Specs2PrefixSuffixTestDiscoveringSuite(suite: Class[Any], runnerBuilder: R
4848

4949
object Specs2FilteringRunnerBuilder {
5050
val f: FilteringRunnerBuilder = {
51-
case (_: org.specs2.runner.JUnitRunner, testClass: Class[_], pattern: Pattern) =>
52-
new FilteredSpecs2ClassRunner(testClass, pattern)
51+
case (parentRunner: org.specs2.runner.JUnitRunner, testClass: Class[_], pattern: Pattern) =>
52+
new FilteredSpecs2ClassRunner(parentRunner, testClass, pattern)
5353
}
5454
}
5555

56-
class FilteredSpecs2ClassRunner(testClass: Class[_], testFilter: Pattern)
56+
class FilteredSpecs2ClassRunner(parentRunner: org.specs2.runner.JUnitRunner, testClass: Class[_], testFilter: Pattern)
5757
extends org.specs2.runner.JUnitRunner(testClass) {
5858

59+
//taking it from parent so not to initialize test classes multiple times
60+
override lazy val specification: SpecificationStructure = parentRunner.specification
61+
5962
override def getDescription(env: Env): Description = {
6063
try createFilteredDescription(specStructure, env.specs2ExecutionEnv)
6164
catch { case NonFatal(t) => env.shutdown; throw t; }

0 commit comments

Comments
 (0)
Please sign in to comment.