diff --git a/.gitignore b/.gitignore
index f007981..13a066e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,22 +1,7 @@
-.vscode/*
!.vscode/extensions.json
!.vscode/launch.json
!.vscode/settings.json
!.vscode/tasks.json
-
-__pycache__
-.classpath
-.DS_Store
-.gradle
-.history
-.kobalt
-.mtj.tmp/
-.mvn/timing.properties
-.mvn/wrapper/maven-wrapper.jar
-.nb-gradle
-.project
-.scannerwork
-.settings
*.class
*.code-workspace
*.ctxt
@@ -27,7 +12,21 @@ __pycache__
*.sublime-*
*.tar.gz
*.zip
-/**/.idea_modules/
+.DS_Store
+.classpath
+.gradle
+.history
+.kobalt
+.mtj.tmp/
+.mvn/timing.properties
+.mvn/wrapper/maven-wrapper.jar
+.nb-gradle
+.project
+.scannerwork
+.settings
+.vscode/*
+/**/.idea/$CACHE_FILE$
+/**/.idea/$PRODUCT_WORKSPACE_FILE$
/**/.idea/**/caches/build_file_checksums.ser
/**/.idea/**/contentModel.xml
/**/.idea/**/dataSources.ids
@@ -48,8 +47,10 @@ __pycache__
/**/.idea/**/uiDesigner.xml
/**/.idea/**/usage.statistics.xml
/**/.idea/**/workspace.xml
-/**/.idea/$CACHE_FILE$
-/**/.idea/$PRODUCT_WORKSPACE_FILE$
+/**/.idea/sonarlint*
+/**/.idea_modules/
+Thumbs.db
+__pycache__
atlassian-ide-plugin.xml
bin/
build/
@@ -71,6 +72,7 @@ lib/kotlin*
libs/
local.properties
out/
+pom.xml.asc
pom.xml.next
pom.xml.releaseBackup
pom.xml.tag
@@ -80,5 +82,4 @@ project.properties
release.properties
target/
test-output
-Thumbs.db
venv
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index 98b5537..a0e051e 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -26,5 +26,15 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries-with-intellij-classes.xml b/.idea/libraries-with-intellij-classes.xml
new file mode 100644
index 0000000..9fa3156
--- /dev/null
+++ b/.idea/libraries-with-intellij-classes.xml
@@ -0,0 +1,65 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 692822a..d38657d 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -13,7 +13,7 @@
-
+
\ No newline at end of file
diff --git a/build.gradle.kts b/build.gradle.kts
index 4bf1661..8beaa4d 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -18,10 +18,6 @@ plugins {
version = "1.0.5"
group = "net.thauvin.erik.gradle"
-object Versions {
- const val SPEK = "2.0.15" // Don't upgrade until 2.0.17
-}
-
val github = "https://github.com/ethauvin/semver-gradle"
val packageName = "net.thauvin.erik.gradle.semver"
@@ -35,14 +31,11 @@ dependencies {
implementation(platform(kotlin("bom")))
implementation(kotlin("stdlib"))
-
- testImplementation(kotlin("reflect"))
- testImplementation(kotlin("test"))
//testImplementation(gradleTestKit())
- testImplementation("org.spekframework.spek2:spek-dsl-jvm:${Versions.SPEK}")
- testRuntimeOnly("org.spekframework.spek2:spek-runner-junit5:${Versions.SPEK}")
+ testImplementation(kotlin("test"))
+ testImplementation(kotlin("test-junit"))
}
tasks {
@@ -57,11 +50,7 @@ tasks {
withType {
testLogging {
exceptionFormat = TestExceptionFormat.FULL
- events = setOf(TestLogEvent.SKIPPED, TestLogEvent.FAILED)
- }
-
- useJUnitPlatform {
- includeEngines("spek2")
+ events = setOf(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
}
}
diff --git a/detekt-baseline.xml b/detekt-baseline.xml
index 52cc674..43012a1 100644
--- a/detekt-baseline.xml
+++ b/detekt-baseline.xml
@@ -2,6 +2,7 @@
+ LongMethod:UtilsTest.kt$UtilsTest$@Test fun testSystemProperties()
MagicNumber:Utils.kt$Utils$3
MagicNumber:Utils.kt$Utils$4
MagicNumber:Utils.kt$Utils$5
diff --git a/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverConfigSpec.kt b/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverConfigSpec.kt
deleted file mode 100644
index 3a5ef79..0000000
--- a/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverConfigSpec.kt
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * SemverConfigSpec.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 org.spekframework.spek2.Spek
-import org.spekframework.spek2.style.gherkin.Feature
-import kotlin.test.assertEquals
-import kotlin.test.assertTrue
-
-@Suppress("unused")
-object SemverConfigSpec : Spek({
- Feature("SemverConfig") {
- val config = SemverConfig(Version())
- Scenario("Testing configs") {
- val vars = listOf(
- config.semverKey,
- config.majorKey,
- config.minorKey,
- config.patchKey,
- config.preReleaseKey,
- config.preReleasePrefixKey,
- config.buildMetaKey,
- config.buildMetaPrefixKey,
- config.separatorKey
- )
- val defaults = listOf(
- SemverConfig.DEFAULT_SEMVER_KEY,
- SemverConfig.DEFAULT_MAJOR_KEY,
- SemverConfig.DEFAULT_MINOR_KEY,
- SemverConfig.DEFAULT_PATCH_KEY,
- SemverConfig.DEFAULT_PRERELEASE_KEY,
- SemverConfig.DEFAULT_PRERELEASE_PREFIX_KEY,
- SemverConfig.DEFAULT_BUILDMETA_KEY,
- SemverConfig.DEFAULT_BUILDMETA_PREFIX_KEY,
- SemverConfig.DEFAULT_SEPARATOR
- )
-
- When("checking defaults") {}
-
- defaults.forEachIndexed { i, d ->
- Then(" ${vars[i]} should be the same: ${config.keysPrefix}$d") {
- assertEquals(vars[i], "${config.keysPrefix}$d")
- }
- }
-
- Then("config.properties should be version.properties") {
- assertEquals(config.properties, "version.properties")
- }
-
- lateinit var newKeys: List
-
- When("setting keyPrefix to test.") {
- config.keysPrefix = "test."
- newKeys = listOf(
- config.semverKey,
- config.majorKey,
- config.minorKey,
- config.patchKey,
- config.preReleaseKey,
- config.preReleasePrefixKey,
- config.buildMetaKey,
- config.buildMetaPrefixKey,
- config.separatorKey
- )
- }
-
- Then("all config keys should start with test.xxxx") {
- newKeys.forEach { k ->
- assertTrue(k.startsWith("test."), k)
- }
- }
-
- When("checking extension properties") {}
-
- Then("semver should be defaults") {
- val defaultSemver =
- "${Version.DEFAULT_MAJOR}${Version.DEFAULT_SEPARATOR}${Version.DEFAULT_MINOR}" +
- "${Version.DEFAULT_SEPARATOR}${Version.DEFAULT_PATCH}"
- assertEquals(config.semver, defaultSemver)
- assertEquals(
- "${config.major}${config.separator}${config.minor}${config.separator}${config.patch}",
- defaultSemver
- )
- assertEquals(config.preRelease, Version.DEFAULT_EMPTY)
- assertEquals(config.buildMeta, Version.DEFAULT_EMPTY)
- assertEquals(config.preReleasePrefix, Version.DEFAULT_PRERELEASE_PREFIX)
- assertEquals(config.buildMetaPrefix, Version.DEFAULT_BUILDMETA_PREFIX)
- }
-
- Then("semver = version") {
- assertEquals(config.semver, config.version)
- }
- }
- }
-})
diff --git a/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverConfigTest.kt b/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverConfigTest.kt
new file mode 100644
index 0000000..b9b4749
--- /dev/null
+++ b/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverConfigTest.kt
@@ -0,0 +1,110 @@
+/*
+ * SemverConfigTest.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
+import kotlin.test.assertTrue
+
+class SemverConfigTest {
+ private val config = SemverConfig(Version())
+
+ @Test
+ fun testConfigs() {
+ val vars = listOf(
+ config.semverKey,
+ config.majorKey,
+ config.minorKey,
+ config.patchKey,
+ config.preReleaseKey,
+ config.preReleasePrefixKey,
+ config.buildMetaKey,
+ config.buildMetaPrefixKey,
+ config.separatorKey
+ )
+ val defaults = listOf(
+ SemverConfig.DEFAULT_SEMVER_KEY,
+ SemverConfig.DEFAULT_MAJOR_KEY,
+ SemverConfig.DEFAULT_MINOR_KEY,
+ SemverConfig.DEFAULT_PATCH_KEY,
+ SemverConfig.DEFAULT_PRERELEASE_KEY,
+ SemverConfig.DEFAULT_PRERELEASE_PREFIX_KEY,
+ SemverConfig.DEFAULT_BUILDMETA_KEY,
+ SemverConfig.DEFAULT_BUILDMETA_PREFIX_KEY,
+ SemverConfig.DEFAULT_SEPARATOR
+ )
+
+ defaults.forEachIndexed { i, d ->
+ assertEquals(vars[i], "${config.keysPrefix}$d", " ${vars[i]} should be the same: ${config.keysPrefix}$d")
+ }
+
+ assertEquals(config.properties, "version.properties", "config.properties should be version.properties")
+ }
+
+ @Test
+ fun testExtensionProperties() {
+ config.keysPrefix = "test."
+
+ val newKeys = listOf(
+ config.semverKey,
+ config.majorKey,
+ config.minorKey,
+ config.patchKey,
+ config.preReleaseKey,
+ config.preReleasePrefixKey,
+ config.buildMetaKey,
+ config.buildMetaPrefixKey,
+ config.separatorKey
+ )
+
+ newKeys.forEach { k ->
+ assertTrue(k.startsWith("test."), "$k: all config keys should start with test.xxxx")
+ }
+
+ val defaultSemver =
+ "${Version.DEFAULT_MAJOR}${Version.DEFAULT_SEPARATOR}${Version.DEFAULT_MINOR}" +
+ "${Version.DEFAULT_SEPARATOR}${Version.DEFAULT_PATCH}"
+ assertEquals(config.semver, defaultSemver, "semver should be defaults")
+ assertEquals(
+ "${config.major}${config.separator}${config.minor}${config.separator}${config.patch}",
+ defaultSemver,
+ "major-minor-patch should be defaults."
+ )
+ assertEquals(config.preRelease, Version.DEFAULT_EMPTY, "preRelease empty default")
+ assertEquals(config.buildMeta, Version.DEFAULT_EMPTY, "buildMeta empty default")
+ assertEquals(config.preReleasePrefix, Version.DEFAULT_PRERELEASE_PREFIX, "preReleasePrefix default")
+ assertEquals(config.buildMetaPrefix, Version.DEFAULT_BUILDMETA_PREFIX, "buildMetaPrefix default")
+
+ assertEquals(config.semver, config.version, "semver = version")
+ }
+}
diff --git a/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverVersionSpec.kt b/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverVersionSpec.kt
deleted file mode 100644
index b7276a3..0000000
--- a/src/test/kotlin/net/thauvin/erik/gradle/semver/SemverVersionSpec.kt
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * SemverVersionSpec.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 org.spekframework.spek2.Spek
-import org.spekframework.spek2.style.gherkin.Feature
-import kotlin.test.assertEquals
-
-@Suppress("unused")
-object SemverVersionSpec : Spek({
- Feature("SemverVersion") {
- val version = Version()
- Scenario("Testing Versions") {
- When("validating default version") {}
-
- Then("major should be 1") {
- assertEquals(1, version.major)
- }
-
- Then("minor should be 1") {
- assertEquals(0, version.minor)
- }
-
- Then("patch should be 0") {
- assertEquals(0, version.patch)
- }
-
- Then("prerelease should be empty") {
- assertEquals("", version.preRelease)
- }
-
- Then("meta should be empty") {
- assertEquals("", version.buildMeta)
- }
-
- Then("preRelease prefix should be -") {
- assertEquals("-", version.preReleasePrefix)
- }
-
- Then("meta prefix should be +") {
- assertEquals("+", version.buildMetaPrefix)
- }
-
- Then("separator should be .") {
- assertEquals(".", version.separator)
- }
-
- Then("version should be 1.0.0") {
- assertEquals("1.0.0", version.semver)
- }
-
- When("incrementing major") {
- version.increment(isMajor = true)
- }
-
- Then("should return 2.0.0") {
- assertEquals("2.0.0", version.semver)
- }
-
- When("incrementing minor") {
- version.increment(isMinor = true)
- }
-
- Then("should return 2.1.0") {
- assertEquals("2.1.0", version.semver)
- }
-
- When("incrementing patch") {
- version.increment(isPatch = true)
- }
-
- Then("should return 2.1.1") {
- assertEquals("2.1.1", version.semver)
- }
-
- When("incrementing minor again") {
- version.increment(isMinor = true)
- }
-
- Then("should return 2.2.0") {
- assertEquals("2.2.0", version.semver)
- }
-
- When("incrementing major again") {
- version.increment(isMajor = true)
- }
-
- Then("should return 3.0.0") {
- assertEquals("3.0.0", version.semver)
- }
-
- When("incrementing all") {
- version.increment(isMajor = true, isMinor = true, isPatch = true)
- }
-
- Then("should return 4.1.1") {
- assertEquals("4.1.1", version.semver)
- }
-
- When("incrementing major and minor") {
- version.increment(isMajor = true, isMinor = true)
- }
-
- Then("should return 5.1.0") {
- assertEquals("5.1.0", version.semver)
- }
-
- When("incrementing minor and patch") {
- version.increment(isMinor = true, isPatch = true)
- }
- Then("should return 5.2.1") {
- assertEquals("5.2.1", version.semver)
- }
-
- When("incrementing nothing") {
- version.increment()
- }
- Then("should still return 5.2.1") {
- assertEquals("5.2.1", version.semver)
- }
-
- When("resetting version") {
- version.major = 1
- version.minor = 0
- version.patch = 0
- }
-
- Then("should return 1.0.0") {
- assertEquals("1.0.0", version.semver)
- }
-
- When("adding prerelease") {
- version.preRelease = "beta"
- }
-
- Then("should return 1.0.0-beta") {
- assertEquals("1.0.0-beta", version.semver)
- }
-
- When("adding metadata") {
- version.buildMeta = "007"
- }
-
- Then("should return 1.0.0-beta+007") {
- assertEquals("1.0.0-beta+007", version.semver)
- }
-
- When("changing prerelease prefix") {
- version.preReleasePrefix = "--"
- }
-
- Then("should return 1.0.0--beta+007") {
- assertEquals("1.0.0--beta+007", version.semver)
- }
-
- When("changing meta prefix") {
- version.buildMetaPrefix = "++"
- }
-
- Then("should return 1.0.0--beta++007") {
- assertEquals("1.0.0--beta++007", version.semver)
- }
-
- When("changing separator") {
- version.separator = "-"
- }
-
- Then("should return 1-0-0--beta++007") {
- assertEquals("1-0-0--beta++007", version.semver)
- }
- }
- }
-})
diff --git a/src/test/kotlin/net/thauvin/erik/gradle/semver/UtilsSpec.kt b/src/test/kotlin/net/thauvin/erik/gradle/semver/UtilsSpec.kt
deleted file mode 100644
index 1e02365..0000000
--- a/src/test/kotlin/net/thauvin/erik/gradle/semver/UtilsSpec.kt
+++ /dev/null
@@ -1,271 +0,0 @@
-/*
- * UtilsSpec.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 net.thauvin.erik.gradle.semver.Utils.canReadFile
-import org.gradle.api.GradleException
-import org.spekframework.spek2.Spek
-import org.spekframework.spek2.style.gherkin.Feature
-import java.io.File
-import java.util.*
-import kotlin.test.assertEquals
-import kotlin.test.assertFailsWith
-import kotlin.test.assertNull
-import kotlin.test.assertTrue
-
-@Suppress("unused")
-object UtilsSpec : Spek(
- {
- Feature("Utils") {
- val version = Version()
- val config = SemverConfig(version)
- val propsFile = File("test.properties")
- val projectDir = File("./")
- lateinit var props: Properties
-
- Scenario("Save/Load Properties") {
- When("saving the property") {
- config.properties = propsFile.name
- Utils.saveProperties(projectDir, config, version)
- }
-
- Then("properties file should exists and be readable") {
- assertEquals(propsFile.canReadFile(), propsFile.canRead() && propsFile.isFile)
- }
-
- When("loading the properties file") {
- props = Utils.loadProperties(propsFile)
- propsFile.delete()
- }
-
- Then("version and properties should be the same.") {
- assertEquals(props.getProperty(config.majorKey), version.major.toString(), "Major")
- assertEquals(props.getProperty(config.minorKey), version.minor.toString(), "Minor")
- assertEquals(props.getProperty(config.patchKey), version.patch.toString(), "Patch")
- assertEquals(props.getProperty(config.preReleaseKey), version.preRelease, "PreRelease")
- assertNull(props.getProperty(config.preReleasePrefixKey), "PreRelease Prefix")
- assertEquals(props.getProperty(config.buildMetaKey), version.buildMeta, "Build Meta")
- assertNull(props.getProperty(config.buildMetaPrefixKey), "Build Meta Prefix")
- assertNull(props.getProperty(config.separatorKey), "Separator")
- assertEquals(props.getProperty(config.semverKey), version.semver, "semver")
- }
- }
-
- Scenario("System Properties") {
- lateinit var sysProps: Array>
-
- Given("new system properties") {
- sysProps = arrayOf(
- Pair(config.majorKey, "2"),
- Pair(config.minorKey, "1"),
- Pair(config.patchKey, "1"),
- Pair(config.preReleaseKey, "beta"),
- Pair(config.buildMetaKey, "007")
- )
- }
-
- Then("none should already exists") {
- assertTrue(
- Utils.isNotSystemProperty(
- setOf(
- config.majorKey,
- config.minorKey,
- config.patchKey,
- config.preReleaseKey,
- config.buildMetaKey
- )
- )
- )
- }
-
- Then("version should match system properties") {
- sysProps.forEach {
- System.getProperties().setProperty(it.first, it.second)
- if (it.first == config.majorKey || it.first == config.minorKey || it.first == config.patchKey) {
- assertEquals(Utils.loadIntProperty(props, it.first, -1), it.second.toInt())
- } else {
- assertEquals(Utils.loadProperty(props, it.first, ""), it.second)
- }
- }
- }
-
- When("loading version") {
- Utils.loadVersion(config, version, props)
- }
-
- Then("version should be identical") {
- assertEquals(version.semver, "2.1.1-beta+007")
- }
-
- When("saving properties") {
- Utils.saveProperties(projectDir, config, version)
- }
-
- lateinit var newProps: Properties
-
- And("loading properties file") {
- newProps = Utils.loadProperties(propsFile)
- }
-
- Then("new properties should validate") {
- sysProps.forEach {
- assertEquals(newProps.getProperty(it.first), it.second, it.second)
- }
- propsFile.delete()
- }
-
- When("setting the version as system property") {
- System.getProperties().setProperty(config.semverKey, "3.2.2")
- }
-
- And("loading the properties") {
- Utils.loadVersion(config, version, props)
- }
-
- Then("versions should match") {
- assertEquals(version.semver, System.getProperty(config.semverKey))
- }
- }
-
- Scenario("Version Parsing") {
- When("validating version parsing") {}
-
- Then("versions should parse") {
- listOf(
- "1.0.0",
- "2.1.0-beta",
- "3.2.1-beta+007",
- "4.3.2+007",
- "11.11.1",
- "111.11.11-beta",
- "1111.111.11-beta+001.12"
- ).forEach {
- assertTrue(Utils.parseSemVer(it, version), "parsing semver: $it")
- assertEquals(it, version.semver, it)
- }
- }
-
- Then("should throw exceptions") {
- assertFailsWith("2.1.1a") {
- Utils.parseSemVer("2.1.1a", version)
- }
- assertFailsWith("2a.1.1") {
- Utils.parseSemVer("2a.1.1", version)
- }
- assertFailsWith("2.1a.1") {
- Utils.parseSemVer("2.1a.1", version)
- }
- assertFailsWith("2.1") {
- Utils.parseSemVer("2.1", version)
- }
- }
-
- Given("new prefixes") {
- version.preReleasePrefix = "."
- version.buildMetaPrefix = "."
- }
-
- Then("prefixes should parse") {
- listOf("2.1.0.beta.1", "2.1.1.1", "3.2.1.beta.1.007").forEach {
- assertTrue(Utils.parseSemVer(it, version), "parsing semver: $it")
- assertEquals(it, version.semver, it)
- }
- }
-
- Then("last pre-release and meta should match") {
- assertEquals(version.preRelease, "beta")
- assertEquals(version.buildMeta, "1.007")
- }
- }
-
- Scenario("Load locked properties") {
- lateinit var locked: File
-
- Given("the locked location") {
- locked = File("locked")
- }
-
- Then("loading locked properties") {
- assertFailsWith {
- Utils.loadProperties(File(locked, propsFile.name))
- }
- locked.delete()
- }
- }
-
- Scenario("Save to locked properties") {
- lateinit var propsLocked: File
- Given("the locked properties") {
- propsLocked = File(System.getProperty("user.home") + File.separator + "locked.properties")
- propsLocked.createNewFile()
- propsLocked.setReadOnly()
- config.properties = propsLocked.name
- }
-
- Then("saving the locked properties file") {
- if (!propsLocked.canWrite()) {
- assertFailsWith {
- Utils.saveProperties(propsLocked.parentFile, config, version)
- }
- }
- propsLocked.delete()
- }
- }
-
- Scenario("Save/Load Properties in foo") {
- lateinit var fooDir: File
- lateinit var fooProps: File
- When("saving the foo property") {
- fooDir = File("foo")
- fooDir.mkdir()
- fooProps = File(fooDir, propsFile.name)
- config.properties = fooProps.absolutePath
- Utils.saveProperties(projectDir, config, version)
- }
-
- Then("foo properties file should exists and be readable") {
- assertEquals(fooProps.canReadFile(), fooProps.canRead() && fooProps.isFile)
- }
-
- When("loading the foo properties file") {
- props = Utils.loadProperties(fooProps)
- fooProps.delete()
- fooDir.delete()
- }
-
- Then("version in foo properties should be the same") {
- assertEquals(props.getProperty(config.semverKey), version.semver)
- }
- }
- }
- }
-)
diff --git a/src/test/kotlin/net/thauvin/erik/gradle/semver/UtilsTest.kt b/src/test/kotlin/net/thauvin/erik/gradle/semver/UtilsTest.kt
new file mode 100644
index 0000000..05c1f6c
--- /dev/null
+++ b/src/test/kotlin/net/thauvin/erik/gradle/semver/UtilsTest.kt
@@ -0,0 +1,220 @@
+/*
+ * UtilsTest.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 net.thauvin.erik.gradle.semver.Utils.canReadFile
+import org.gradle.api.GradleException
+import java.io.File
+import kotlin.test.*
+
+/**
+ * [Utils] Tests
+ */
+class UtilsTest {
+ private val version = Version()
+ private val config = SemverConfig(version)
+ private val propsFile = File("test.properties")
+ private val projectDir = File("./")
+
+ @Test
+ fun testExceptions() {
+ assertFailsWith("2.1.1a") {
+ Utils.parseSemVer("2.1.1a", version)
+ }
+ assertFailsWith("2a.1.1") {
+ Utils.parseSemVer("2a.1.1", version)
+ }
+ assertFailsWith("2.1a.1") {
+ Utils.parseSemVer("2.1a.1", version)
+ }
+ assertFailsWith("2.1") {
+ Utils.parseSemVer("2.1", version)
+ }
+ }
+
+ @Test
+ fun testFooProperties() {
+ val fooDir = File("foo")
+ fooDir.mkdir()
+ val fooFile = File(fooDir, propsFile.name)
+ config.properties = fooFile.absolutePath
+ Utils.saveProperties(projectDir, config, version)
+
+ assertEquals(
+ fooFile.canReadFile(),
+ fooFile.canRead() && fooFile.isFile,
+ "foo properties file should exists and be readable"
+ )
+
+ val fooProps = Utils.loadProperties(fooFile)
+ fooFile.delete()
+ fooDir.delete()
+
+ assertEquals(
+ fooProps.getProperty(config.semverKey),
+ version.semver,
+ "version in foo properties should be the same"
+ )
+ }
+
+ @Test
+ fun testLoadSaveProperties() {
+ config.properties = propsFile.name
+ Utils.saveProperties(projectDir, config, version)
+ assertEquals(
+ propsFile.canReadFile(),
+ propsFile.canRead() && propsFile.isFile,
+ "properties file should exists and be readable"
+ )
+
+ val props = Utils.loadProperties(propsFile)
+
+ assertEquals(props.getProperty(config.majorKey), version.major.toString(), "Major")
+ assertEquals(props.getProperty(config.minorKey), version.minor.toString(), "Minor")
+ assertEquals(props.getProperty(config.patchKey), version.patch.toString(), "Patch")
+ assertEquals(props.getProperty(config.preReleaseKey), version.preRelease, "PreRelease")
+ assertNull(props.getProperty(config.preReleasePrefixKey), "PreRelease Prefix")
+ assertEquals(props.getProperty(config.buildMetaKey), version.buildMeta, "Build Meta")
+ assertNull(props.getProperty(config.buildMetaPrefixKey), "Build Meta Prefix")
+ assertNull(props.getProperty(config.separatorKey), "Separator")
+ assertEquals(props.getProperty(config.semverKey), version.semver, "semver")
+
+ propsFile.delete()
+ }
+
+ @Test
+ fun testLockedProperties() {
+ var locked = File("locked")
+
+ assertFailsWith {
+ Utils.loadProperties(File(locked, propsFile.name))
+ }
+ locked.delete()
+
+ locked = File(System.getProperty("user.home") + File.separator + "locked.properties")
+ locked.createNewFile()
+ locked.setReadOnly()
+ config.properties = locked.name
+
+ if (!locked.canWrite()) {
+ assertFailsWith {
+ Utils.saveProperties(locked.parentFile, config, version)
+ }
+ }
+ locked.delete()
+ }
+
+ @Test
+ fun testPrefix() {
+ version.preReleasePrefix = "."
+ version.buildMetaPrefix = "."
+
+ listOf("2.1.0.beta.1", "2.1.1.1", "3.2.1.beta.1.007").forEach {
+ assertTrue(Utils.parseSemVer(it, version), "parsing semver: $it")
+ assertEquals(it, version.semver, it)
+ }
+
+ assertEquals(version.preRelease, "beta", "last pre-release should match")
+ assertEquals(version.buildMeta, "1.007", "last meta should match")
+ }
+
+ @Test
+ fun testSystemProperties() {
+ val sysProps = arrayOf(
+ Pair(config.majorKey, "2"),
+ Pair(config.minorKey, "1"),
+ Pair(config.patchKey, "1"),
+ Pair(config.preReleaseKey, "beta"),
+ Pair(config.buildMetaKey, "007")
+ )
+
+ assertTrue(
+ Utils.isNotSystemProperty(
+ setOf(
+ config.majorKey,
+ config.minorKey,
+ config.patchKey,
+ config.preReleaseKey,
+ config.buildMetaKey
+ )
+ ),
+ "none should already exists"
+ )
+
+ val props = Utils.loadProperties(propsFile)
+
+ sysProps.forEach {
+ val msg = "${it.first} should match system properties"
+ System.getProperties().setProperty(it.first, it.second)
+ if (it.first == config.majorKey || it.first == config.minorKey || it.first == config.patchKey) {
+ assertEquals(Utils.loadIntProperty(props, it.first, -1), it.second.toInt(), msg)
+ } else {
+ assertEquals(Utils.loadProperty(props, it.first, ""), it.second, msg)
+ }
+ }
+
+ Utils.loadVersion(config, version, props)
+ assertEquals(version.semver, "2.1.1-beta+007", "version should be identical")
+
+ Utils.saveProperties(projectDir, config, version)
+
+ val newPropsFile = File(config.properties)
+ val newProps = Utils.loadProperties(newPropsFile)
+
+ sysProps.forEach {
+ assertEquals(newProps.getProperty(it.first), it.second, "new properties should validate")
+ }
+
+ newPropsFile.delete()
+
+ System.getProperties().setProperty(config.semverKey, "3.2.2")
+ Utils.loadVersion(config, version, props)
+ assertEquals(version.semver, System.getProperty(config.semverKey), "versions should match")
+ }
+
+ @Test
+ fun testVersionParsing() {
+ listOf(
+ "1.0.0",
+ "2.1.0-beta",
+ "3.2.1-beta+007",
+ "4.3.2+007",
+ "11.11.1",
+ "111.11.11-beta",
+ "1111.111.11-beta+001.12"
+ ).forEach {
+ assertTrue(Utils.parseSemVer(it, version), "parsing semver: $it")
+ assertEquals(it, version.semver, it)
+ }
+ }
+}
diff --git a/src/test/kotlin/net/thauvin/erik/gradle/semver/VersionTest.kt b/src/test/kotlin/net/thauvin/erik/gradle/semver/VersionTest.kt
new file mode 100644
index 0000000..9e122d7
--- /dev/null
+++ b/src/test/kotlin/net/thauvin/erik/gradle/semver/VersionTest.kt
@@ -0,0 +1,106 @@
+/*
+ * SemverVersionTest.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 VersionTest {
+ private val version = Version()
+
+ @Test
+ fun testDefaultVersion() {
+ assertEquals(1, version.major, "major should be 1")
+ assertEquals(0, version.minor, "minor should be 1")
+ assertEquals(0, version.patch, "patch should be 0")
+ assertEquals("", version.preRelease, "prerelease should be empty")
+ assertEquals("", version.buildMeta, "meta should be empty")
+ assertEquals("-", version.preReleasePrefix, "preRelease prefix should be -")
+ 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")
+ }
+
+ @Test
+ fun testIncrement() {
+ version.increment(isMajor = true)
+ assertEquals("2.0.0", version.semver, "should return 2.0.0")
+
+ version.increment(isMinor = true)
+ assertEquals("2.1.0", version.semver, "should return 2.1.0")
+
+ version.increment(isPatch = true)
+ assertEquals("2.1.1", version.semver, "should return 2.1.1")
+
+ version.increment(isMinor = true)
+ assertEquals("2.2.0", version.semver, "should return 2.2.0")
+
+ version.increment(isMajor = true)
+ assertEquals("3.0.0", version.semver, "should return 3.0.0")
+
+ version.increment(isMajor = true, isMinor = true, isPatch = true)
+ assertEquals("4.1.1", version.semver, "should return 4.1.1")
+
+ version.increment(isMajor = true, isMinor = true)
+ assertEquals("5.1.0", version.semver, "should return 5.1.0")
+
+ version.increment(isMinor = true, isPatch = true)
+ assertEquals("5.2.1", version.semver, "should return 5.2.1")
+
+ version.increment()
+ assertEquals("5.2.1", version.semver, "should still return 5.2.1")
+ }
+
+ @Test
+ fun testVersion() {
+ version.major = 1
+ version.minor = 0
+ version.patch = 0
+ assertEquals("1.0.0", version.semver, "should return 1.0.0")
+
+ version.preRelease = "beta"
+ assertEquals("1.0.0-beta", version.semver, "should return 1.0.0-beta")
+
+ version.buildMeta = "007"
+ assertEquals("1.0.0-beta+007", version.semver, "should return 1.0.0-beta+007")
+
+ version.preReleasePrefix = "--"
+ assertEquals("1.0.0--beta+007", version.semver, "should return 1.0.0--beta+007")
+
+ version.buildMetaPrefix = "++"
+ assertEquals("1.0.0--beta++007", version.semver, "should return 1.0.0--beta++007")
+
+ version.separator = "-"
+ assertEquals("1-0-0--beta++007", version.semver, "should return 1-0-0--beta++007")
+ }
+}