Switched to gherkin syntax.
This commit is contained in:
parent
239a952d89
commit
7c45ed087f
3 changed files with 218 additions and 115 deletions
|
@ -32,51 +32,53 @@
|
||||||
package net.thauvin.erik.gradle.semver
|
package net.thauvin.erik.gradle.semver
|
||||||
|
|
||||||
import org.spekframework.spek2.Spek
|
import org.spekframework.spek2.Spek
|
||||||
import org.spekframework.spek2.style.specification.describe
|
import org.spekframework.spek2.style.gherkin.Feature
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
object SemverConfigSpec : Spek({
|
object SemverConfigSpec : Spek({
|
||||||
describe("a config") {
|
Feature("SemverConfig") {
|
||||||
val config by memoized { SemverConfig() }
|
Scenario("Testing configs") {
|
||||||
val vars = listOf(
|
val config by memoized { SemverConfig() }
|
||||||
config.majorKey,
|
val vars = listOf(
|
||||||
config.minorKey,
|
config.majorKey,
|
||||||
config.patchKey,
|
config.minorKey,
|
||||||
config.preReleaseKey,
|
config.patchKey,
|
||||||
config.preReleasePrefixKey,
|
config.preReleaseKey,
|
||||||
config.buildMetaKey,
|
config.preReleasePrefixKey,
|
||||||
config.buildMetaPrefixKey,
|
config.buildMetaKey,
|
||||||
config.separatorKey
|
config.buildMetaPrefixKey,
|
||||||
)
|
config.separatorKey
|
||||||
val defaults = listOf(
|
)
|
||||||
SemverConfig.DEFAULT_MAJOR_KEY,
|
val defaults = listOf(
|
||||||
SemverConfig.DEFAULT_MINOR_KEY,
|
SemverConfig.DEFAULT_MAJOR_KEY,
|
||||||
SemverConfig.DEFAULT_PATCH_KEY,
|
SemverConfig.DEFAULT_MINOR_KEY,
|
||||||
SemverConfig.DEFAULT_PRERELEASE_KEY,
|
SemverConfig.DEFAULT_PATCH_KEY,
|
||||||
SemverConfig.DEFAULT_PRERELEASE_PREFIX_KEY,
|
SemverConfig.DEFAULT_PRERELEASE_KEY,
|
||||||
SemverConfig.DEFAULT_BUILDMETA_KEY,
|
SemverConfig.DEFAULT_PRERELEASE_PREFIX_KEY,
|
||||||
SemverConfig.DEFAULT_BUILDMETA_PREFIX_KEY,
|
SemverConfig.DEFAULT_BUILDMETA_KEY,
|
||||||
SemverConfig.DEFAULT_SEPARATOR
|
SemverConfig.DEFAULT_BUILDMETA_PREFIX_KEY,
|
||||||
)
|
SemverConfig.DEFAULT_SEPARATOR
|
||||||
|
)
|
||||||
|
|
||||||
|
When("checking defaults") {}
|
||||||
|
|
||||||
describe("check defaults") {
|
|
||||||
defaults.forEachIndexed { i, d ->
|
defaults.forEachIndexed { i, d ->
|
||||||
it("should be the same: ${vars[i]}, ${config.keysPrefix}$d") {
|
Then(" ${vars[i]} should be the same: ${config.keysPrefix}$d") {
|
||||||
assertEquals(vars[i], "${config.keysPrefix}$d")
|
assertEquals(vars[i], "${config.keysPrefix}$d")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
describe("check version.properties") {
|
Then("config.properties should be version.properties") {
|
||||||
it("should be version.properties") {
|
|
||||||
assertEquals(config.properties, "version.properties")
|
assertEquals(config.properties, "version.properties")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
describe("set keys to test.xxx") {
|
lateinit var newKeys: List<String>
|
||||||
it("should all start with test.xxx") {
|
|
||||||
|
When("setting keyPrefix to test.") {
|
||||||
config.keysPrefix = "test."
|
config.keysPrefix = "test."
|
||||||
val keys = listOf(
|
newKeys = listOf(
|
||||||
config.majorKey,
|
config.majorKey,
|
||||||
config.minorKey,
|
config.minorKey,
|
||||||
config.patchKey,
|
config.patchKey,
|
||||||
|
@ -85,9 +87,11 @@ object SemverConfigSpec : Spek({
|
||||||
config.buildMetaKey,
|
config.buildMetaKey,
|
||||||
config.buildMetaPrefixKey,
|
config.buildMetaPrefixKey,
|
||||||
config.separatorKey)
|
config.separatorKey)
|
||||||
|
}
|
||||||
|
|
||||||
keys.forEach { k ->
|
Then("all config keys should start with test.xxxx") {
|
||||||
assertTrue(k.startsWith("test."), "Should be test.$k")
|
newKeys.forEach { k ->
|
||||||
|
assertTrue(k.startsWith("test."), k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,131 +32,169 @@
|
||||||
package net.thauvin.erik.gradle.semver
|
package net.thauvin.erik.gradle.semver
|
||||||
|
|
||||||
import org.spekframework.spek2.Spek
|
import org.spekframework.spek2.Spek
|
||||||
import org.spekframework.spek2.style.specification.describe
|
import org.spekframework.spek2.style.gherkin.Feature
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
object SemverVersionSpec : Spek({
|
object SemverVersionSpec : Spek({
|
||||||
describe("test version") {
|
Feature("SemverVersion") {
|
||||||
val version = Version()
|
val version = Version()
|
||||||
describe("validate default version") {
|
Scenario("Testing Versions") {
|
||||||
it("major should be 1") {
|
When("validating default version") {}
|
||||||
|
|
||||||
|
Then("major should be 1") {
|
||||||
assertEquals("1", version.major)
|
assertEquals("1", version.major)
|
||||||
}
|
}
|
||||||
it("minor should be 1") {
|
|
||||||
|
Then("minor should be 1") {
|
||||||
assertEquals("0", version.minor)
|
assertEquals("0", version.minor)
|
||||||
}
|
}
|
||||||
it("patch should be 0") {
|
|
||||||
|
Then("patch should be 0") {
|
||||||
assertEquals("0", version.patch)
|
assertEquals("0", version.patch)
|
||||||
}
|
}
|
||||||
it("prerelease should be empty") {
|
|
||||||
|
Then("prerelease should be empty") {
|
||||||
assertEquals("", version.preRelease)
|
assertEquals("", version.preRelease)
|
||||||
}
|
}
|
||||||
it("meta should be empty") {
|
|
||||||
|
Then("meta should be empty") {
|
||||||
assertEquals("", version.buildMeta)
|
assertEquals("", version.buildMeta)
|
||||||
}
|
}
|
||||||
it("preRelease prefix should be -") {
|
|
||||||
|
Then("preRelease prefix should be -") {
|
||||||
assertEquals("-", version.preReleasePrefix)
|
assertEquals("-", version.preReleasePrefix)
|
||||||
}
|
}
|
||||||
it("meta prefix should be +") {
|
|
||||||
|
Then("meta prefix should be +") {
|
||||||
assertEquals("+", version.buildMetaPrefix)
|
assertEquals("+", version.buildMetaPrefix)
|
||||||
}
|
}
|
||||||
it("separator should be .") {
|
|
||||||
|
Then("separator should be .") {
|
||||||
assertEquals(".", version.separator)
|
assertEquals(".", version.separator)
|
||||||
}
|
}
|
||||||
it("version should be 1.0.0") {
|
|
||||||
|
Then("version should be 1.0.0") {
|
||||||
assertEquals("1.0.0", version.semver)
|
assertEquals("1.0.0", version.semver)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
describe("increment") {
|
When("incrementing major") {
|
||||||
it("should return 2.0.0") {
|
|
||||||
version.increment(isMajor = true)
|
version.increment(isMajor = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
Then("should return 2.0.0") {
|
||||||
assertEquals("2.0.0", version.semver)
|
assertEquals("2.0.0", version.semver)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
describe("increment minor") {
|
When("incrementing minor") {
|
||||||
it("should return 2.1.0") {
|
|
||||||
version.increment(isMinor = true)
|
version.increment(isMinor = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
Then("should return 2.1.0") {
|
||||||
assertEquals("2.1.0", version.semver)
|
assertEquals("2.1.0", version.semver)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
describe("increment patch") {
|
When("incrementing patch") {
|
||||||
it("should return 2.1.1") {
|
|
||||||
version.increment(isPatch = true)
|
version.increment(isPatch = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
Then("should return 2.1.1") {
|
||||||
assertEquals("2.1.1", version.semver)
|
assertEquals("2.1.1", version.semver)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
describe("increment minor again") {
|
When("incrementing minor again") {
|
||||||
it("should return 2.2.0") {
|
|
||||||
version.increment(isMinor = true)
|
version.increment(isMinor = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
Then("should return 2.2.0") {
|
||||||
assertEquals("2.2.0", version.semver)
|
assertEquals("2.2.0", version.semver)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
describe("increment major again") {
|
When("incrementing major again") {
|
||||||
it("should return 3.0.0") {
|
|
||||||
version.increment(isMajor = true)
|
version.increment(isMajor = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
Then("should return 3.0.0") {
|
||||||
assertEquals("3.0.0", version.semver)
|
assertEquals("3.0.0", version.semver)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
describe("increment all") {
|
When("incrementing all") {
|
||||||
it("should return 4.1.1") {
|
|
||||||
version.increment(isMajor = true, isMinor = true, isPatch = true)
|
version.increment(isMajor = true, isMinor = true, isPatch = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
Then("should return 4.1.1") {
|
||||||
assertEquals("4.1.1", version.semver)
|
assertEquals("4.1.1", version.semver)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
describe("increment major and minor") {
|
When("incrementing major and minor") {
|
||||||
it("should return 5.1.0") {
|
|
||||||
version.increment(isMajor = true, isMinor = true)
|
version.increment(isMajor = true, isMinor = true)
|
||||||
|
}
|
||||||
|
|
||||||
|
Then("should return 5.1.0") {
|
||||||
assertEquals("5.1.0", version.semver)
|
assertEquals("5.1.0", version.semver)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
describe("increment minor and patch") {
|
When("incrementing minor and patch") {
|
||||||
it("should return 5.2.1") {
|
|
||||||
version.increment(isMinor = true, isPatch = true)
|
version.increment(isMinor = true, isPatch = true)
|
||||||
|
}
|
||||||
|
Then("should return 5.2.1") {
|
||||||
assertEquals("5.2.1", version.semver)
|
assertEquals("5.2.1", version.semver)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
describe("increment nothing") {
|
When("incrementing nothing") {
|
||||||
it("should still return 5.2.1") {
|
|
||||||
version.increment()
|
version.increment()
|
||||||
|
}
|
||||||
|
Then("should still return 5.2.1") {
|
||||||
assertEquals("5.2.1", version.semver)
|
assertEquals("5.2.1", version.semver)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
describe("reset version") {
|
When("resetting version") {
|
||||||
it("should return 1.0.0") {
|
|
||||||
version.major = "1"
|
version.major = "1"
|
||||||
version.minor = "0"
|
version.minor = "0"
|
||||||
version.patch = "0"
|
version.patch = "0"
|
||||||
|
}
|
||||||
|
|
||||||
|
Then("should return 1.0.0") {
|
||||||
assertEquals("1.0.0", version.semver)
|
assertEquals("1.0.0", version.semver)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
describe("add prerelease") {
|
When("adding prerelease") {
|
||||||
it("should return 1.0.0-beta") {
|
|
||||||
version.preRelease = "beta"
|
version.preRelease = "beta"
|
||||||
|
}
|
||||||
|
|
||||||
|
Then("should return 1.0.0-beta") {
|
||||||
assertEquals("1.0.0-beta", version.semver)
|
assertEquals("1.0.0-beta", version.semver)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
describe("add metadata") {
|
When("adding metadata") {
|
||||||
it("should return 1.0.0-beta+007") {
|
|
||||||
version.buildMeta = "007"
|
version.buildMeta = "007"
|
||||||
|
}
|
||||||
|
|
||||||
|
Then("should return 1.0.0-beta+007") {
|
||||||
assertEquals("1.0.0-beta+007", version.semver)
|
assertEquals("1.0.0-beta+007", version.semver)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
describe("change prerelease prefix") {
|
When("changing prerelease prefix") {
|
||||||
it("should return 1.0.0--beta+007") {
|
|
||||||
version.preReleasePrefix = "--"
|
version.preReleasePrefix = "--"
|
||||||
|
}
|
||||||
|
|
||||||
|
Then("should return 1.0.0--beta+007") {
|
||||||
assertEquals("1.0.0--beta+007", version.semver)
|
assertEquals("1.0.0--beta+007", version.semver)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
describe("change meta prefix") {
|
When("changing meta prefix") {
|
||||||
it("should return 1.0.0--beta++007") {
|
|
||||||
version.buildMetaPrefix = "++"
|
version.buildMetaPrefix = "++"
|
||||||
|
}
|
||||||
|
|
||||||
|
Then("should return 1.0.0--beta++007") {
|
||||||
assertEquals("1.0.0--beta++007", version.semver)
|
assertEquals("1.0.0--beta++007", version.semver)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
describe("change separator") {
|
When("changing separator") {
|
||||||
it("should return 1-0-0--beta++007") {
|
|
||||||
version.separator = "-"
|
version.separator = "-"
|
||||||
|
}
|
||||||
|
|
||||||
|
Then("should return 1-0-0--beta++007") {
|
||||||
assertEquals("1-0-0--beta++007", version.semver)
|
assertEquals("1-0-0--beta++007", version.semver)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ package net.thauvin.erik.gradle.semver
|
||||||
|
|
||||||
import net.thauvin.erik.gradle.semver.Utils.canReadFile
|
import net.thauvin.erik.gradle.semver.Utils.canReadFile
|
||||||
import org.spekframework.spek2.Spek
|
import org.spekframework.spek2.Spek
|
||||||
import org.spekframework.spek2.style.specification.describe
|
import org.spekframework.spek2.style.gherkin.Feature
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.Properties
|
import java.util.Properties
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
@ -42,25 +42,28 @@ import kotlin.test.assertTrue
|
||||||
|
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
object UtilsSpec : Spek({
|
object UtilsSpec : Spek({
|
||||||
describe("a config and version") {
|
Feature("Utils") {
|
||||||
val version = Version()
|
val version = Version()
|
||||||
val config = SemverConfig()
|
val config = SemverConfig()
|
||||||
val propsFile = File("test.properties")
|
val propsFile = File("test.properties")
|
||||||
lateinit var props: Properties
|
lateinit var props: Properties
|
||||||
|
|
||||||
describe("save properties") {
|
Scenario("Save/Load Properties") {
|
||||||
it("save properties") {
|
When("saving the property") {
|
||||||
config.properties = propsFile.name
|
config.properties = propsFile.name
|
||||||
Utils.saveProperties(config, version)
|
Utils.saveProperties(config, version)
|
||||||
assertTrue(propsFile.canReadFile())
|
|
||||||
}
|
}
|
||||||
it("load the properties") {
|
|
||||||
|
Then("properties file should exists and be readable") {
|
||||||
|
assertEquals(propsFile.canReadFile(), propsFile.canRead() && propsFile.isFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
When("loading the properties file") {
|
||||||
props = Utils.loadProperties(propsFile)
|
props = Utils.loadProperties(propsFile)
|
||||||
propsFile.delete()
|
propsFile.delete()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
describe("validate the properties") {
|
Then("version and properties should be the same.") {
|
||||||
it("version should be the same") {
|
|
||||||
assertEquals(props.getProperty(config.majorKey), version.major, "Major")
|
assertEquals(props.getProperty(config.majorKey), version.major, "Major")
|
||||||
assertEquals(props.getProperty(config.minorKey), version.minor, "Minor")
|
assertEquals(props.getProperty(config.minorKey), version.minor, "Minor")
|
||||||
assertEquals(props.getProperty(config.patchKey), version.patch, "Patch")
|
assertEquals(props.getProperty(config.patchKey), version.patch, "Patch")
|
||||||
|
@ -69,39 +72,97 @@ object UtilsSpec : Spek({
|
||||||
assertEquals(props.getProperty(config.buildMetaKey), version.buildMeta, "Build Meta")
|
assertEquals(props.getProperty(config.buildMetaKey), version.buildMeta, "Build Meta")
|
||||||
assertNull(props.getProperty(config.buildMetaPrefixKey), "Build Meta Prefix")
|
assertNull(props.getProperty(config.buildMetaPrefixKey), "Build Meta Prefix")
|
||||||
assertNull(props.getProperty(config.separatorKey), "Separator")
|
assertNull(props.getProperty(config.separatorKey), "Separator")
|
||||||
|
assertEquals(props.getProperty(config.semverKey), version.semver, "semver")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
describe("setting system properties") {
|
|
||||||
val newVersion = arrayOf(
|
Scenario("System Properties") {
|
||||||
Pair(config.majorKey, "2"),
|
lateinit var sysProps: Array<Pair<String, String>>
|
||||||
Pair(config.minorKey, "1"),
|
|
||||||
Pair(config.patchKey, "1"),
|
Given("new system properties") {
|
||||||
Pair(config.preReleaseKey, "beta"),
|
sysProps = arrayOf(
|
||||||
Pair(config.buildMetaKey, "007"))
|
Pair(config.majorKey, "2"),
|
||||||
it("should have none of our properties") {
|
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,
|
assertTrue(Utils.isNotSystemProperty(setOf(config.majorKey, config.minorKey, config.patchKey, config.preReleaseKey,
|
||||||
config.buildMetaKey)))
|
config.buildMetaKey)))
|
||||||
}
|
}
|
||||||
it("version should match system properties") {
|
|
||||||
newVersion.forEach {
|
Then("version should match system properties") {
|
||||||
|
sysProps.forEach {
|
||||||
System.getProperties().setProperty(it.first, it.second)
|
System.getProperties().setProperty(it.first, it.second)
|
||||||
assertEquals(Utils.loadProperty(props, it.first, ""), it.second)
|
assertEquals(Utils.loadProperty(props, it.first, ""), it.second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
it("load version") {
|
|
||||||
|
When("loading version") {
|
||||||
Utils.loadVersion(config, version, props)
|
Utils.loadVersion(config, version, props)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Then("version should be identical") {
|
||||||
assertEquals(version.semver, "2.1.1-beta+007")
|
assertEquals(version.semver, "2.1.1-beta+007")
|
||||||
}
|
}
|
||||||
it("save new properties") {
|
|
||||||
|
When("saving properties") {
|
||||||
Utils.saveProperties(config, version)
|
Utils.saveProperties(config, version)
|
||||||
}
|
}
|
||||||
it("check saved properties") {
|
|
||||||
val newProps = Utils.loadProperties(propsFile)
|
lateinit var newProps: Properties
|
||||||
newVersion.forEach {
|
|
||||||
|
And("loading properties file") {
|
||||||
|
newProps = Utils.loadProperties(propsFile)
|
||||||
|
}
|
||||||
|
|
||||||
|
Then("new properties should validate") {
|
||||||
|
sysProps.forEach {
|
||||||
assertEquals(newProps.getProperty(it.first), it.second, it.second)
|
assertEquals(newProps.getProperty(it.first), it.second, it.second)
|
||||||
}
|
}
|
||||||
propsFile.delete()
|
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("Testing Version Parsing") {
|
||||||
|
When("validating version parsing") {
|
||||||
|
listOf("1.0.0", "2.1.0-beta", "3.2.1-beta+007", "4.3.2+007").forEach {
|
||||||
|
assertTrue(Utils.parseSemVer(it, version), "parsing semver: $it")
|
||||||
|
assertEquals(it, version.semver, it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Given("new prefixes") {
|
||||||
|
version.preReleasePrefix = "."
|
||||||
|
version.buildMetaPrefix = "."
|
||||||
|
}
|
||||||
|
|
||||||
|
Then("validating prefixes parsing") {
|
||||||
|
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("verifying pre-release and meta") {
|
||||||
|
assertEquals(version.preRelease, "beta.1")
|
||||||
|
assertEquals(version.buildMeta, "007")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue