Skip to content

Commit

Permalink
Migrate performacne tests to occur on tests project
Browse files Browse the repository at this point in the history
This will open up the ability to assert on JS and native which simply isn't possible with the Kotlin Compiler Testing infrastructure.
  • Loading branch information
JakeWharton committed Sep 5, 2023
1 parent 83952e6 commit 47b1688
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 18 deletions.
1 change: 0 additions & 1 deletion poko-compiler-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ dependencies {
testImplementation(libs.kotlin.compileTesting)
testImplementation(libs.junit)
testImplementation(libs.assertk)
testImplementation(libs.asm.util)
testImplementation(libs.testParameterInjector)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,6 @@ class PokoCompilerPluginTest(
}
//endregion

//region Performance optimizations
@Test fun `int property does not emit hashCode method invocation`() {
testCompilation(
"api/Primitives",
) {
val classFile = it.generatedFiles.single { it.name.endsWith(".class") }
val bytecode = bytecodeToText(classFile.readBytes())
assertThat(bytecode).all {
contains("java/lang/Long.hashCode")
doesNotContain("java/lang/Integer.hashCode")
}
}
}
//endregion

private inline fun testCompilation(
vararg sourceFileNames: String,
pokoAnnotationName: String = "dev/drewhamilton/poko/Poko",
Expand Down
13 changes: 13 additions & 0 deletions poko-tests/performance/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plugins {
alias(libs.plugins.kotlin.jvm)
}

dependencies {
testImplementation(libs.junit)
testImplementation(libs.assertk)
testImplementation(libs.asm.util)
}

tasks.named("test") {
dependsOn(":poko-tests:compileKotlinJvm")
}
16 changes: 16 additions & 0 deletions poko-tests/performance/src/test/kotlin/JvmPerformanceTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import assertk.all
import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.doesNotContain
import org.junit.Test

class JvmPerformanceTest {
@Test fun `int property does not emit hashCode method invocation`() {
val classfile = jvmOutput("performance/IntAndLong.class")
val bytecode = bytecodeToText(classfile.readBytes())
assertThat(bytecode).all {
contains("java/lang/Long.hashCode")
doesNotContain("java/lang/Integer.hashCode")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
package dev.drewhamilton.poko

import java.io.PrintWriter
import java.io.StringWriter
import org.objectweb.asm.ClassReader
Expand Down
3 changes: 3 additions & 0 deletions poko-tests/performance/src/test/kotlin/sources.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import java.io.File

fun jvmOutput(relativePath: String) = File("../build/classes/kotlin/jvm/main", relativePath)
9 changes: 9 additions & 0 deletions poko-tests/src/commonMain/kotlin/performance/IntAndLong.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package performance

import dev.drewhamilton.poko.Poko

@Suppress("unused")
@Poko class IntAndLong(
val int: Int,
val long: Long,
)
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ include(
":poko-annotations",
":poko-gradle-plugin",
":poko-tests",
":poko-tests:performance",
)

0 comments on commit 47b1688

Please sign in to comment.