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

Fix bugs in JS tests #28

Merged
merged 1 commit into from
Oct 17, 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
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")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💀

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