-
Notifications
You must be signed in to change notification settings - Fork 26
[TS] Test factory DSL #320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c3f2332
Rewrite test factory DSL
Lipen 9ed4cc7
Local jacodb
Lipen 3a6940f
Local jacodb on CI
Lipen 0b80323
Bump jacodb
Lipen d8d0b80
Tag manual tests
Lipen 47d3a60
Add instructions for getting SDK
Lipen 38e5c3c
Remove typescript SDK
Lipen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
401 changes: 198 additions & 203 deletions
401
usvm-ts-dataflow/src/test/kotlin/org/usvm/dataflow/ts/test/EtsTypeInferenceTest.kt
Large diffs are not rendered by default.
Oops, something went wrong.
83 changes: 54 additions & 29 deletions
83
usvm-ts-dataflow/src/testFixtures/kotlin/org/usvm/dataflow/ts/TestFactoryDsl.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,52 +1,77 @@ | ||
| package org.usvm.dataflow.ts | ||
|
|
||
| import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
| import kotlinx.coroutines.channels.Channel | ||
| import org.junit.jupiter.api.DynamicContainer | ||
| import org.junit.jupiter.api.DynamicNode | ||
| import org.junit.jupiter.api.DynamicTest | ||
| import org.junit.jupiter.api.function.Executable | ||
| import java.util.stream.Stream | ||
|
|
||
| private interface TestProvider { | ||
| fun test(name: String, test: () -> Unit) | ||
| } | ||
|
|
||
| private interface ContainerProvider { | ||
| fun container(name: String, init: TestContainerBuilder.() -> Unit) | ||
| } | ||
| @DslMarker | ||
| annotation class TestFactoryDsl | ||
|
|
||
| class TestContainerBuilder(var name: String) : TestProvider, ContainerProvider { | ||
| private val nodes: MutableList<DynamicNode> = mutableListOf() | ||
| @TestFactoryDsl | ||
| abstract class TestNodeBuilder { | ||
| private val nodeChannel = Channel<() -> DynamicNode>(Channel.UNLIMITED) | ||
|
|
||
| override fun test(name: String, test: () -> Unit) { | ||
| nodes += dynamicTest(name, test) | ||
| fun test(name: String, test: () -> Unit) { | ||
| nodeChannel.trySend { dynamicTest(name, test) } | ||
| } | ||
|
|
||
| override fun container(name: String, init: TestContainerBuilder.() -> Unit) { | ||
| nodes += containerBuilder(name, init) | ||
| fun container(name: String, init: TestContainerBuilder.() -> Unit) { | ||
| nodeChannel.trySend { dynamicContainer(name, init) } | ||
| } | ||
|
|
||
| fun build(): DynamicContainer = DynamicContainer.dynamicContainer(name, nodes) | ||
| } | ||
| protected fun createNodes(): Iterable<DynamicNode> = | ||
| Iterable { DynamicNodeIterator() } | ||
|
|
||
| private fun containerBuilder(name: String, init: TestContainerBuilder.() -> Unit): DynamicContainer = | ||
| TestContainerBuilder(name).apply(init).build() | ||
| private inner class DynamicNodeIterator : Iterator<DynamicNode> { | ||
| @OptIn(ExperimentalCoroutinesApi::class) | ||
| override fun hasNext(): Boolean = !nodeChannel.isEmpty | ||
|
|
||
| class TestFactoryBuilder : TestProvider, ContainerProvider { | ||
| private val nodes: MutableList<DynamicNode> = mutableListOf() | ||
|
|
||
| override fun test(name: String, test: () -> Unit) { | ||
| nodes += dynamicTest(name, test) | ||
| override fun next(): DynamicNode { | ||
| val node = nodeChannel.tryReceive().getOrThrow() | ||
| return node() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override fun container(name: String, init: TestContainerBuilder.() -> Unit) { | ||
| nodes += containerBuilder(name, init) | ||
| class TestContainerBuilder(var name: String) : TestNodeBuilder() { | ||
| fun build(): DynamicContainer { | ||
| return DynamicContainer.dynamicContainer(name, createNodes()) | ||
| } | ||
| } | ||
|
|
||
| fun build(): Stream<out DynamicNode> = nodes.stream() | ||
| class TestFactoryBuilder : TestNodeBuilder() { | ||
| fun build(): Iterable<DynamicNode> { | ||
| return createNodes() | ||
| } | ||
| } | ||
|
|
||
| fun testFactory(init: TestFactoryBuilder.() -> Unit): Stream<out DynamicNode> = | ||
| inline fun testFactory(init: TestFactoryBuilder.() -> Unit): Iterable<DynamicNode> = | ||
| TestFactoryBuilder().apply(init).build() | ||
|
|
||
| private fun dynamicTest(name: String, test: () -> Unit): DynamicTest = | ||
| DynamicTest.dynamicTest(name, Executable(test)) | ||
| DynamicTest.dynamicTest(name, test) | ||
|
|
||
| private fun dynamicContainer(name: String, init: TestContainerBuilder.() -> Unit): DynamicContainer = | ||
| TestContainerBuilder(name).apply(init).build() | ||
|
|
||
| inline fun <reified T> TestNodeBuilder.testForEach( | ||
| data: Iterable<T>, | ||
| crossinline nameProvider: (T) -> String = { it.toString() }, | ||
| crossinline test: (T) -> Unit, | ||
| ) { | ||
| data.forEach { item -> | ||
| test(nameProvider(item)) { test(item) } | ||
| } | ||
| } | ||
|
|
||
| inline fun <reified T> TestNodeBuilder.containerForEach( | ||
| data: Iterable<T>, | ||
| crossinline nameProvider: (T) -> String = { it.toString() }, | ||
| crossinline init: TestContainerBuilder.(T) -> Unit, | ||
| ) { | ||
| data.forEach { item -> | ||
| container(nameProvider(item)) { init(item) } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.