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
|
||||
|
||||
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.assertTrue
|
||||
|
||||
@Suppress("unused")
|
||||
object SemverConfigSpec : Spek({
|
||||
describe("a config") {
|
||||
val config by memoized { SemverConfig() }
|
||||
val vars = listOf(
|
||||
config.majorKey,
|
||||
config.minorKey,
|
||||
config.patchKey,
|
||||
config.preReleaseKey,
|
||||
config.preReleasePrefixKey,
|
||||
config.buildMetaKey,
|
||||
config.buildMetaPrefixKey,
|
||||
config.separatorKey
|
||||
)
|
||||
val defaults = listOf(
|
||||
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
|
||||
)
|
||||
Feature("SemverConfig") {
|
||||
Scenario("Testing configs") {
|
||||
val config by memoized { SemverConfig() }
|
||||
val vars = listOf(
|
||||
config.majorKey,
|
||||
config.minorKey,
|
||||
config.patchKey,
|
||||
config.preReleaseKey,
|
||||
config.preReleasePrefixKey,
|
||||
config.buildMetaKey,
|
||||
config.buildMetaPrefixKey,
|
||||
config.separatorKey
|
||||
)
|
||||
val defaults = listOf(
|
||||
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") {}
|
||||
|
||||
describe("check defaults") {
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
describe("check version.properties") {
|
||||
it("should be version.properties") {
|
||||
|
||||
Then("config.properties should be version.properties") {
|
||||
assertEquals(config.properties, "version.properties")
|
||||
}
|
||||
}
|
||||
describe("set keys to test.xxx") {
|
||||
it("should all start with test.xxx") {
|
||||
|
||||
lateinit var newKeys: List<String>
|
||||
|
||||
When("setting keyPrefix to test.") {
|
||||
config.keysPrefix = "test."
|
||||
val keys = listOf(
|
||||
newKeys = listOf(
|
||||
config.majorKey,
|
||||
config.minorKey,
|
||||
config.patchKey,
|
||||
|
@ -85,9 +87,11 @@ object SemverConfigSpec : Spek({
|
|||
config.buildMetaKey,
|
||||
config.buildMetaPrefixKey,
|
||||
config.separatorKey)
|
||||
}
|
||||
|
||||
keys.forEach { k ->
|
||||
assertTrue(k.startsWith("test."), "Should be test.$k")
|
||||
Then("all config keys should start with test.xxxx") {
|
||||
newKeys.forEach { k ->
|
||||
assertTrue(k.startsWith("test."), k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,131 +32,169 @@
|
|||
package net.thauvin.erik.gradle.semver
|
||||
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
import org.spekframework.spek2.style.gherkin.Feature
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@Suppress("unused")
|
||||
object SemverVersionSpec : Spek({
|
||||
describe("test version") {
|
||||
Feature("SemverVersion") {
|
||||
val version = Version()
|
||||
describe("validate default version") {
|
||||
it("major should be 1") {
|
||||
Scenario("Testing Versions") {
|
||||
When("validating default version") {}
|
||||
|
||||
Then("major should be 1") {
|
||||
assertEquals("1", version.major)
|
||||
}
|
||||
it("minor should be 1") {
|
||||
|
||||
Then("minor should be 1") {
|
||||
assertEquals("0", version.minor)
|
||||
}
|
||||
it("patch should be 0") {
|
||||
|
||||
Then("patch should be 0") {
|
||||
assertEquals("0", version.patch)
|
||||
}
|
||||
it("prerelease should be empty") {
|
||||
|
||||
Then("prerelease should be empty") {
|
||||
assertEquals("", version.preRelease)
|
||||
}
|
||||
it("meta should be empty") {
|
||||
|
||||
Then("meta should be empty") {
|
||||
assertEquals("", version.buildMeta)
|
||||
}
|
||||
it("preRelease prefix should be -") {
|
||||
|
||||
Then("preRelease prefix should be -") {
|
||||
assertEquals("-", version.preReleasePrefix)
|
||||
}
|
||||
it("meta prefix should be +") {
|
||||
|
||||
Then("meta prefix should be +") {
|
||||
assertEquals("+", version.buildMetaPrefix)
|
||||
}
|
||||
it("separator should be .") {
|
||||
|
||||
Then("separator should be .") {
|
||||
assertEquals(".", version.separator)
|
||||
}
|
||||
it("version should be 1.0.0") {
|
||||
|
||||
Then("version should be 1.0.0") {
|
||||
assertEquals("1.0.0", version.semver)
|
||||
}
|
||||
}
|
||||
describe("increment") {
|
||||
it("should return 2.0.0") {
|
||||
|
||||
When("incrementing major") {
|
||||
version.increment(isMajor = true)
|
||||
}
|
||||
|
||||
Then("should return 2.0.0") {
|
||||
assertEquals("2.0.0", version.semver)
|
||||
}
|
||||
}
|
||||
describe("increment minor") {
|
||||
it("should return 2.1.0") {
|
||||
|
||||
When("incrementing minor") {
|
||||
version.increment(isMinor = true)
|
||||
}
|
||||
|
||||
Then("should return 2.1.0") {
|
||||
assertEquals("2.1.0", version.semver)
|
||||
}
|
||||
}
|
||||
describe("increment patch") {
|
||||
it("should return 2.1.1") {
|
||||
|
||||
When("incrementing patch") {
|
||||
version.increment(isPatch = true)
|
||||
}
|
||||
|
||||
Then("should return 2.1.1") {
|
||||
assertEquals("2.1.1", version.semver)
|
||||
}
|
||||
}
|
||||
describe("increment minor again") {
|
||||
it("should return 2.2.0") {
|
||||
|
||||
When("incrementing minor again") {
|
||||
version.increment(isMinor = true)
|
||||
}
|
||||
|
||||
Then("should return 2.2.0") {
|
||||
assertEquals("2.2.0", version.semver)
|
||||
}
|
||||
}
|
||||
describe("increment major again") {
|
||||
it("should return 3.0.0") {
|
||||
|
||||
When("incrementing major again") {
|
||||
version.increment(isMajor = true)
|
||||
}
|
||||
|
||||
Then("should return 3.0.0") {
|
||||
assertEquals("3.0.0", version.semver)
|
||||
}
|
||||
}
|
||||
describe("increment all") {
|
||||
it("should return 4.1.1") {
|
||||
|
||||
When("incrementing all") {
|
||||
version.increment(isMajor = true, isMinor = true, isPatch = true)
|
||||
}
|
||||
|
||||
Then("should return 4.1.1") {
|
||||
assertEquals("4.1.1", version.semver)
|
||||
}
|
||||
}
|
||||
describe("increment major and minor") {
|
||||
it("should return 5.1.0") {
|
||||
|
||||
When("incrementing major and minor") {
|
||||
version.increment(isMajor = true, isMinor = true)
|
||||
}
|
||||
|
||||
Then("should return 5.1.0") {
|
||||
assertEquals("5.1.0", version.semver)
|
||||
}
|
||||
}
|
||||
describe("increment minor and patch") {
|
||||
it("should return 5.2.1") {
|
||||
|
||||
When("incrementing minor and patch") {
|
||||
version.increment(isMinor = true, isPatch = true)
|
||||
}
|
||||
Then("should return 5.2.1") {
|
||||
assertEquals("5.2.1", version.semver)
|
||||
}
|
||||
}
|
||||
describe("increment nothing") {
|
||||
it("should still return 5.2.1") {
|
||||
|
||||
When("incrementing nothing") {
|
||||
version.increment()
|
||||
}
|
||||
Then("should still return 5.2.1") {
|
||||
assertEquals("5.2.1", version.semver)
|
||||
}
|
||||
}
|
||||
describe("reset version") {
|
||||
it("should return 1.0.0") {
|
||||
|
||||
When("resetting version") {
|
||||
version.major = "1"
|
||||
version.minor = "0"
|
||||
version.patch = "0"
|
||||
}
|
||||
|
||||
Then("should return 1.0.0") {
|
||||
assertEquals("1.0.0", version.semver)
|
||||
}
|
||||
}
|
||||
describe("add prerelease") {
|
||||
it("should return 1.0.0-beta") {
|
||||
|
||||
When("adding prerelease") {
|
||||
version.preRelease = "beta"
|
||||
}
|
||||
|
||||
Then("should return 1.0.0-beta") {
|
||||
assertEquals("1.0.0-beta", version.semver)
|
||||
}
|
||||
}
|
||||
describe("add metadata") {
|
||||
it("should return 1.0.0-beta+007") {
|
||||
|
||||
When("adding metadata") {
|
||||
version.buildMeta = "007"
|
||||
}
|
||||
|
||||
Then("should return 1.0.0-beta+007") {
|
||||
assertEquals("1.0.0-beta+007", version.semver)
|
||||
}
|
||||
}
|
||||
describe("change prerelease prefix") {
|
||||
it("should return 1.0.0--beta+007") {
|
||||
|
||||
When("changing prerelease prefix") {
|
||||
version.preReleasePrefix = "--"
|
||||
}
|
||||
|
||||
Then("should return 1.0.0--beta+007") {
|
||||
assertEquals("1.0.0--beta+007", version.semver)
|
||||
}
|
||||
}
|
||||
describe("change meta prefix") {
|
||||
it("should return 1.0.0--beta++007") {
|
||||
|
||||
When("changing meta prefix") {
|
||||
version.buildMetaPrefix = "++"
|
||||
}
|
||||
|
||||
Then("should return 1.0.0--beta++007") {
|
||||
assertEquals("1.0.0--beta++007", version.semver)
|
||||
}
|
||||
}
|
||||
describe("change separator") {
|
||||
it("should return 1-0-0--beta++007") {
|
||||
|
||||
When("changing separator") {
|
||||
version.separator = "-"
|
||||
}
|
||||
|
||||
Then("should return 1-0-0--beta++007") {
|
||||
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 org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
import org.spekframework.spek2.style.gherkin.Feature
|
||||
import java.io.File
|
||||
import java.util.Properties
|
||||
import kotlin.test.assertEquals
|
||||
|
@ -42,25 +42,28 @@ import kotlin.test.assertTrue
|
|||
|
||||
@Suppress("unused")
|
||||
object UtilsSpec : Spek({
|
||||
describe("a config and version") {
|
||||
Feature("Utils") {
|
||||
val version = Version()
|
||||
val config = SemverConfig()
|
||||
val propsFile = File("test.properties")
|
||||
lateinit var props: Properties
|
||||
|
||||
describe("save properties") {
|
||||
it("save properties") {
|
||||
Scenario("Save/Load Properties") {
|
||||
When("saving the property") {
|
||||
config.properties = propsFile.name
|
||||
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)
|
||||
propsFile.delete()
|
||||
}
|
||||
}
|
||||
describe("validate the properties") {
|
||||
it("version should be the same") {
|
||||
|
||||
Then("version and properties should be the same.") {
|
||||
assertEquals(props.getProperty(config.majorKey), version.major, "Major")
|
||||
assertEquals(props.getProperty(config.minorKey), version.minor, "Minor")
|
||||
assertEquals(props.getProperty(config.patchKey), version.patch, "Patch")
|
||||
|
@ -69,39 +72,97 @@ object UtilsSpec : Spek({
|
|||
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")
|
||||
}
|
||||
}
|
||||
describe("setting system properties") {
|
||||
val newVersion = arrayOf(
|
||||
Pair(config.majorKey, "2"),
|
||||
Pair(config.minorKey, "1"),
|
||||
Pair(config.patchKey, "1"),
|
||||
Pair(config.preReleaseKey, "beta"),
|
||||
Pair(config.buildMetaKey, "007"))
|
||||
it("should have none of our properties") {
|
||||
|
||||
Scenario("System Properties") {
|
||||
lateinit var sysProps: Array<Pair<String, String>>
|
||||
|
||||
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)))
|
||||
}
|
||||
it("version should match system properties") {
|
||||
newVersion.forEach {
|
||||
|
||||
Then("version should match system properties") {
|
||||
sysProps.forEach {
|
||||
System.getProperties().setProperty(it.first, it.second)
|
||||
assertEquals(Utils.loadProperty(props, it.first, ""), it.second)
|
||||
}
|
||||
}
|
||||
it("load version") {
|
||||
|
||||
When("loading version") {
|
||||
Utils.loadVersion(config, version, props)
|
||||
|
||||
}
|
||||
|
||||
Then("version should be identical") {
|
||||
assertEquals(version.semver, "2.1.1-beta+007")
|
||||
}
|
||||
it("save new properties") {
|
||||
|
||||
When("saving properties") {
|
||||
Utils.saveProperties(config, version)
|
||||
}
|
||||
it("check saved properties") {
|
||||
val newProps = Utils.loadProperties(propsFile)
|
||||
newVersion.forEach {
|
||||
|
||||
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("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