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

Upgraded Showkase to newer versions of Compose + Kotlin + KSP #384

Merged
merged 5 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 11 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.KSP_VERSION = '1.8.10-1.0.9'
ext.KSP_VERSION = '1.9.20-1.0.14'
ext.versions = [
'androidXTestCore' : '1.4.0',
'androidXTestRules' : '1.4.0',
'assertJ' : '3.16.1',
'compose' : '1.4.2',
'composeCompiler' : '1.4.2',
'composeActivity' : '1.5.1',
'compose' : '1.6.7',
Copy link

@skylerreimer skylerreimer May 21, 2024

Choose a reason for hiding this comment

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

✨✨✨✨✨

Thank you!!!

'composeCompiler' : '1.5.5',
'composeActivity' : '1.9.0',
'composeConstraintLayout': '1.0.1',
'composeNavigation' : '2.5.1',
'detekt' : '1.7.4',
'espresso' : '3.2.0',
'gradle' : '8.0.0',
'gradle' : '8.1.1',
'junit' : '4.13.2',
'junitImplementation' : '1.1.2',
'kotlin' : '1.8.10',
'kotlinCompilerVersion' : '1.8.10',
'kotlinCompileTesting' : '1.5.0',
'kotlin' : '1.9.20',
'kotlinCompilerVersion' : '1.9.20',
'kotlinCompileTesting' : '0.4.0',
'kotlinPoet' : '1.12.0',
'kotlinXMetadata' : '0.6.0',
'ksp' : "$KSP_VERSION",
Expand All @@ -33,7 +33,7 @@ buildscript {
'mavenPublish' : '0.22.0',
'mdcComposeThemeAdapter' : '1.0.2',
'strikt' : '0.33.0',
'xprocessing' : '2.6.0-alpha01',
'xprocessing' : '2.6.1',
'corektx' : '1.7.0',
'shot' : '6.0.0'
]
Expand All @@ -54,8 +54,8 @@ buildscript {
'uiTest' : "androidx.compose.ui:ui-test-junit4:${versions.compose}",
'uiLiveData' : "androidx.compose.runtime:runtime-livedata:${versions.compose}"
],
'kotlinCompileTesting' : "com.github.tschuchortdev:kotlin-compile-testing:${versions.kotlinCompileTesting}",
'kotlinCompileTestingKsp': "com.github.tschuchortdev:kotlin-compile-testing-ksp:${versions.kotlinCompileTesting}",
'kotlinCompileTesting' : "dev.zacsweers.kctfork:core:${versions.kotlinCompileTesting}",
'kotlinCompileTestingKsp': "dev.zacsweers.kctfork:ksp:${versions.kotlinCompileTesting}",
'kotlinPoet' : "com.squareup:kotlinpoet:${versions.kotlinPoet}",
'kotlinJavaPoetInterop' : "com.squareup:kotlinpoet-javapoet:${versions.kotlinPoet}",
'kotlinXMetadata' : "org.jetbrains.kotlinx:kotlinx-metadata-jvm:${versions.kotlinXMetadata}",
Expand Down
2 changes: 1 addition & 1 deletion sample-submodule-2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ android {

defaultConfig {
minSdkVersion 21
compileSdk 33
compileSdk 34
targetSdkVersion 33

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
2 changes: 1 addition & 1 deletion sample-submodule/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ android {

defaultConfig {
minSdkVersion 21
compileSdk 33
compileSdk 34
targetSdkVersion 33

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
2 changes: 1 addition & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ android {
defaultConfig {
applicationId "com.airbnb.android.showkasesample"
minSdkVersion 21
compileSdk 33
compileSdk 34
targetSdkVersion 33
versionCode 1
versionName "1.0"
Expand Down
2 changes: 1 addition & 1 deletion showkase-browser-testing-submodule-2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ android {
}
defaultConfig {
minSdkVersion 26
compileSdk 33
compileSdk 34
targetSdkVersion 33
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
// The following argument makes the Android Test Orchestrator run its
Expand Down
2 changes: 1 addition & 1 deletion showkase-browser-testing-submodule/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ android {
}
defaultConfig {
minSdkVersion 26
compileSdk 33
compileSdk 34
targetSdkVersion 33
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
// The following argument makes the Android Test Orchestrator run its
Expand Down
2 changes: 1 addition & 1 deletion showkase-browser-testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ android {

defaultConfig {
minSdkVersion 26
compileSdk 33
compileSdk 34
targetSdkVersion 33
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
// The following argument makes the Android Test Orchestrator run its
Expand Down
2 changes: 1 addition & 1 deletion showkase-processor-testing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android {
}
defaultConfig {
minSdkVersion 26
compileSdk 33
compileSdk 34
targetSdkVersion 33
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
// The following argument makes the Android Test Orchestrator run its
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ package com.airbnb.android.showkase_processor_testing
import com.airbnb.android.showkase.processor.ShowkaseProcessor
import com.airbnb.android.showkase.processor.ShowkaseProcessorProvider
import com.google.common.io.Resources
import com.tschuchort.compiletesting.CompilationResult
import com.tschuchort.compiletesting.JvmCompilationResult
import com.tschuchort.compiletesting.KotlinCompilation
import com.tschuchort.compiletesting.SourceFile
import com.tschuchort.compiletesting.kspArgs
import com.tschuchort.compiletesting.kspSourcesDir
import com.tschuchort.compiletesting.symbolProcessorProviders
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.junit.Rule
import java.io.File

Expand All @@ -31,10 +34,11 @@ abstract class BaseProcessorTest {
* Collects the files in the "input" directory of this test's resources directory
* and compiles them with Kotlin, returning the result.
*/
@OptIn(ExperimentalCompilerApi::class)
protected fun compileInputs(
modes: List<Mode> = listOf(Mode.KSP, Mode.KAPT),
options: MutableMap<String, String> = mutableMapOf(),
onCompilation: (mode: Mode, compilation: KotlinCompilation, result: KotlinCompilation.Result) -> Unit
onCompilation: (mode: Mode, compilation: KotlinCompilation, result: CompilationResult) -> Unit
) {
val testResourcesDir = getTestResourcesDirectory(getRootResourcesDir())

Expand Down Expand Up @@ -65,6 +69,7 @@ abstract class BaseProcessorTest {
}
}

@OptIn(ExperimentalCompilerApi::class)
protected fun assertCompilationFails(errorMessage: String) {
compileInputs { _, _, result ->
assertThat(result.exitCode)
Expand All @@ -75,6 +80,7 @@ abstract class BaseProcessorTest {
}
}

@OptIn(ExperimentalCompilerApi::class)
protected fun compileInputsAndVerifyOutputs(
modes:List<Mode> = listOf(Mode.KSP, Mode.KAPT),
options: MutableMap<String, String> = mutableMapOf(),
Expand All @@ -88,7 +94,8 @@ abstract class BaseProcessorTest {
* Collects the files in the "output" directory of this test's resources directory
* and validates that they match the generated sources of this compilation result.
*/
protected fun KotlinCompilation.Result.assertGeneratedSources(mode: Mode, compilation: KotlinCompilation) {
@OptIn(ExperimentalCompilerApi::class)
protected fun CompilationResult.assertGeneratedSources(mode: Mode, compilation: KotlinCompilation) {
assertThat(exitCode).isEqualTo(KotlinCompilation.ExitCode.OK)

val testResourcesDir = getTestResourcesDirectory(getRootResourcesDir())
Expand All @@ -101,7 +108,7 @@ abstract class BaseProcessorTest {

val generatedSources = when (mode) {
Mode.KSP -> compilation.kspSourcesDir.walk().filter { it.isFile }.toList()
Mode.KAPT -> sourcesGeneratedByAnnotationProcessor
Mode.KAPT -> (this as JvmCompilationResult).sourcesGeneratedByAnnotationProcessor
}

if (UPDATE_TEST_OUTPUTS) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,6 @@ class ShowkaseProcessorTest : BaseProcessorTest() {
assertCompilationFails("Only one class in a module can be annotated with ShowkaseRoot")
}

@Test
fun `method with showkaseroot annotation throws compilation error`() {
assertCompilationFails("Only classes can be annotated with @ShowkaseRoot")
}

@Test
fun `class with no interface but showkaseroot annotation throws compilation error`() {
assertCompilationFails("Only an implementation of com.airbnb.android.showkase.annotation.ShowkaseRootModule can be annotated with @ShowkaseRoot")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.google.testing.junit.testparameterinjector.TestParameter
import com.google.testing.junit.testparameterinjector.TestParameter.TestParameterValuesProvider
import com.google.testing.junit.testparameterinjector.TestParameterInjector
import getMetadata
import kotlin.Unit
import kotlin.collections.List
import org.junit.Rule
import org.junit.Test
Expand All @@ -33,13 +32,13 @@ public class MyScreenshotTest_PaparazziShowkaseTest : MyScreenshotTest() {
direction: LayoutDirection,
@TestParameter(valuesProvider = PaparazziShowkaseUIModeProvider::class)
uiMode: PaparazziShowkaseUIMode,
): Unit {
) {
paparazzi.unsafeUpdateConfig(config.deviceConfig.copy(softButtons = false))
takePaparazziSnapshot(paparazzi, elementPreview, direction, uiMode)
}

private object PaparazziShowkasePreviewProvider : TestParameter.TestParameterValuesProvider {
public override fun provideValues(): List<PaparazziShowkaseTestPreview> {
override fun provideValues(): List<PaparazziShowkaseTestPreview> {
val metadata = Showkase.getMetadata()
val components = metadata.componentList.map(::ComponentPaparazziShowkaseTestPreview)
val colors = metadata.colorList.map(::ColorPaparazziShowkaseTestPreview)
Expand All @@ -49,15 +48,15 @@ public class MyScreenshotTest_PaparazziShowkaseTest : MyScreenshotTest() {
}

private object PaparazziShowkaseDeviceConfigProvider : TestParameter.TestParameterValuesProvider {
public override fun provideValues(): List<PaparazziShowkaseDeviceConfig> = deviceConfigs()
override fun provideValues(): List<PaparazziShowkaseDeviceConfig> = deviceConfigs()
}

private object PaparazziShowkaseLayoutDirectionProvider :
TestParameter.TestParameterValuesProvider {
public override fun provideValues(): List<LayoutDirection> = layoutDirections()
override fun provideValues(): List<LayoutDirection> = layoutDirections()
}

private object PaparazziShowkaseUIModeProvider : TestParameter.TestParameterValuesProvider {
public override fun provideValues(): List<PaparazziShowkaseUIMode> = uiModes()
override fun provideValues(): List<PaparazziShowkaseUIMode> = uiModes()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package com.airbnb.android.showkase

import com.airbnb.android.showkase.`annotation`.ShowkaseCodegenMetadata
import kotlin.Unit

public class ShowkaseMetadata_ {
@ShowkaseCodegenMetadata(
Expand All @@ -18,7 +17,7 @@ public class ShowkaseMetadata_ {
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
)
public fun TestComposable1group1name1(): Unit {
public fun TestComposable1group1name1() {
}

@ShowkaseCodegenMetadata(
Expand All @@ -34,7 +33,7 @@ public class ShowkaseMetadata_ {
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
)
public fun TestComposable2group2name2(): Unit {
public fun TestComposable2group2name2() {
}

@ShowkaseCodegenMetadata(
Expand All @@ -49,7 +48,7 @@ public class ShowkaseMetadata_ {
generatedPropertyName = "redcolorname",
showkaseMetadataType = "COLOR",
)
public fun redcolorname(): Unit {
public fun redcolorname() {
}

@ShowkaseCodegenMetadata(
Expand All @@ -64,6 +63,6 @@ public class ShowkaseMetadata_ {
generatedPropertyName = "titletypographyname",
showkaseMetadataType = "TYPOGRAPHY",
)
public fun titletypographyname(): Unit {
public fun titletypographyname() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ import kotlin.collections.List
numTypography = 1,
)
public class TestShowkaseRootCodegen : ShowkaseProvider {
public override fun getShowkaseComponents(): List<ShowkaseBrowserComponent> {
override fun getShowkaseComponents(): List<ShowkaseBrowserComponent> {

return listOf<ShowkaseBrowserComponent>(
TestComposable1group1name1,
TestComposable2group2name2,
)
}

public override fun getShowkaseColors(): List<ShowkaseBrowserColor> {
override fun getShowkaseColors(): List<ShowkaseBrowserColor> {

return listOf<ShowkaseBrowserColor>(
redcolorname,
)
}

public override fun getShowkaseTypography(): List<ShowkaseBrowserTypography> {
override fun getShowkaseTypography(): List<ShowkaseBrowserTypography> {

return listOf<ShowkaseBrowserTypography>(
titletypographyname,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import androidx.compose.ui.test.junit4.createComposeRule
import androidx.test.rule.GrantPermissionRule
import com.airbnb.android.showkase.models.Showkase
import com.airbnb.android.showkase_processor_testing.getMetadata
import kotlin.Unit
import kotlin.jvm.JvmField
import org.junit.Rule
import org.junit.Test
Expand All @@ -17,7 +16,7 @@ import org.junit.runners.JUnit4
@RunWith(JUnit4::class)
public class MyScreenshotTest_ShowkaseCodegen : MyScreenshotTest() {
@get:Rule
public override val composeTestRule: ComposeContentTestRule = createComposeRule()
override val composeTestRule: ComposeContentTestRule = createComposeRule()

@Rule
@JvmField
Expand All @@ -27,22 +26,22 @@ public class MyScreenshotTest_ShowkaseCodegen : MyScreenshotTest() {
)

@Test
public fun composable_screenshot_test_0(): Unit {
public fun composable_screenshot_test_0() {
takeComposableScreenshot(Showkase.getMetadata().componentList[0])
}

@Test
public fun composable_screenshot_test_1(): Unit {
public fun composable_screenshot_test_1() {
takeComposableScreenshot(Showkase.getMetadata().componentList[1])
}

@Test
public fun typography_screenshot_test_0(): Unit {
public fun typography_screenshot_test_0() {
takeTypographyScreenshot(Showkase.getMetadata().typographyList[0])
}

@Test
public fun color_screenshot_test_0(): Unit {
public fun color_screenshot_test_0() {
takeColorScreenshot(Showkase.getMetadata().colorList[0])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
package com.airbnb.android.showkase

import com.airbnb.android.showkase.`annotation`.ShowkaseCodegenMetadata
import kotlin.Unit

public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
@ShowkaseCodegenMetadata(
Expand All @@ -18,7 +17,7 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
)
public fun comairbnbandroidshowkaseprocessortestingTestComposable1group1name1(): Unit {
public fun comairbnbandroidshowkaseprocessortestingTestComposable1group1name1() {
}

@ShowkaseCodegenMetadata(
Expand All @@ -34,7 +33,7 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
showkaseMetadataType = "COMPONENT",
isDefaultStyle = false,
)
public fun comairbnbandroidshowkaseprocessortestingTestComposable2group2name2(): Unit {
public fun comairbnbandroidshowkaseprocessortestingTestComposable2group2name2() {
}

@ShowkaseCodegenMetadata(
Expand All @@ -49,7 +48,7 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
generatedPropertyName = "redcolorname",
showkaseMetadataType = "COLOR",
)
public fun comairbnbandroidshowkaseprocessortestingredcolorname(): Unit {
public fun comairbnbandroidshowkaseprocessortestingredcolorname() {
}

@ShowkaseCodegenMetadata(
Expand All @@ -64,6 +63,6 @@ public class ShowkaseMetadata_com_airbnb_android_showkase_processor_testing {
generatedPropertyName = "titletypographyname",
showkaseMetadataType = "TYPOGRAPHY",
)
public fun comairbnbandroidshowkaseprocessortestingtitletypographyname(): Unit {
public fun comairbnbandroidshowkaseprocessortestingtitletypographyname() {
}
}
Loading
Loading