From e60b62799659e5d6cff8d7730d350a70750d20c4 Mon Sep 17 00:00:00 2001 From: Simon Vergauwen Date: Wed, 30 Aug 2023 09:31:21 +0200 Subject: [PATCH] Fix optics tests --- .../optics/plugin/internals/processor.kt | 24 +++++++------------ .../kotlin/arrow/optics/plugin/Compilation.kt | 8 +++++-- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt index b42b9a8e97e..ac05262e74b 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/internals/processor.kt @@ -22,12 +22,15 @@ internal fun adt(c: KSClassDeclaration, logger: KSPLogger): ADT = OpticsTarget.LENS -> evalAnnotatedDataClass(c, c.qualifiedNameOrSimpleName.lensErrorMessage, logger) .let(::LensTarget) + OpticsTarget.ISO -> evalAnnotatedValueClass(c, c.qualifiedNameOrSimpleName.isoErrorMessage, logger) .let(::IsoTarget) + OpticsTarget.PRISM -> evalAnnotatedPrismElement(c, c.qualifiedNameOrSimpleName.prismErrorMessage, logger) .let(::PrismTarget) + OpticsTarget.DSL -> evalAnnotatedDslElement(c, logger) } }, @@ -37,25 +40,16 @@ internal fun KSClassDeclaration.targets(): List = targetsFromOpticsAnnotation().let { targets -> when { isSealed -> - if (targets.isEmpty()) { - listOf(OpticsTarget.PRISM, OpticsTarget.DSL) - } else { - targets.filter { it == OpticsTarget.PRISM || it == OpticsTarget.DSL } - } + listOf(OpticsTarget.PRISM, OpticsTarget.DSL) + .filter { targets.isEmpty() || it in targets } + isValue -> listOf(OpticsTarget.ISO, OpticsTarget.DSL) .filter { targets.isEmpty() || it in targets } + else -> - if (targets.isEmpty()) { - listOf(OpticsTarget.ISO, OpticsTarget.LENS, OpticsTarget.DSL) - } else { - targets.filter { - when (it) { - OpticsTarget.ISO, OpticsTarget.LENS, OpticsTarget.DSL -> true - else -> false - } - } - } + listOf(OpticsTarget.LENS, OpticsTarget.DSL) + .filter { targets.isEmpty() || it in targets } } } diff --git a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/Compilation.kt b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/Compilation.kt index 37380de368a..f2c70b03b2a 100644 --- a/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/Compilation.kt +++ b/arrow-libs/optics/arrow-optics-ksp-plugin/src/test/kotlin/arrow/optics/plugin/Compilation.kt @@ -28,12 +28,16 @@ fun String.compilationFails() { fun String.compilationSucceeds(allWarningsAsErrors: Boolean = false) { val compilationResult = compile(this, allWarningsAsErrors = allWarningsAsErrors) - Assertions.assertThat(compilationResult.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) + Assertions.assertThat(compilationResult.exitCode) + .withFailMessage(compilationResult.messages) + .isEqualTo(KotlinCompilation.ExitCode.OK) } fun String.evals(thing: Pair) { val compilationResult = compile(this) - Assertions.assertThat(compilationResult.exitCode).isEqualTo(KotlinCompilation.ExitCode.OK) + Assertions.assertThat(compilationResult.exitCode) + .withFailMessage(compilationResult.messages) + .isEqualTo(KotlinCompilation.ExitCode.OK) val classesDirectory = compilationResult.outputDirectory val (variable, output) = thing Assertions.assertThat(eval(variable, classesDirectory)).isEqualTo(output)