-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add test dependencies * Gradle cleaning * Configure test * Improve testability * Cleanup existing tests * Test todos * Write StabilityWrapper tests * Write runtime tests * LoadingOrder todos * Write DurableKey tests * Improve StabilityWrapper test * Write InvalidationTrackableTransformer test (wip) * Fix Out of index exception when additionalVisitor is not null * Fix StabilityWrapper test * Todo InvalidationTrackableTransformer test
- Loading branch information
Showing
28 changed files
with
1,028 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...gration-test/src/test/kotlin/land/sungbin/composeinvestigator/compiler/test/IrBaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Designed and developed by Ji Sungbin 2023. | ||
* | ||
* Licensed under the MIT. | ||
* Please see full license: https://github.com/jisungbin/ComposeInvestigator/blob/main/LICENSE | ||
*/ | ||
|
||
@file:Suppress("UnusedReceiverParameter") | ||
|
||
package land.sungbin.composeinvestigator.compiler.test | ||
|
||
import androidx.compose.compiler.plugins.kotlin.ComposeCommandLineProcessor | ||
import androidx.compose.compiler.plugins.kotlin.ComposePluginRegistrar | ||
import com.tschuchort.compiletesting.KotlinCompilation | ||
import com.tschuchort.compiletesting.PluginOption | ||
import com.tschuchort.compiletesting.SourceFile | ||
import land.sungbin.composeinvestigator.compiler.COMPOSE_INVESTIGATOR_PLUGIN_ID | ||
import land.sungbin.composeinvestigator.compiler.ComposeInvestigatorCommandLineProcessor | ||
import land.sungbin.composeinvestigator.compiler.ComposeInvestigatorPluginRegistrar | ||
import land.sungbin.composeinvestigator.compiler.OPTION_VERBOSE | ||
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension | ||
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext | ||
import org.jetbrains.kotlin.com.intellij.mock.MockProject | ||
import org.jetbrains.kotlin.com.intellij.openapi.extensions.LoadingOrder | ||
import org.jetbrains.kotlin.compiler.plugin.CommandLineProcessor | ||
import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar | ||
import org.jetbrains.kotlin.config.CompilerConfiguration | ||
import org.jetbrains.kotlin.config.JvmTarget | ||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment | ||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid | ||
import org.jetbrains.kotlin.ir.visitors.acceptVoid | ||
import java.io.File | ||
|
||
interface IrBaseTest | ||
|
||
fun IrBaseTest.emptyIrElementVisitor() = object : IrElementVisitorVoid {} | ||
|
||
@Suppress("DEPRECATION") | ||
fun IrBaseTest.buildIrVisiterRegistrar(builder: (context: IrPluginContext) -> IrElementVisitorVoid): ComponentRegistrar = | ||
object : ComponentRegistrar { | ||
override val supportsK2 = false | ||
override fun registerProjectComponents(project: MockProject, configuration: CompilerConfiguration) { | ||
@Suppress("UnstableApiUsage") | ||
project.extensionArea | ||
.getExtensionPoint(IrGenerationExtension.extensionPointName) | ||
.registerExtension( | ||
object : IrGenerationExtension { | ||
override fun generate(moduleFragment: IrModuleFragment, pluginContext: IrPluginContext) { | ||
moduleFragment.acceptVoid(builder(pluginContext)) | ||
} | ||
}, | ||
// TODO: LoadingOrder("after $COMPOSE_INVESTIGATOR_PLUGIN_ID"), | ||
// https://github.com/JetBrains/intellij-community/blob/17ca1d0afb43f824cda948fc3ea4467ebe55b346/platform/extensions/src/com/intellij/openapi/extensions/LoadingOrder.kt#L24 | ||
LoadingOrder.LAST, | ||
project, | ||
) | ||
} | ||
} | ||
|
||
fun IrBaseTest.kotlinCompilation( | ||
workingDir: File, | ||
enableComposeCompiler: Boolean = true, | ||
enableVerboseLogging: Boolean = true, | ||
@Suppress("DEPRECATION") additionalVisitor: ComponentRegistrar? = null, | ||
vararg sourceFiles: SourceFile, | ||
) = KotlinCompilation().apply { | ||
this.workingDir = workingDir | ||
sources = sourceFiles.asList() | ||
jvmTarget = JvmTarget.JVM_17.toString() | ||
inheritClassPath = true | ||
supportsK2 = false | ||
pluginOptions = listOf( | ||
PluginOption( | ||
pluginId = COMPOSE_INVESTIGATOR_PLUGIN_ID, | ||
optionName = OPTION_VERBOSE.optionName, | ||
optionValue = enableVerboseLogging.toString(), | ||
), | ||
) | ||
@Suppress("DEPRECATION") | ||
componentRegistrars = mutableListOf<ComponentRegistrar>(ComposeInvestigatorPluginRegistrar()).also { registrars -> | ||
if (enableComposeCompiler) registrars.add(0, ComposePluginRegistrar()) | ||
if (additionalVisitor != null) registrars.add(additionalVisitor) | ||
} | ||
commandLineProcessors = mutableListOf<CommandLineProcessor>(ComposeInvestigatorCommandLineProcessor()).also { processors -> | ||
if (enableComposeCompiler) processors.add(0, ComposeCommandLineProcessor()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
10 changes: 10 additions & 0 deletions
10
...ation-test/src/test/kotlin/land/sungbin/composeinvestigator/compiler/test/source/hello.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Designed and developed by Ji Sungbin 2023. | ||
* | ||
* Licensed under the MIT. | ||
* Please see full license: https://github.com/jisungbin/ComposeInvestigator/blob/main/LICENSE | ||
*/ | ||
|
||
package land.sungbin.composeinvestigator.compiler.test.source | ||
|
||
fun hello() = "Hello, world!" |
13 changes: 13 additions & 0 deletions
13
...lin/land/sungbin/composeinvestigator/compiler/test/source/tracker/DurableKeyTestSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* Designed and developed by Ji Sungbin 2023. | ||
* | ||
* Licensed under the MIT. | ||
* Please see full license: https://github.com/jisungbin/ComposeInvestigator/blob/main/LICENSE | ||
*/ | ||
|
||
package land.sungbin.composeinvestigator.compiler.test.source.tracker | ||
|
||
fun one() {} | ||
fun one(a: Any) {} | ||
fun one(a: Any, b: Any) {} | ||
fun one(a: Any, b: Any, c: Any) {} |
76 changes: 76 additions & 0 deletions
76
...seinvestigator/compiler/test/source/tracker/InvalidationTrackableTransformerTestSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Designed and developed by Ji Sungbin 2023. | ||
* | ||
* Licensed under the MIT. | ||
* Please see full license: https://github.com/jisungbin/ComposeInvestigator/blob/main/LICENSE | ||
*/ | ||
|
||
@file:Suppress("unused", "TestFunctionName", "LocalVariableName") | ||
|
||
package land.sungbin.composeinvestigator.compiler.test.source.tracker | ||
|
||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
|
||
@Composable | ||
fun InTopLevel(param: Any) { | ||
Text("Hello, World!: $param") | ||
} | ||
|
||
@Suppress("NOTHING_TO_INLINE") | ||
@Composable | ||
inline fun InTopLevelInline(param: Any) { | ||
Text("Hello, World!: $param") | ||
} | ||
|
||
class Class { | ||
@Composable | ||
fun InClass(param: Any) { | ||
Text("Hello, World!: $param") | ||
} | ||
} | ||
|
||
object Object { | ||
@Composable | ||
fun InObject(param: Any) { | ||
Text("Hello, World!: $param") | ||
} | ||
} | ||
|
||
fun Local() { | ||
@Composable | ||
fun InLocal(param: Any) { | ||
Text("Hello, World!: $param") | ||
} | ||
} | ||
|
||
fun Lambda(param: Any) { | ||
@Suppress("UNUSED_VARIABLE") | ||
val InLambda = @Composable { | ||
Text("Hello, World!: $param") | ||
} | ||
} | ||
|
||
@Composable | ||
fun InParameter(content: @Composable (param: Any) -> Unit = { param -> Text("Hello, World!: $param") }) { | ||
content(Any()) | ||
} | ||
|
||
class CompanionObject { | ||
companion object { | ||
@Composable | ||
fun InCompanionObject(param: Any) { | ||
Text("Hello, World!: $param") | ||
} | ||
} | ||
} | ||
|
||
fun AnonymousObject() { | ||
@Suppress("UNUSED_VARIABLE") | ||
val anonymousObject = object { | ||
@Composable | ||
fun InAnonymousObject(param: Any) { | ||
Text("Hello, World!: $param") | ||
} | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
.../src/test/kotlin/land/sungbin/composeinvestigator/compiler/test/tracker/DurableKeyTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Designed and developed by Ji Sungbin 2023. | ||
* | ||
* Licensed under the MIT. | ||
* Please see full license: https://github.com/jisungbin/ComposeInvestigator/blob/main/LICENSE | ||
*/ | ||
|
||
package land.sungbin.composeinvestigator.compiler.test.tracker | ||
|
||
import io.kotest.core.spec.style.ShouldSpec | ||
import io.kotest.engine.spec.tempdir | ||
import io.kotest.matchers.shouldBe | ||
import land.sungbin.composeinvestigator.compiler.internal.WeakBindingTracee | ||
import land.sungbin.composeinvestigator.compiler.internal.irTracee | ||
import land.sungbin.composeinvestigator.compiler.internal.tracker.key.DurableWritableSlices | ||
import land.sungbin.composeinvestigator.compiler.test.IrBaseTest | ||
import land.sungbin.composeinvestigator.compiler.test.buildIrVisiterRegistrar | ||
import land.sungbin.composeinvestigator.compiler.test.kotlinCompilation | ||
import land.sungbin.composeinvestigator.compiler.test.utils.source | ||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment | ||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction | ||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid | ||
|
||
class DurableKeyTest : ShouldSpec(), IrBaseTest { | ||
init { | ||
should("Generates a unique key for the same function name") { | ||
val irFunctions = mutableListOf<IrSimpleFunction>() | ||
var irTrace: WeakBindingTracee? = null | ||
|
||
val irVisitor = buildIrVisiterRegistrar { context -> | ||
object : IrElementVisitorVoid { | ||
override fun visitModuleFragment(declaration: IrModuleFragment) { | ||
irFunctions += declaration.files.single().declarations.filterIsInstance<IrSimpleFunction>() | ||
irTrace = context.irTracee | ||
return super.visitModuleFragment(declaration) | ||
} | ||
} | ||
} | ||
|
||
kotlinCompilation( | ||
workingDir = tempdir(), | ||
enableComposeCompiler = false, | ||
enableVerboseLogging = false, | ||
additionalVisitor = irVisitor, | ||
sourceFiles = arrayOf(source("tracker/DurableKeyTestSource.kt")), | ||
).compile() | ||
|
||
val zeroArgFn = irFunctions.single { fn -> fn.valueParameters.isEmpty() } | ||
val oneArgFn = irFunctions.single { fn -> fn.valueParameters.size == 1 } | ||
val twoArgFn = irFunctions.single { fn -> fn.valueParameters.size == 2 } | ||
val threeArgFn = irFunctions.single { fn -> fn.valueParameters.size == 3 } | ||
|
||
val zeroArgFnKey = irTrace!![DurableWritableSlices.DURABLE_FUNCTION_KEY, zeroArgFn]!! | ||
val oneArgFnKey = irTrace!![DurableWritableSlices.DURABLE_FUNCTION_KEY, oneArgFn]!! | ||
val twoArgFnKey = irTrace!![DurableWritableSlices.DURABLE_FUNCTION_KEY, twoArgFn]!! | ||
val threeArgFnKey = irTrace!![DurableWritableSlices.DURABLE_FUNCTION_KEY, threeArgFn]!! | ||
|
||
zeroArgFnKey.name shouldBe "fun-one()Unit/pkg-land.sungbin.composeinvestigator.compiler.test.source.tracker/file-DurableKeyTestSource.kt" | ||
oneArgFnKey.name shouldBe "fun-one(Any)Unit/pkg-land.sungbin.composeinvestigator.compiler.test.source.tracker/file-DurableKeyTestSource.kt" | ||
twoArgFnKey.name shouldBe "fun-one(Any,Any)Unit/pkg-land.sungbin.composeinvestigator.compiler.test.source.tracker/file-DurableKeyTestSource.kt" | ||
threeArgFnKey.name shouldBe "fun-one(Any,Any,Any)Unit/pkg-land.sungbin.composeinvestigator.compiler.test.source.tracker/file-DurableKeyTestSource.kt" | ||
} | ||
} | ||
} |
Oops, something went wrong.