diff --git a/build.gradle.kts b/build.gradle.kts index bae462a..c815a43 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -78,6 +78,7 @@ detekt { sonarqube { properties { + property("sonar.projectName", "semver-gradle") property("sonar.projectKey", "ethauvin_semver-gradle") property("sonar.organization", "ethauvin-github") property("sonar.host.url", "https://sonarcloud.io") diff --git a/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverConfig.kt b/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverConfig.kt index ac7f703..75511e5 100644 --- a/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverConfig.kt +++ b/src/main/kotlin/net/thauvin/erik/gradle/semver/SemverConfig.kt @@ -96,28 +96,29 @@ open class SemverConfig @Inject constructor( val separator: String get() = semVersion.separator + override fun toString(): String { - return "SemverConfig(" + - "properties='$properties', " + - "semverKey='$semverKey', " + - "majorKey='$majorKey', " + - "minorKey='$minorKey', " + - "patchKey='$patchKey', " + - "preReleaseKey='$preReleaseKey', " + - "preReleasePrefixKey='$preReleasePrefixKey', " + - "buildMetaKey='$buildMetaKey', " + - "buildMetaPrefixKey='$buildMetaPrefixKey', " + - "separator='$separatorKey', " + - "keysPrefix='$keysPrefix', " + - "semver='$semver', " + - "major='$major', " + - "minor='$minor', " + - "patch='$patch', " + - "preRelease='$preRelease', " + - "buildMeta='$buildMeta', " + - "preReleasePrefix='$preReleasePrefix', " + - "buildMetaPrefix='$buildMetaPrefix', " + - "separator='$separator'" + - ')' + return mapOf( + Pair("properties", properties), + Pair("semverKey", semverKey), + Pair("majorKey", majorKey), + Pair("minorKey", minorKey), + Pair("patchKey", patchKey), + Pair("preReleaseKey", preReleaseKey), + Pair("preReleasePrefixKey", preReleasePrefixKey), + Pair("buildMetaKey", buildMetaKey), + Pair("buildMetaPrefixKey", buildMetaPrefixKey), + Pair("separator", separatorKey), + Pair("keysPrefix", keysPrefix), + Pair("semver", semver), + Pair("major", major), + Pair("minor", minor), + Pair("patch", patch), + Pair("preRelease", preRelease), + Pair("buildMeta", buildMeta), + Pair("preReleasePrefix", preReleasePrefix), + Pair("buildMetaPrefix", buildMetaPrefix), + Pair("separator", separator) + ).toString() } } diff --git a/src/main/kotlin/net/thauvin/erik/gradle/semver/Version.kt b/src/main/kotlin/net/thauvin/erik/gradle/semver/Version.kt index 0526348..77e824d 100644 --- a/src/main/kotlin/net/thauvin/erik/gradle/semver/Version.kt +++ b/src/main/kotlin/net/thauvin/erik/gradle/semver/Version.kt @@ -70,16 +70,5 @@ class Version { if (isPatch) patch++ } - override fun toString(): String { - return "Version(" + - "major='$major', " + - "minor='$minor', " + - "patch='$patch', " + - "preRelease='$preRelease', " + - "preReleasePrefix='$preReleasePrefix', " + - "buildMeta='$buildMeta', " + - "buildMetaPrefix='$buildMetaPrefix', " + - "separator='$separator', " + - ')' - } + override fun toString() = semver } diff --git a/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverConfigTest.kt b/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverConfigTest.kt index b9b4749..402b4ef 100644 --- a/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverConfigTest.kt +++ b/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverConfigTest.kt @@ -69,6 +69,11 @@ class SemverConfigTest { } assertEquals(config.properties, "version.properties", "config.properties should be version.properties") + + assertTrue( + config.toString().contains("properties=${SemverConfig.DEFAULT_PROPERTIES}"), + "toString contains default properties" + ) } @Test diff --git a/src/test/kotlin/net/thauvin/erik/gradle/semver/SortedPropertiesTest.kt b/src/test/kotlin/net/thauvin/erik/gradle/semver/SortedPropertiesTest.kt new file mode 100644 index 0000000..2724bf0 --- /dev/null +++ b/src/test/kotlin/net/thauvin/erik/gradle/semver/SortedPropertiesTest.kt @@ -0,0 +1,58 @@ +/* + * testSortedProperties.kt + * + * Copyright (c) 2018-2021, Erik C. Thauvin (erik@thauvin.net) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of this project nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package net.thauvin.erik.gradle.semver + +import kotlin.test.Test +import kotlin.test.assertEquals + +class SortedPropertiesTest { + @Test + fun testSortedProperties() { + val props = SortedProperties() + val fruits = setOf("Avocado", "Tomato", "apple", "banana", "cucumber", "zucchini") + + fruits.reversed().forEach { + props[it] = "test" + } + + val keys = props.keys().iterator() + fruits.forEach { + assertEquals(it, keys.next(), "$it key") + } + + val entries = props.entries.iterator() + fruits.forEach { + assertEquals(it, entries.next().key, "$it entry") + } + } +} diff --git a/src/test/kotlin/net/thauvin/erik/gradle/semver/UtilsTest.kt b/src/test/kotlin/net/thauvin/erik/gradle/semver/UtilsTest.kt index 05c1f6c..9290814 100644 --- a/src/test/kotlin/net/thauvin/erik/gradle/semver/UtilsTest.kt +++ b/src/test/kotlin/net/thauvin/erik/gradle/semver/UtilsTest.kt @@ -134,6 +134,16 @@ class UtilsTest { locked.delete() } + @Test + fun testLoadIntProperty() { + val props = SortedProperties() + props["foo"] = "bar" + + assertFailsWith { Utils.loadIntProperty(props, "foo", 1) } + + assertEquals(Utils.loadIntProperty(props, "none", 1), 1, "default int value") + } + @Test fun testPrefix() { version.preReleasePrefix = "." @@ -198,6 +208,7 @@ class UtilsTest { newPropsFile.delete() System.getProperties().setProperty(config.semverKey, "3.2.2") + props["foo"] = "bar" Utils.loadVersion(config, version, props) assertEquals(version.semver, System.getProperty(config.semverKey), "versions should match") } diff --git a/src/test/kotlin/net/thauvin/erik/gradle/semver/VersionTest.kt b/src/test/kotlin/net/thauvin/erik/gradle/semver/VersionTest.kt index 9e122d7..2b132d1 100644 --- a/src/test/kotlin/net/thauvin/erik/gradle/semver/VersionTest.kt +++ b/src/test/kotlin/net/thauvin/erik/gradle/semver/VersionTest.kt @@ -49,6 +49,7 @@ class VersionTest { assertEquals("+", version.buildMetaPrefix, "meta prefix should be +") assertEquals(".", version.separator, "separator should be .") assertEquals("1.0.0", version.semver, "version should be 1.0.0") + assertEquals(version.toString(), version.semver, "toString should be semver") } @Test @@ -102,5 +103,7 @@ class VersionTest { version.separator = "-" assertEquals("1-0-0--beta++007", version.semver, "should return 1-0-0--beta++007") + + assertEquals(version.toString(), version.semver, "toString() should return semver") } }