mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 21:05:28 +00:00
Remove LayoutLibErrorFilterStatement
Paparazzi 2.0.0-alpha05.1 ships layoutlib 16.2.3, which fixes the errors this rule was swallowing. All screenshot tests pass without it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+1
-1
@@ -237,7 +237,7 @@ subprojects {
|
||||
//
|
||||
// Pruning per preview, and not per screenshot, is deliberate: a preview that fails to render is absent
|
||||
// from the run report in exactly the same way as a preview that was deleted, and LayoutLib does fail to
|
||||
// render a preview now and then (see LayoutLibErrorFilterStatement). Matching whole previews means such
|
||||
// render a preview now and then. Matching whole previews means such
|
||||
// a failure leaves the other screenshots of that preview in place, so it cannot silently delete a
|
||||
// screenshot that is still in use. The cost is that dropping one value from a PreviewParameterProvider
|
||||
// leaves its last screenshot behind, since the preview itself still renders. Run `removeOldSnapshots`
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2026 Element Creations Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package ui
|
||||
|
||||
import org.junit.rules.TestRule
|
||||
import org.junit.runner.Description
|
||||
import org.junit.runners.model.Statement
|
||||
|
||||
/**
|
||||
* Workaround for Paparazzi 2.0.0-alpha05 / LayoutLib 16.2.1 bug where
|
||||
* HandlerThread_Delegate calls Thread.setPosixNicenessInternal which doesn't exist on JVM.
|
||||
* Tracked in https://github.com/cashapp/paparazzi/issues/2342 — fixed in layoutlib 16.2.3.
|
||||
* Remove this workaround once Paparazzi ships with layoutlib >= 16.2.3.
|
||||
*
|
||||
* Paparazzi's PaparazziLogger collects background thread errors and re-throws them via
|
||||
* assertNoErrors(). This Statement wrapper catches the known NoSuchMethodError so the test
|
||||
* can pass despite the LayoutLib bug.
|
||||
*/
|
||||
class LayoutLibErrorFilterStatement : TestRule {
|
||||
override fun apply(base: Statement, description: Description): Statement {
|
||||
return object : Statement() {
|
||||
@Throws(Throwable::class)
|
||||
override fun evaluate() {
|
||||
try {
|
||||
base.evaluate()
|
||||
} catch (e: NoSuchMethodError) {
|
||||
if (e.message?.contains("setPosixNicenessInternal") != true) throw e
|
||||
} catch (npe: NullPointerException) {
|
||||
// Also catch this error on `HorizontalFloatingToolbarPreview` and `HorizontalFloatingToolbarNoFabPreview`
|
||||
if (npe.message?.contains("""Cannot invoke "java.util.ArrayList.size()" because "childrenList" is null""") != true) throw npe
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,10 +29,7 @@ class PreviewA11yTest(
|
||||
@TestParameter(valuesProvider = ComposableA11yPreviewProvider::class)
|
||||
val preview: ComposablePreview<AndroidPreviewInfo>,
|
||||
) {
|
||||
@get:Rule(order = 0)
|
||||
val layoutLibErrorFilterStatement = LayoutLibErrorFilterStatement()
|
||||
|
||||
@get:Rule(order = 1)
|
||||
@get:Rule
|
||||
val paparazziRule = PaparazziPreviewRule.createFor(
|
||||
preview = preview,
|
||||
locale = "en",
|
||||
|
||||
@@ -28,10 +28,7 @@ class PreviewShard1Test(
|
||||
@TestParameter(valuesProvider = Shard1ComposablePreviewProvider::class)
|
||||
val preview: ComposablePreview<AndroidPreviewInfo>,
|
||||
) {
|
||||
@get:Rule(order = 0)
|
||||
val layoutLibErrorFilterStatement = LayoutLibErrorFilterStatement()
|
||||
|
||||
@get:Rule(order = 1)
|
||||
@get:Rule
|
||||
val paparazziRule = PaparazziPreviewRule.createFor(preview, locale = "en")
|
||||
|
||||
@Test
|
||||
|
||||
@@ -28,10 +28,7 @@ class PreviewShard2Test(
|
||||
@TestParameter(valuesProvider = Shard2ComposablePreviewProvider::class)
|
||||
val preview: ComposablePreview<AndroidPreviewInfo>,
|
||||
) {
|
||||
@get:Rule(order = 0)
|
||||
val layoutLibErrorFilterStatement = LayoutLibErrorFilterStatement()
|
||||
|
||||
@get:Rule(order = 1)
|
||||
@get:Rule
|
||||
val paparazziRule = PaparazziPreviewRule.createFor(preview, locale = "en")
|
||||
|
||||
@Test
|
||||
|
||||
@@ -28,10 +28,7 @@ class PreviewShard3Test(
|
||||
@TestParameter(valuesProvider = Shard3ComposablePreviewProvider::class)
|
||||
val preview: ComposablePreview<AndroidPreviewInfo>,
|
||||
) {
|
||||
@get:Rule(order = 0)
|
||||
val layoutLibErrorFilterStatement = LayoutLibErrorFilterStatement()
|
||||
|
||||
@get:Rule(order = 1)
|
||||
@get:Rule
|
||||
val paparazziRule = PaparazziPreviewRule.createFor(preview, locale = "en")
|
||||
|
||||
@Test
|
||||
|
||||
@@ -28,10 +28,7 @@ class PreviewShard4Test(
|
||||
@TestParameter(valuesProvider = Shard4ComposablePreviewProvider::class)
|
||||
val preview: ComposablePreview<AndroidPreviewInfo>,
|
||||
) {
|
||||
@get:Rule(order = 0)
|
||||
val layoutLibErrorFilterStatement = LayoutLibErrorFilterStatement()
|
||||
|
||||
@get:Rule(order = 1)
|
||||
@get:Rule
|
||||
val paparazziRule = PaparazziPreviewRule.createFor(preview, locale = "en")
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user