diff --git a/CHANGELOG.md b/CHANGELOG.md index 80572d3..0c1aeeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 3.3.2 +* Fix boolean parsing in plain class (#65) + # 3.3.1 * Revert breaking change to argument name resolution. The naming strategy can be changed in `configureArkenv`. diff --git a/arkenv/build.gradle.kts b/arkenv/build.gradle.kts index f4bd1c6..6e3f4fa 100644 --- a/arkenv/build.gradle.kts +++ b/arkenv/build.gradle.kts @@ -1,7 +1,7 @@ plugins { base - kotlin("jvm") version "1.4.32" - id("org.jetbrains.dokka") version "1.4.32" + kotlin("jvm") version "1.5.10" + id("org.jetbrains.dokka") version "1.5.0" id("java-test-fixtures") signing } @@ -24,6 +24,7 @@ dependencies { testFixturesApi("org.jmockit:jmockit:$jmockitVersion") testFixturesApi("org.amshove.kluent:kluent:$kluentVersion") testFixturesApi("org.junit.jupiter:junit-jupiter-api:$junitVersion") + testFixturesApi("org.junit.jupiter:junit-jupiter-params:$junitVersion") testFixturesApi("io.strikt:strikt-core:$striktVersion") testImplementation(testFixtures(project(":arkenv"))) diff --git a/arkenv/src/main/kotlin/com/apurebase/arkenv/ArkenvMapper.kt b/arkenv/src/main/kotlin/com/apurebase/arkenv/ArkenvMapper.kt index 02cab3d..99b619f 100644 --- a/arkenv/src/main/kotlin/com/apurebase/arkenv/ArkenvMapper.kt +++ b/arkenv/src/main/kotlin/com/apurebase/arkenv/ArkenvMapper.kt @@ -31,6 +31,7 @@ internal object ArkenvMapper { Long::class -> toLongOrNull() String::class -> this Char::class -> firstOrNull() + Boolean::class -> toBoolean() || this == "1" List::class, Collection::class -> split() IntArray::class -> split().map(String::toInt).toIntArray() ShortArray::class -> split().map(String::toShort).toShortArray() diff --git a/arkenv/src/test/kotlin/com/apurebase/arkenv/ParseClassTests.kt b/arkenv/src/test/kotlin/com/apurebase/arkenv/ParseClassTests.kt index e67d688..66eee06 100644 --- a/arkenv/src/test/kotlin/com/apurebase/arkenv/ParseClassTests.kt +++ b/arkenv/src/test/kotlin/com/apurebase/arkenv/ParseClassTests.kt @@ -5,9 +5,13 @@ import com.apurebase.arkenv.test.Expected import com.apurebase.arkenv.util.argument import com.apurebase.arkenv.util.parse import org.junit.jupiter.api.Test +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.ValueSource import strikt.api.expectThat import strikt.assertions.isEqualTo +import strikt.assertions.isFalse import strikt.assertions.isNull +import strikt.assertions.isTrue /** * Tests for the [ArkenvParser.parseClass] functionality, parsing plain classes. @@ -94,4 +98,30 @@ class ParseClassTests { get { databasePort } isEqualTo Expected.databasePort } } + + @ParameterizedTest + @ValueSource(strings = ["true", "1"]) + fun `boolean true`(input: String) { + // Arrange + class Configuration(val headless: Boolean = false) + + // Act + val config = Arkenv.parse(arrayOf("--headless", input)) + + // Assert + expectThat(config) { get { headless }.isTrue() } + } + + @ParameterizedTest + @ValueSource(strings = ["false", "0", ""]) + fun `boolean false`(input: String) { + // Arrange + class Configuration(val headless: Boolean = false) + + // Act + val config = Arkenv.parse(arrayOf("--headless", input)) + + // Assert + expectThat(config) { get { headless }.isFalse() } + } } diff --git a/gradle.properties b/gradle.properties index 3096b94..082706a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ group=com.apurebase -version=3.3.1 +version=3.3.2 # Versions junitVersion=5.7.1 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 0f80bbf..69a9715 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists