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

Support internal functions for preview generation #86

Merged
merged 3 commits into from
Oct 11, 2023
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
2 changes: 1 addition & 1 deletion snapshots/sample/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ emerge {

android {
namespace = "com.emergetools.snapshots.sample"
compileSdk = 33
compileSdk = 34
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Think the sample project broke when the versions were bumped recently.


defaultConfig {
applicationId = "com.emergetools.snapshots.sample"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ fun TextRowWithIconPreviewFromMain() {
)
}

@Preview
@Composable
internal fun TextRowWithIconPreviewFromMainInternalFunction() {
TextRowWithIcon(
titleText = stringResource(com.emergetools.snapshots.sample.R.string.sample_title),
subtitleText = stringResource(com.emergetools.snapshots.sample.R.string.sample_subtitle)
)
}

@SnapshotTestingPreview
@Composable
internal fun TextRowWithIconPreviewFromMainInternalFunctionMultiPreview() {
TextRowWithIcon(
titleText = stringResource(com.emergetools.snapshots.sample.R.string.sample_title),
subtitleText = stringResource(com.emergetools.snapshots.sample.R.string.sample_subtitle)
)
}

@LocalePreviews
@FontScalePreviews
@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,21 @@ class PreviewProcessorTest {
compileInputsAndVerifyOutputs()
}

@Test
fun `standalone preview function with internal preview produces one snapshot test`() {
compileInputsAndVerifyOutputs()
}

@Test
fun `multipreview function with two previews produces two snapshots`() {
compileInputsAndVerifyOutputs()
}

@Test
fun `multipreview internal function with two previews produces two snapshots`() {
compileInputsAndVerifyOutputs()
}

@Test
fun `multipreview function with two previews and additional preview produces three snapshots`() {
compileInputsAndVerifyOutputs()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package PreviewProcessorTest.multipreview_internal_function_with_two_previews_produces_two_snapshots.input

import androidx.compose.ui.tooling.preview.Preview

@Preview(
name = "Small font",
fontScale = 0.5f,
)
@Preview(
name = "Large font",
fontScale = 1.5f,
)
annotation class FontScalePreviews
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.emergetools.android.standalone_preview_function_compiles_ok

import PreviewProcessorTest.multipreview_internal_function_with_two_previews_produces_two_snapshots.input.FontScalePreviews
import androidx.compose.runtime.Composable

@FontScalePreviews
@Composable
internal fun MultiPreviewComposable() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.emergetools.android.standalone_preview_function_compiles_ok

import androidx.compose.runtime.Composable
import androidx.compose.ui.test.junit4.ComposeContentTestRule
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.emergetools.android.standalone_preview_function_compiles_ok.MultiPreviewComposable
import com.emergetools.snapshots.EmergeSnapshots
import com.emergetools.snapshots.compose.SnapshotVariantProvider
import com.emergetools.snapshots.shared.ComposePreviewSnapshotConfig
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
public class `MultiPreviewComposable_-849881519_GenSnapshot` {
@get:Rule
public val composeRule: ComposeContentTestRule = createComposeRule()

public val previewConfig: ComposePreviewSnapshotConfig = ComposePreviewSnapshotConfig(originalFqn
= "com.emergetools.android.standalone_preview_function_compiles_ok.MultiPreviewComposable",
name = "Small font",
fontScale = 0.5f)

@get:Rule
public val snapshotRule: EmergeSnapshots = EmergeSnapshots()

@Test
public fun MultiPreviewComposable_GenSnapshot() {
composeRule.setContent {
SnapshotVariantProvider(previewConfig) {
MultiPreviewComposable()
}
}
snapshotRule.take(composeRule, previewConfig)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.emergetools.android.standalone_preview_function_compiles_ok

import androidx.compose.runtime.Composable
import androidx.compose.ui.test.junit4.ComposeContentTestRule
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.emergetools.android.standalone_preview_function_compiles_ok.MultiPreviewComposable
import com.emergetools.snapshots.EmergeSnapshots
import com.emergetools.snapshots.compose.SnapshotVariantProvider
import com.emergetools.snapshots.shared.ComposePreviewSnapshotConfig
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
public class MultiPreviewComposable_1597336221_GenSnapshot {
@get:Rule
public val composeRule: ComposeContentTestRule = createComposeRule()

public val previewConfig: ComposePreviewSnapshotConfig = ComposePreviewSnapshotConfig(originalFqn
= "com.emergetools.android.standalone_preview_function_compiles_ok.MultiPreviewComposable",
name = "Large font",
fontScale = 1.5f)

@get:Rule
public val snapshotRule: EmergeSnapshots = EmergeSnapshots()

@Test
public fun MultiPreviewComposable_GenSnapshot() {
composeRule.setContent {
SnapshotVariantProvider(previewConfig) {
MultiPreviewComposable()
}
}
snapshotRule.take(composeRule, previewConfig)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.emergetools.android.standalone_preview_function_with_internal_preview_produces_one_snapshot_test

import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.runtime.Composable

@Preview
@Composable
internal fun TestComposable() {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.emergetools.android.standalone_preview_function_with_internal_preview_produces_one_snapshot_test

import androidx.compose.runtime.Composable
import androidx.compose.ui.test.junit4.ComposeContentTestRule
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.emergetools.android.standalone_preview_function_with_internal_preview_produces_one_snapshot_test.TestComposable
import com.emergetools.snapshots.EmergeSnapshots
import com.emergetools.snapshots.compose.SnapshotVariantProvider
import com.emergetools.snapshots.shared.ComposePreviewSnapshotConfig
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
public class TestComposable_GenSnapshot {
@get:Rule
public val composeRule: ComposeContentTestRule = createComposeRule()

public val previewConfig: ComposePreviewSnapshotConfig = ComposePreviewSnapshotConfig(originalFqn
=
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure why this is formatted so odd

"com.emergetools.android.standalone_preview_function_with_internal_preview_produces_one_snapshot_test.TestComposable")

@get:Rule
public val snapshotRule: EmergeSnapshots = EmergeSnapshots()

@Test
public fun TestComposable_GenSnapshot() {
composeRule.setContent {
SnapshotVariantProvider(previewConfig) {
TestComposable()
}
}
snapshotRule.take(composeRule, previewConfig)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import com.emergetools.snapshots.processor.utils.putOrAppend
import com.emergetools.snapshots.shared.ComposePreviewSnapshotConfig
import com.google.devtools.ksp.KspExperimental
import com.google.devtools.ksp.isAnnotationPresent
import com.google.devtools.ksp.isInternal
import com.google.devtools.ksp.isPrivate
import com.google.devtools.ksp.processing.CodeGenerator
import com.google.devtools.ksp.processing.Dependencies
Expand Down Expand Up @@ -78,11 +77,6 @@ class PreviewProcessor(
return@flatMap emptyList()
}

if (function.isInternal()) {
logger.info("Skipping ${function.simpleName.asString()} as it is internal")
return@flatMap emptyList()
}

if (function.isAnnotationPresent(IgnoreEmergeSnapshot::class)) {
logger.info(
"Skipping ${function.simpleName.asString()} as it's annotated with @IgnoreEmergeSnapshot"
Expand Down
Loading