All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.zegreatrob.testmints.TestTemplate.kt Maven / Gradle / Ivy

There is a newer version: 12.1.30
Show newest version
package com.zegreatrob.testmints

import com.zegreatrob.testmints.report.ReporterProvider

class TestTemplate(val reporterProvider: ReporterProvider, val wrapper: (TestFunc) -> Unit) {

    fun  extend(wrapper: (SC, TestFunc) -> Unit) = TestTemplate(reporterProvider) { test ->
        this.wrapper { sc1 -> wrapper(sc1, test) }
    }

    fun  extend(sharedSetup: (SC) -> SC2, sharedTeardown: (SC2) -> Unit = {}) = extend { sc1, test ->
        val sc2 = sharedSetup(sc1)
        test(sc2)
        sharedTeardown(sc2)
    }

    fun extend(sharedSetup: () -> Unit = {}, sharedTeardown: () -> Unit = {}) = TestTemplate(
        reporterProvider,
    ) { test ->
        wrapper {
            sharedSetup()
            test(it)
            sharedTeardown()
        }
    }

    fun  extend(beforeAll: () -> BAC): TestTemplate = extend(
        beforeAll = beforeAll,
        mergeContext = { _, bac -> bac },
    )

    fun  extend(beforeAll: () -> BAC, mergeContext: (SC, BAC) -> SC2): TestTemplate {
        val lazy by lazy { beforeAll() }
        return TestTemplate(reporterProvider) { test -> wrapper { sc -> test(mergeContext(sc, lazy)) } }
    }

    operator fun  invoke(contextProvider: (SC) -> C, additionalSetupActions: C.() -> Unit = {}) =
        Setup(contextProvider, reporterProvider.reporter, additionalSetupActions, wrapper)

    operator fun  invoke(
        context: C,
        additionalSetupActions: C.() -> Unit = {},
    ) = Setup({ context }, reporterProvider.reporter, additionalSetupActions, wrapper)

    operator fun invoke(additionalSetupActions: SC.() -> Unit = {}): Setup =
        Setup({ it }, reporterProvider.reporter, additionalSetupActions, wrapper)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy