Skip to content
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

Kotest project setup #185

Merged
merged 12 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/jvm-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ jobs:
if: always() # always run even if the previous step fails
with:
check_name: JUnit ${{ matrix.jre }} ${{ matrix.os }}
report_paths: '*/build/test-results/*/TEST-*.xml'
report_paths: 'jvm/*/build/test-results/*/TEST-*.xml'
3 changes: 3 additions & 0 deletions jvm/example-junit5/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ tasks.register('exampleAppJvm', JavaExec) {
classpath = sourceSets.test.runtimeClasspath
mainClass = 'com.example.Dev'
args = ['dev']
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
1,385 changes: 9 additions & 1,376 deletions jvm/kotlin-js-store/yarn.lock

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions jvm/selfie-lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ kotlin {
})
}
}
js(IR) {
browser {
}
js {
nodejs()
}
sourceSets {
commonMain {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,31 @@ class DuplicateWriteTest : Harness("undertest-junit5") {
fun cannot_write_multiple_things_to_one_snapshot() {
ut_mirrorKt().linesFrom("fun shouldFail()").toFirst("}").uncomment()
ut_mirrorKt().linesFrom("fun shouldPass()").toFirst("}").commentOut()
gradlew("underTest", "-Pselfie=overwrite")!!.message shouldStartWith
gradlew("test", "-PunderTest=true", "-Pselfie=overwrite")!!.message shouldStartWith
"Snapshot was set to multiple values"
}

@Test @Order(3)
fun can_write_one_thing_multiple_times_to_one_snapshot() {
ut_mirrorKt().linesFrom("fun shouldFail()").toFirst("}").commentOut()
ut_mirrorKt().linesFrom("fun shouldPass()").toFirst("}").uncomment()
gradlew("underTest", "-Pselfie=overwrite") shouldBe null
gradlew("test", "-PunderTest=true", "-Pselfie=overwrite") shouldBe null
}

@Test @Order(4)
fun can_read_one_thing_multiple_times_from_one_snapshot() {
ut_mirrorKt().linesFrom("fun shouldFail()").toFirst("}").commentOut()
ut_mirrorKt().linesFrom("fun shouldPass()").toFirst("}").uncomment()
gradlew("underTest", "-Pselfie=readonly") shouldBe null
gradlew("test", "-PunderTest=true", "-Pselfie=readonly") shouldBe null
}

@Test @Order(5)
fun writeonce_mode() {
ut_mirrorKt().linesFrom("fun shouldFail()").toFirst("}").commentOut()
ut_mirrorKt().linesFrom("fun shouldPass()").toFirst("}").uncomment()
gradlew(
"underTest",
"test",
"-PunderTest=true",
"-Pselfie=overwrite",
"-Pselfie.settings=undertest.junit5.SelfieWriteOnce")!!
.message shouldStartWith "Snapshot was set to the same value multiple times"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import org.w3c.dom.NodeList
import org.xml.sax.InputSource

open class Harness(subproject: String) {
// not sure why, but it doesn't work in this project
val onlyRunThisTest = subproject != "undertest-junit-vintage"
val subprojectFolder: Path

init {
Expand Down Expand Up @@ -206,45 +204,30 @@ open class Harness(subproject: String) {
.connect()
.use { connection ->
try {
if (onlyRunThisTest) {
var testLauncher =
connection
.newTestLauncher()
.setStandardError(System.err)
.setStandardOutput(System.out)
if (runOnlyMethod == null) {
testLauncher =
testLauncher.withTaskAndTestClasses(
":${subprojectFolder.name}:$task", listOf("UT_${javaClass.simpleName}"))
} else {
testLauncher =
testLauncher.withTaskAndTestMethods(
":${subprojectFolder.name}:$task",
"UT_${javaClass.simpleName}",
listOf(runOnlyMethod!!))
}
testLauncher
.withArguments(
buildList<String> {
addAll(args)
add("--configuration-cache") // enabled vs disabled is 11s vs 24s
add("--stacktrace")
})
.run()
var testLauncher =
connection
.newTestLauncher()
.setStandardError(System.err)
.setStandardOutput(System.out)
if (runOnlyMethod == null) {
testLauncher =
testLauncher.withTaskAndTestClasses(
":${subprojectFolder.name}:$task", listOf("UT_${javaClass.simpleName}"))
} else {
connection
.newBuild()
.setStandardError(System.err)
.setStandardOutput(System.out)
.forTasks(":${subprojectFolder.name}:$task")
.withArguments(
buildList<String> {
addAll(args)
add("--configuration-cache") // enabled vs disabled is 11s vs 24s
add("--stacktrace")
})
.run()
testLauncher =
testLauncher.withTaskAndTestMethods(
":${subprojectFolder.name}:$task",
"UT_${javaClass.simpleName}",
listOf(runOnlyMethod!!))
}
testLauncher
.withArguments(
buildList<String> {
addAll(args)
add("--configuration-cache") // enabled vs disabled is 11s vs 24s
add("--stacktrace")
})
.run()
null
} catch (e: TestExecutionException) {
parseBuildException(task, e)
Expand Down Expand Up @@ -306,30 +289,30 @@ open class Harness(subproject: String) {
return error
}
fun gradleWriteSS() {
gradlew("underTest", "-Pselfie=overwrite")?.let {
gradlew("test", "-PunderTest=true", "-Pselfie=overwrite")?.let {
throw AssertionError("Expected write snapshots to succeed, but it failed", it)
}
}
fun gradleReadSS() {
gradlew("underTest", "-Pselfie=readonly")?.let {
gradlew("test", "-PunderTest=true", "-Pselfie=readonly")?.let {
throw AssertionError("Expected read snapshots to succeed, but it failed", it)
}
}
fun gradleReadSSFail(): AssertionFailedError {
val failure = gradlew("underTest", "-Pselfie=readonly")
val failure = gradlew("test", "-PunderTest=true", "-Pselfie=readonly")
if (failure == null) {
throw AssertionError("Expected read snapshots to fail, but it succeeded.")
} else {
return failure
}
}
fun gradleInteractivePass() {
gradlew("underTest", "-Pselfie=interactive")?.let {
gradlew("test", "-PunderTest=true", "-Pselfie=interactive")?.let {
throw AssertionError("Expected interactive selfie run to succeed, but it failed.", it)
}
}
fun gradleInteractiveFail(): AssertionFailedError {
val failure = gradlew("underTest", "-Pselfie=interactive")
val failure = gradlew("test", "-PunderTest=true", "-Pselfie=interactive")
if (failure == null) {
throw AssertionError("Expected interactive selfie run to fail, but it succeeded.")
} else {
Expand Down
8 changes: 8 additions & 0 deletions jvm/selfie-runner-kotest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Module selfie-runner-kotest

<!-- This div needs to stay, it keeps styling consistent between multiplatform and singleplatform module readmes. -->
<div class="selfie-box selfie-box--border">

A selfie test runner for [Kotest](https://kotest.io/docs/framework/framework.html). High level docs for this live at [selfie.dev](https://selfie.dev/jvm/get-started).

</div>
64 changes: 64 additions & 0 deletions jvm/selfie-runner-kotest/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
plugins {
id 'org.jetbrains.kotlin.multiplatform'
id 'io.kotest.multiplatform'
}
repositories {
mavenCentral()
}
ext {
maven_name = 'selfie-runner-kotest'
maven_desc = 'Kotest test runner for Selfie'
}

apply from: 干.file('base/changelog.gradle')
apply from: rootProject.file('gradle/spotless.gradle')
apply plugin: 'java-library'

kotlin {
jvm {
testRuns["test"].executionTask.configure {
useJUnitPlatform()
}
}
js {
nodejs()
}
sourceSets {
commonMain {
dependencies {
api project(":selfie-lib")
api "io.kotest:kotest-framework-engine:$ver_KOTEST"
implementation "com.squareup.okio:okio:$ver_OKIO"
}
}
jsMain {
dependencies {
implementation "com.squareup.okio:okio-nodefilesystem:$ver_OKIO"
}
}
commonTest {
dependencies {
implementation("io.kotest:kotest-framework-engine:$ver_KOTEST")
implementation("io.kotest:kotest-assertions-core:$ver_KOTEST")
implementation(kotlin('test'))
}
}
jvmTest {
dependencies {
implementation "io.kotest:kotest-runner-junit5:$ver_KOTEST"
}
}
}
}

jsNodeTest {
enabled = false // TODO: https://github.com/diffplug/selfie/issues/186
getInputs().dir('../undertest-kotest/src/commonTest/kotlin')
}
jvmTest {
getInputs().dir('../undertest-kotest/src/commonTest/kotlin')
}

// it all needs to get published and formatted
apply from: 干.file('base/maven.gradle')
apply from: 干.file('base/sonatype.gradle')
Loading
Loading