Skip to content

Commit

Permalink
improve data driven unit tests to use kotest withData()
Browse files Browse the repository at this point in the history
  • Loading branch information
irmen committed Sep 8, 2024
1 parent c5b7eda commit edc5a5a
Show file tree
Hide file tree
Showing 35 changed files with 117 additions and 125 deletions.
23 changes: 23 additions & 0 deletions .idea/libraries/io_kotest_framework_datatest.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions codeGenCpu6502/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies {
implementation "com.michael-bull.kotlin-result:kotlin-result-jvm:2.0.0"

testImplementation 'io.kotest:kotest-runner-junit5-jvm:5.9.1'
testImplementation 'io.kotest:kotest-framework-datatest:5.9.1'
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.2'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
Expand Down
1 change: 1 addition & 0 deletions codeGenCpu6502/codeGenCpu6502.iml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
<orderEntry type="library" name="michael.bull.kotlin.result.jvm" level="project" />
<orderEntry type="library" name="io.kotest.assertions.core.jvm" level="project" />
<orderEntry type="library" name="io.kotest.runner.junit5.jvm" level="project" />
<orderEntry type="library" name="io.kotest.framework.datatest" level="project" />
</component>
</module>
1 change: 1 addition & 0 deletions codeGenIntermediate/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ dependencies {

testImplementation 'io.kotest:kotest-runner-junit5-jvm:5.9.1'
testImplementation 'org.junit.jupiter:junit-jupiter:5.9.2'
testImplementation 'io.kotest:kotest-framework-datatest:5.9.1'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

}
Expand Down
1 change: 1 addition & 0 deletions codeGenIntermediate/codeGenIntermediate.iml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<orderEntry type="module" module-name="intermediate" />
<orderEntry type="library" name="io.kotest.assertions.core.jvm" level="project" />
<orderEntry type="library" name="io.kotest.runner.junit5.jvm" level="project" />
<orderEntry type="library" name="io.kotest.framework.datatest" level="project" />
<orderEntry type="library" name="michael.bull.kotlin.result.jvm" level="project" />
</component>
</module>
2 changes: 1 addition & 1 deletion compiler/test/ModuleImporterTests.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package prog8tests
package prog8tests.compiler

import com.github.michaelbull.result.getErrorOrElse
import com.github.michaelbull.result.getOrElse
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/ProjectConfig.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package prog8tests
package prog8tests.compiler

import io.kotest.core.config.AbstractProjectConfig
import io.kotest.core.spec.SpecExecutionOrder
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/TestBuiltinFunctions.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package prog8tests
package prog8tests.compiler

import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/TestCallgraph.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package prog8tests
package prog8tests.compiler

import io.kotest.assertions.withClue
import io.kotest.core.spec.style.FunSpec
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/TestCompilerOnCharLit.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package prog8tests
package prog8tests.compiler

import io.kotest.assertions.fail
import io.kotest.assertions.withClue
Expand Down
81 changes: 41 additions & 40 deletions compiler/test/TestCompilerOnExamples.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package prog8tests
package prog8tests.compiler

import io.kotest.core.spec.style.FunSpec
import io.kotest.datatest.withData
import io.kotest.matchers.shouldNotBe
import prog8.code.core.ICompilationTarget
import prog8.code.target.*
Expand All @@ -11,7 +12,6 @@ import prog8tests.helpers.*
import java.nio.file.Path
import kotlin.io.path.absolute
import kotlin.io.path.exists
import kotlin.io.path.readText


/**
Expand Down Expand Up @@ -89,13 +89,14 @@ class TestCompilerOnExamplesC64: FunSpec({
listOf(false, true)
)

onlyC64.forEach {
val (source, optimize) = it
val target = C64Target()
val (displayName, filepath) = prepareTestFiles(source, optimize, target)
test(displayName) {
compileTheThing(filepath, optimize, target) shouldNotBe null
}
val target = C64Target()
withData(
nameFn = { it.second.first },
onlyC64.map { it to prepareTestFiles(it.first, it.second, target) }
) { (params, prep) ->
val filepath = prep.second
val optimize = params.second
compileTheThing(filepath, optimize, target) shouldNotBe null
}
})

Expand Down Expand Up @@ -145,13 +146,14 @@ class TestCompilerOnExamplesCx16: FunSpec({
listOf(false, true)
)

onlyCx16.forEach {
val (source, optimize) = it
val target = Cx16Target()
val (displayName, filepath) = prepareTestFiles(source, optimize, target)
test(displayName) {
compileTheThing(filepath, optimize, target) shouldNotBe null
}
val target = Cx16Target()
withData(
nameFn = { it.second.first },
onlyCx16.map { it to prepareTestFiles(it.first, it.second, target) }
) { (params, prep) ->
val filepath = prep.second
val optimize = params.second
compileTheThing(filepath, optimize, target) shouldNotBe null
}
})

Expand Down Expand Up @@ -181,40 +183,39 @@ class TestCompilerOnExamplesBothC64andCx16: FunSpec({
"tehtriz",
"textelite",
),
listOf(false, true)
listOf(false, true),
listOf(C64Target(), Cx16Target())
)

bothCx16AndC64.forEach {
val (source, optimize) = it
val c64target = C64Target()
val cx16target = Cx16Target()
val (displayNameC64, filepathC64) = prepareTestFiles(source, optimize, c64target)
val (displayNameCx16, filepathCx16) = prepareTestFiles(source, optimize, cx16target)
test(displayNameC64) {
compileTheThing(filepathC64, optimize, c64target) shouldNotBe null
}
test(displayNameCx16) {
compileTheThing(filepathCx16, optimize, cx16target) shouldNotBe null
}
withData(
nameFn = { it.third.first },
bothCx16AndC64.map { Triple(it.second, it.third, prepareTestFiles(it.first, it.second, it.third)) }
) { params ->
val filepath = params.third.second
val optimize = params.first
compileTheThing(filepath, optimize, params.second) shouldNotBe null
}
})

class TestCompilerOnExamplesVirtual: FunSpec({

val onlyVirtual = listOf(
val onlyVirtual = cartesianProduct(
listOf(
"bouncegfx",
"bsieve",
"pixelshader",
"sincos"
)

onlyVirtual.forEach {
val target = VMTarget()
val (displayName, filepath) = prepareTestFiles(it, false, target)
test(displayName) {
val src = filepath.readText()
compileText(target, false, src, writeAssembly = true) shouldNotBe null
compileText(target, true, src, writeAssembly = true) shouldNotBe null
}
),
listOf(false, true)
)

val target = VMTarget()
withData(
nameFn = { it.second.first },
onlyVirtual.map { it to prepareTestFiles(it.first, it.second, target) }
) { (params, prep) ->
val filepath = prep.second
val optimize = params.second
compileTheThing(filepath, optimize, target) shouldNotBe null
}
})
2 changes: 1 addition & 1 deletion compiler/test/TestCompilerOnImportsAndIncludes.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package prog8tests
package prog8tests.compiler

import io.kotest.assertions.withClue
import io.kotest.core.spec.style.FunSpec
Expand Down
45 changes: 22 additions & 23 deletions compiler/test/TestCompilerOnRanges.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package prog8tests
package prog8tests.compiler

import io.kotest.assertions.withClue
import io.kotest.core.spec.style.FunSpec
import io.kotest.datatest.withData
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.kotest.matchers.string.shouldContain
Expand Down Expand Up @@ -93,26 +94,26 @@ class TestCompilerOnRanges: FunSpec({
}

context("floatArrayInitializerWithRange") {
val combos = cartesianProduct(
listOf("", "42", "41"), // sizeInDecl
listOf("%import floats", ""), // optEnableFloats
listOf(Cx16Target(), C64Target()), // platform
listOf(false, true) // optimize
)

combos.forEach {
val (sizeInDecl, optEnableFloats, platform, optimize) = it
val displayName =
when (sizeInDecl) {
withData(
nameFn = {
when (it.first) {
"" -> "no"
"42" -> "correct"
else -> "wrong"
} + " array size given" +
", " + (if (optEnableFloats == "") "without" else "with") + " %option enable_floats" +
", ${platform.name}, optimize: $optimize"

test(displayName) {
val result = compileText(platform, optimize, """
", " + (if (it.second == "") "without" else "with") + " %option enable_floats" +
", ${it.third.name}, optimize: ${it.fourth}"
},
cartesianProduct(
listOf("", "42", "41"), // sizeInDecl
listOf("%import floats", ""), // optEnableFloats
listOf(Cx16Target(), C64Target()), // platform
listOf(false, true) // optimize
)
) { seq ->
val (sizeInDecl, optEnableFloats, platform, optimize) = seq

val result = compileText(platform, optimize, """
$optEnableFloats
main {
sub start() {
Expand All @@ -121,12 +122,10 @@ class TestCompilerOnRanges: FunSpec({
}
}
""")
if (optEnableFloats != "" && (sizeInDecl=="" || sizeInDecl=="42"))
result shouldNotBe null
else
result shouldBe null

}
if (optEnableFloats != "" && (sizeInDecl=="" || sizeInDecl=="42"))
result shouldNotBe null
else
result shouldBe null
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/test/TestCompilerOptionLibdirs.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package prog8tests
package prog8tests.compiler

import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldNotBe
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/TestGoldenRam.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package prog8tests
package prog8tests.compiler

import com.github.michaelbull.result.expectError
import com.github.michaelbull.result.getOrThrow
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/TestImportedModulesOrderAndOptions.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package prog8tests
package prog8tests.compiler

import io.kotest.assertions.withClue
import io.kotest.core.spec.style.FunSpec
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/TestLaunchEmu.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package prog8tests
package prog8tests.compiler

import io.kotest.core.spec.style.FunSpec
import prog8.code.target.VMTarget
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/TestMemory.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package prog8tests
package prog8tests.compiler

import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.FunSpec
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/TestNumbers.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package prog8tests
package prog8tests.compiler

import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.FunSpec
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/TestNumericLiteral.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package prog8tests
package prog8tests.compiler

import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.FunSpec
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/TestOptimization.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package prog8tests
package prog8tests.compiler

import io.kotest.assertions.withClue
import io.kotest.core.spec.style.FunSpec
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/TestPtNumber.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package prog8tests
package prog8tests.compiler

import io.kotest.assertions.throwables.shouldThrow
import io.kotest.core.spec.style.FunSpec
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/TestScoping.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package prog8tests
package prog8tests.compiler

import io.kotest.assertions.withClue
import io.kotest.core.spec.style.FunSpec
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/TestStringEncodings.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package prog8tests
package prog8tests.compiler

import com.github.michaelbull.result.Ok
import com.github.michaelbull.result.expectError
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/TestSubroutines.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package prog8tests
package prog8tests.compiler

import io.kotest.assertions.withClue
import io.kotest.core.spec.style.FunSpec
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/TestSymbolTable.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package prog8tests
package prog8tests.compiler

import io.kotest.assertions.fail
import io.kotest.core.spec.style.FunSpec
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/TestTypecasts.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package prog8tests
package prog8tests.compiler

import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.ints.shouldBeGreaterThan
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/TestZeropage.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package prog8tests
package prog8tests.compiler

import com.github.michaelbull.result.expectError
import com.github.michaelbull.result.getOrElse
Expand Down
Loading

0 comments on commit edc5a5a

Please sign in to comment.