/
FreeSpecRootContext.kt
59 lines (52 loc) · 1.82 KB
/
FreeSpecRootContext.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package io.kotest.core.spec.style.scopes
import io.kotest.core.Tag
import io.kotest.core.extensions.TestCaseExtension
import io.kotest.core.spec.KotestDsl
import io.kotest.core.test.EnabledIf
import io.kotest.core.test.TestCaseSeverityLevel
import io.kotest.core.test.TestContext
import io.kotest.core.test.createTestName
import io.kotest.core.test.deriveTestCaseConfig
import kotlin.time.Duration
@Deprecated("Renamed to FreeSpecRootContext. This typealias will be removed in 4.8")
typealias FreeSpecRootScope = FreeSpecRootContext
@KotestDsl
interface FreeSpecRootContext : RootContext {
// eg, "this test" - { } // adds a container test
infix operator fun String.minus(test: suspend FreeSpecContainerContext.() -> Unit) {
val name = createTestName(this)
registration().addContainerTest(name, xdisabled = false) {
FreeSpecContainerContext(this).test()
}
}
// "this test" { } // adds a leaf test
infix operator fun String.invoke(test: suspend TestContext.() -> Unit) {
registration().addTest(createTestName(this), xdisabled = false, test = test)
}
// adds a leaf test with config
fun String.config(
enabled: Boolean? = null,
invocations: Int? = null,
threads: Int? = null,
tags: Set<Tag>? = null,
timeout: Duration? = null,
extensions: List<TestCaseExtension>? = null,
enabledIf: EnabledIf? = null,
invocationTimeout: Duration? = null,
severity: TestCaseSeverityLevel? = null,
test: suspend TestContext.() -> Unit
) {
val config = defaultConfig().deriveTestCaseConfig(
enabled,
tags,
extensions,
timeout,
invocationTimeout,
enabledIf,
invocations,
threads,
severity
)
registration().addTest(createTestName(this), false, config, test)
}
}