From 5e5083ef1c4802a3807af3d507c6b44d90e9de81 Mon Sep 17 00:00:00 2001 From: Brian Norman Date: Wed, 12 Feb 2020 22:23:28 -0600 Subject: [PATCH] Prepare for release 0.2.0 --- CHANGELOG.md | 9 +++++ README.md | 33 +++++++++++++++++-- build.gradle.kts | 2 +- .../bnorm/power/PowerAssertGradleSubplugin.kt | 2 +- .../src/test/kotlin/com/bnorm/power/test.kt | 10 +++--- 5 files changed, 47 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a93ffb05844..9f04ba9d971 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ Change Log ========== +## Version 0.2.0 + +_2020-02-12_ + + * Support configuring of which functions are transformed (eg, assert, require, + check, assertTrue). This works for any function which takes a Boolean and a + String. + * Support Boolean expressions which are split onto multiple lines. + ## Version 0.1.0 _2020-02-10_ diff --git a/README.md b/README.md index d065dbab076..2bf85607a3b 100644 --- a/README.md +++ b/README.md @@ -51,24 +51,51 @@ assert(hello.length == "World".substring(1, 4).length) at ``` +Complex, multi-line, boolean expression are also supported: + +```text +Assertion failed +assert( + (text != null && text.toLowerCase() == text) || + | | + | false + null + text == "Hello" + | | + | false + null +) +``` + ## Gradle Plugin Builds of the Gradle plugin are available through the [Gradle Plugin Portal][kotlin-power-assert-gradle]. -```groovy +```kotlin plugins { - id "com.bnorm.power.kotlin-power-assert" version "0.1.0" + id("com.bnorm.power.kotlin-power-assert") version "0.2.0" } ``` +The plugin by default will transform `assert` function call but can also +transform other functions like `require`, `check`, and/or `assertTrue`. The +function needs to validate the Boolean expression evaluates to `true` and has a +form which also takes a String or String producing lambda. + +```kotlin +configure { + functions = listOf("kotlin.test.AssertionsKt.assertTrue", "kotlin.PreconditionsKt.require") +} +``` + ## Kotlin IR Using this compiler plugin only works if the code is compiled using IR. This can be enabled only when compiling the test SourceSet if desired. As Kotlin IR is still experimental, mileage may vary. -```groovy +```kotlin compileTestKotlin { kotlinOptions { useIR = true diff --git a/build.gradle.kts b/build.gradle.kts index 8ee5786eb5c..738e8ce64b9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ plugins { allprojects { group = "com.bnorm.power" - version = "0.2.0-SNAPSHOT" + version = "0.2.0" } subprojects { diff --git a/kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradleSubplugin.kt b/kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradleSubplugin.kt index b1264ad2763..29c922eabb3 100644 --- a/kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradleSubplugin.kt +++ b/kotlin-power-assert-gradle/src/main/kotlin/com/bnorm/power/PowerAssertGradleSubplugin.kt @@ -37,7 +37,7 @@ class PowerAssertGradleSubplugin : KotlinGradleSubplugin { override fun getPluginArtifact(): SubpluginArtifact = SubpluginArtifact( groupId = "com.bnorm.power", artifactId = "kotlin-power-assert", - version = "0.2.0-SNAPSHOT" + version = "0.2.0" ) override fun apply( diff --git a/kotlin-power-assert/src/test/kotlin/com/bnorm/power/test.kt b/kotlin-power-assert/src/test/kotlin/com/bnorm/power/test.kt index 389ffb72489..598d6d6fee0 100644 --- a/kotlin-power-assert/src/test/kotlin/com/bnorm/power/test.kt +++ b/kotlin-power-assert/src/test/kotlin/com/bnorm/power/test.kt @@ -228,10 +228,12 @@ assert(text == null || (text.length == 5 && text.toLowerCase() == text)) @Test fun booleanMixOrLast() { assertMessage( - """ -fun main() { - val text = "Hello" - assert((text.length == 5 && text.toLowerCase() == text) || text.length == 1) + """fun main() { + val text: String? = null + assert( + (text != null && text.toLowerCase() == text) || + text == "Hello" + ) }""", """ Assertion failed