Skip to content

Commit

Permalink
Make MinutestRootContextBuilder a LateContextBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
dmcg committed May 1, 2019
1 parent f97520b commit 8fbbfba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import dev.minutest.experimental.transformedBy
/**
* A [NodeBuilder] that captures markers and transforms applied by prefix [TestAnnotation]s.
*/
internal data class LateContextBuilder<PF, F>(
private val delegate: MinutestContextBuilder<PF, F>,
private val builder: TestContextBuilder<PF, F>.() -> Unit
internal open class LateContextBuilder<PF, F>(
protected val delegate: MinutestContextBuilder<PF, F>,
protected val builder: TestContextBuilder<PF, F>.() -> Unit
) : NodeBuilder<PF> by delegate {

constructor(
Expand All @@ -20,14 +20,10 @@ internal data class LateContextBuilder<PF, F>(
) : this(MinutestContextBuilder(name, type, fixtureFactory), builder)

override fun buildNode(): Node<PF> = delegate.apply(builder).buildNode()

fun withName(newName: String) = copy(delegate = delegate.copy(name = newName))
}

/**
* Internal implementation of [TestContextBuilder] which hides the details and the [NodeBuilder]ness.
*/

internal data class MinutestContextBuilder<PF, F>(
val name: String,
private val type: FixtureType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,29 @@ import dev.minutest.*
import dev.minutest.experimental.transformedBy

/**
* A [NodeBuilder] for root contexts that finds and applies [RootTransform]s.
*
* This delegates to [LateContextBuilder] rather than inherits because it's the easiest way to cope with [withName].
* A [LateContextBuilder] for root contexts that finds and applies [RootTransform]s.
*/
internal data class MinutestRootContextBuilder<F>(
private val delegate: LateContextBuilder<Unit, F>
) : NodeBuilder<Unit> by delegate, RootContextBuilder {
internal class MinutestRootContextBuilder<F>(
delegate: MinutestContextBuilder<Unit, F>,
builder: TestContextBuilder<Unit, F>.() -> Unit
) : LateContextBuilder<Unit, F>(delegate, builder), RootContextBuilder {

constructor(
name: String,
type: FixtureType,
builder: TestContextBuilder<Unit, F>.() -> Unit
) : this(LateContextBuilder<Unit, F>(name, type, rootFixtureFactoryHack(), builder))
) : this(MinutestContextBuilder(name, type, rootFixtureFactoryHack()), builder)

override fun buildNode(): Node<Unit> {
val rootContext = delegate.buildNode()
val rootContext = super.buildNode()
val deduplicatedTransformsInTree = rootContext.findRootTransforms().toSet()
return rootContext.transformedBy(deduplicatedTransformsInTree)
}

override fun withName(newName: String) = copy(delegate = delegate.withName(newName))
override fun withName(newName: String) = MinutestRootContextBuilder(
delegate.copy(name = newName),
builder
)
}

// TODO - this should probably be breadth-first
Expand Down

0 comments on commit 8fbbfba

Please sign in to comment.