Skip to content

Commit

Permalink
Fix bugs in JS tests
Browse files Browse the repository at this point in the history
I typo'd the package name, kotlin.text, which prevented anything
from matching.

And I had two primary constructors.

And I had the visibility wrong.

These problems didn't matter for Kotlin/JVM, but they prevented
tests from running successfully on Kotlin/JS.

Kotlin/Native in a follow-up.
  • Loading branch information
squarejesse committed Oct 16, 2024
1 parent 67fb106 commit 8788fd8
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,45 +30,95 @@ import org.junit.Test

class BurstGradlePluginTest {
@Test
fun multiplatform() {
fun multiplatformJvm() {
multiplatform(
testTaskName = "jvmTest",
platformName = "jvm",
)
}

@Test
fun multiplatformJs() {
multiplatform(
testTaskName = "jsNodeTest",
platformName = "js, node",
)
}

private fun multiplatform(
testTaskName: String,
platformName: String,
) {
val projectDir = File("src/test/projects/multiplatform")

val taskName = ":lib:jvmTest"
val taskName = ":lib:$testTaskName"
val result = createRunner(projectDir, "clean", taskName).build()
assertThat(SUCCESS_OUTCOMES)
.contains(result.task(taskName)!!.outcome)

val testResults = projectDir.resolve("lib/build/test-results")
val jvmTestXmlFile = testResults.resolve("jvmTest/TEST-CoffeeTest.xml")

val testSuite = readTestSuite(jvmTestXmlFile)

assertThat(testSuite.testCases.map { it.name }).containsExactlyInAnyOrder(
"test[jvm]",
"test_Decaf_Milk[jvm]",
"test_Decaf_None[jvm]",
"test_Decaf_Oat[jvm]",
"test_Double_Milk[jvm]",
"test_Double_None[jvm]",
"test_Double_Oat[jvm]",
"test_Regular_Milk[jvm]",
"test_Regular_None[jvm]",
"test_Regular_Oat[jvm]",
)

val originalTest = testSuite.testCases.single { it.name == "test[jvm]" }
assertThat(originalTest.skipped).isFalse()

val defaultSpecialization = testSuite.testCases.single { it.name == "test_Decaf_None[jvm]" }
assertThat(defaultSpecialization.skipped).isTrue()

val sampleSpecialization = testSuite.testCases.single { it.name == "test_Regular_Milk[jvm]" }
assertThat(sampleSpecialization.skipped).isFalse()
// The original test class runs the default specialization.
with(readTestSuite(testResults.resolve("$testTaskName/TEST-CoffeeTest.xml"))) {
assertThat(testCases.map { it.name }).containsExactlyInAnyOrder(
"test[$platformName]",
"test_Milk[$platformName]",
"test_None[$platformName]",
"test_Oat[$platformName]",
)

val defaultFunction = testCases.single { it.name == "test[$platformName]" }
assertThat(defaultFunction.skipped).isFalse()

val defaultSpecialization = testCases.single { it.name == "test_None[$platformName]" }
assertThat(defaultSpecialization.skipped).isTrue()

val sampleSpecialization = testCases.single { it.name == "test_Milk[$platformName]" }
assertThat(sampleSpecialization.skipped).isFalse()
}

// The default test class is completely skipped.
with(readTestSuite(testResults.resolve("$testTaskName/TEST-CoffeeTest_Decaf.xml"))) {
assertThat(testCases.map { it.name }).containsExactlyInAnyOrder(
"test[$platformName]",
"test_Milk[$platformName]",
"test_None[$platformName]",
"test_Oat[$platformName]",
)

val defaultFunction = testCases.single { it.name == "test[$platformName]" }
assertThat(defaultFunction.skipped).isTrue()

val defaultSpecialization = testCases.single { it.name == "test_None[$platformName]" }
assertThat(defaultSpecialization.skipped).isTrue()

val sampleSpecialization = testCases.single { it.name == "test_Milk[$platformName]" }
assertThat(sampleSpecialization.skipped).isTrue()
}

// Another test class is executed normally with nothing skipped.
with(readTestSuite(testResults.resolve("$testTaskName/TEST-CoffeeTest_Regular.xml"))) {
assertThat(testCases.map { it.name }).containsExactlyInAnyOrder(
"test[$platformName]",
"test_Milk[$platformName]",
"test_None[$platformName]",
"test_Oat[$platformName]",
)

val defaultFunction = testCases.single { it.name == "test[$platformName]" }
assertThat(defaultFunction.skipped).isFalse()

val defaultSpecialization = testCases.single { it.name == "test_None[$platformName]" }
assertThat(defaultSpecialization.skipped).isTrue()

val sampleSpecialization = testCases.single { it.name == "test_Milk[$platformName]" }
assertThat(sampleSpecialization.skipped).isFalse()
}
}

@Test
fun jvm() {
val projectDir = File("src/test/projects/jvm")
fun functionParameters() {
val projectDir = File("src/test/projects/functionParameters")

val taskName = ":lib:test"
val result = createRunner(projectDir, "clean", taskName).build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ plugins {

kotlin {
jvm()
js {
nodejs()
}

sourceSets {
commonTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import app.cash.burst.Burst
import kotlin.test.BeforeTest
import kotlin.test.Test

@Burst
class CoffeeTest {
class CoffeeTest(
private val espresso: Espresso,
) {
@BeforeTest
fun setUp() {
println("set up $espresso")
}

@Test
fun test(espresso: Espresso, dairy: Dairy) {
fun test(dairy: Dairy) {
println("running $espresso $dairy")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private val burstAnnotationClassId = burstFqPackage.classId("Burst")

val junitPackage = FqPackageName("org.junit")
val junitTestClassId = junitPackage.classId("Test")
val kotlinTestPackage = FqPackageName("kotlin.text")
val kotlinTestPackage = FqPackageName("kotlin.test")
val kotlinTestClassId = kotlinTestPackage.classId("Test")

internal val IrAnnotationContainer.hasAtTest: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
package app.cash.burst.kotlin

import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities.PROTECTED
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities.PUBLIC
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.ir.builders.declarations.addConstructor
import org.jetbrains.kotlin.ir.builders.declarations.buildClass
Expand Down Expand Up @@ -96,7 +97,7 @@ internal class ClassSpecializer(
// Add @Ignore and open the class
// TODO: don't double-add @Ignore
original.modality = Modality.OPEN
onlyConstructor.visibility = DescriptorVisibilities.PROTECTED
onlyConstructor.visibility = PROTECTED

// Add a no-args constructor that calls the only constructor as the default specialization.
createNoArgsConstructor(
Expand All @@ -121,6 +122,7 @@ internal class ClassSpecializer(
) {
val specialization = original.factory.buildClass {
initDefaults(original)
visibility = PUBLIC
name = Name.identifier(name("${original.name.identifier}_", arguments))
}.apply {
superTypes = listOf(original.defaultType)
Expand Down Expand Up @@ -161,6 +163,7 @@ internal class ClassSpecializer(
) {
original.addConstructor {
initDefaults(original)
isPrimary = false
}.apply {
irConstructorBody(pluginContext) { statements ->
statements += irDelegatingConstructorCall(
Expand Down

0 comments on commit 8788fd8

Please sign in to comment.