Moved to spek2.
This commit is contained in:
parent
23b3a4f204
commit
f18ac5976f
3 changed files with 174 additions and 134 deletions
|
@ -31,50 +31,50 @@
|
|||
*/
|
||||
package net.thauvin.erik.gradle.semver
|
||||
|
||||
import org.jetbrains.spek.api.Spek
|
||||
import org.jetbrains.spek.api.dsl.describe
|
||||
import org.jetbrains.spek.api.dsl.given
|
||||
import org.jetbrains.spek.api.dsl.it
|
||||
import org.jetbrains.spek.api.dsl.on
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@Suppress("unused")
|
||||
object SemverConfigSpec : Spek({
|
||||
describe("config test") {
|
||||
given("a config") {
|
||||
val config = 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
|
||||
)
|
||||
on("defaults") {
|
||||
defaults.forEachIndexed { i, d ->
|
||||
it("should be the same: ${vars[i]}, ${config.keysPrefix}$d") {
|
||||
assertEquals(vars[i], "${config.keysPrefix}$d")
|
||||
}
|
||||
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
|
||||
)
|
||||
|
||||
describe("check defaults") {
|
||||
defaults.forEachIndexed { i, d ->
|
||||
it("should be the same: ${vars[i]}, ${config.keysPrefix}$d") {
|
||||
assertEquals(vars[i], "${config.keysPrefix}$d")
|
||||
}
|
||||
}
|
||||
on("should be version.properties") {
|
||||
}
|
||||
describe("check version.properties") {
|
||||
it("should be version.properties") {
|
||||
assertEquals(config.properties, "version.properties")
|
||||
}
|
||||
on("set keys to test.xxx") {
|
||||
}
|
||||
describe("set keys to test.xxx") {
|
||||
it("should all start with test.xxx") {
|
||||
config.keysPrefix = "test."
|
||||
val keys = listOf(
|
||||
config.majorKey,
|
||||
|
@ -87,9 +87,7 @@ object SemverConfigSpec : Spek({
|
|||
config.separatorKey)
|
||||
|
||||
keys.forEach { k ->
|
||||
it("should all start with test.xxx: $k") {
|
||||
assertTrue(k.startsWith("test."))
|
||||
}
|
||||
assertTrue(k.startsWith("test."), "Should be test.$k")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
package net.thauvin.erik.gradle.semver
|
||||
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import java.util.Properties
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNull
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
@Suppress("unused")
|
||||
object SemverPluginSpec : Spek({
|
||||
describe("a config and version") {
|
||||
val version by memoized { Version() }
|
||||
val config by memoized { SemverConfig() }
|
||||
val configFile = File("test.properties")
|
||||
|
||||
config.properties = configFile.name
|
||||
|
||||
describe("test save properties") {
|
||||
it("should save properties") {
|
||||
SemverPlugin.saveProperties(config, version)
|
||||
assertTrue(configFile.exists())
|
||||
}
|
||||
}
|
||||
describe("validate the properties file") {
|
||||
it("verion should be the same") {
|
||||
val props = Properties().apply {
|
||||
Files.newInputStream(configFile.toPath()).use { nis ->
|
||||
load(nis)
|
||||
configFile.delete()
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(props.getProperty(config.majorKey), version.major, "Major")
|
||||
assertEquals(props.getProperty(config.minorKey), version.minor, "Minor")
|
||||
assertEquals(props.getProperty(config.patchKey), version.patch, "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")
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
|
@ -31,138 +31,133 @@
|
|||
*/
|
||||
package net.thauvin.erik.gradle.semver
|
||||
|
||||
import org.jetbrains.spek.api.Spek
|
||||
import org.jetbrains.spek.api.dsl.describe
|
||||
import org.jetbrains.spek.api.dsl.given
|
||||
import org.jetbrains.spek.api.dsl.it
|
||||
import org.jetbrains.spek.api.dsl.on
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@Suppress("unused")
|
||||
object SemverVersionSpec : Spek({
|
||||
describe("version test") {
|
||||
given("a version") {
|
||||
val version = Version()
|
||||
on("valdiate default version") {
|
||||
it("major should be 1") {
|
||||
assertEquals("1", version.major)
|
||||
}
|
||||
it("minor should be 1") {
|
||||
assertEquals("0", version.minor)
|
||||
}
|
||||
it("patch should be 0") {
|
||||
assertEquals("0", version.patch)
|
||||
}
|
||||
it("prerelease should be empty") {
|
||||
assertEquals("", version.preRelease)
|
||||
}
|
||||
it("meta should be empty") {
|
||||
assertEquals("", version.buildMeta)
|
||||
}
|
||||
it("preRelease prefix should be -") {
|
||||
assertEquals("-", version.preReleasePrefix)
|
||||
}
|
||||
it("meta prefix should be +") {
|
||||
assertEquals("+", version.buildMetaPrefix)
|
||||
}
|
||||
it("separator should be .") {
|
||||
assertEquals(".", version.separator)
|
||||
}
|
||||
it("version should be 1.0.0") {
|
||||
assertEquals("1.0.0", version.semver)
|
||||
}
|
||||
describe("a version") {
|
||||
val version = Version()
|
||||
describe("valdiate default version") {
|
||||
it("major should be 1") {
|
||||
assertEquals("1", version.major)
|
||||
}
|
||||
on("increment major") {
|
||||
it("minor should be 1") {
|
||||
assertEquals("0", version.minor)
|
||||
}
|
||||
it("patch should be 0") {
|
||||
assertEquals("0", version.patch)
|
||||
}
|
||||
it("prerelease should be empty") {
|
||||
assertEquals("", version.preRelease)
|
||||
}
|
||||
it("meta should be empty") {
|
||||
assertEquals("", version.buildMeta)
|
||||
}
|
||||
it("preRelease prefix should be -") {
|
||||
assertEquals("-", version.preReleasePrefix)
|
||||
}
|
||||
it("meta prefix should be +") {
|
||||
assertEquals("+", version.buildMetaPrefix)
|
||||
}
|
||||
it("separator should be .") {
|
||||
assertEquals(".", version.separator)
|
||||
}
|
||||
it("version should be 1.0.0") {
|
||||
assertEquals("1.0.0", version.semver)
|
||||
}
|
||||
}
|
||||
describe("increment major") {
|
||||
it("should return 2.0.0") {
|
||||
version.increment(isMajor = true)
|
||||
it("should return 2.0.0") {
|
||||
assertEquals("2.0.0", version.semver)
|
||||
}
|
||||
assertEquals("2.0.0", version.semver)
|
||||
}
|
||||
on("increment minor") {
|
||||
}
|
||||
describe("increment minor") {
|
||||
it("should return 2.1.0") {
|
||||
version.increment(isMinor = true)
|
||||
it("should return 2.1.0") {
|
||||
assertEquals("2.1.0", version.semver)
|
||||
}
|
||||
assertEquals("2.1.0", version.semver)
|
||||
}
|
||||
on("increment patch") {
|
||||
}
|
||||
describe("increment patch") {
|
||||
it("should return 2.1.1") {
|
||||
version.increment(isPatch = true)
|
||||
it("should return 2.1.1") {
|
||||
assertEquals("2.1.1", version.semver)
|
||||
}
|
||||
assertEquals("2.1.1", version.semver)
|
||||
}
|
||||
on("increment minor again") {
|
||||
}
|
||||
describe("increment minor again") {
|
||||
it("should return 2.2.0") {
|
||||
version.increment(isMinor = true)
|
||||
it("should return 2.2.0") {
|
||||
assertEquals("2.2.0", version.semver)
|
||||
}
|
||||
assertEquals("2.2.0", version.semver)
|
||||
}
|
||||
on("increment major again") {
|
||||
}
|
||||
describe("increment major again") {
|
||||
it("should return 3.0.0") {
|
||||
version.increment(isMajor = true)
|
||||
it("should return 3.0.0") {
|
||||
assertEquals("3.0.0", version.semver)
|
||||
}
|
||||
assertEquals("3.0.0", version.semver)
|
||||
}
|
||||
on("increment all") {
|
||||
}
|
||||
describe("increment all") {
|
||||
it("should return 4.1.1") {
|
||||
version.increment(isMajor = true, isMinor = true, isPatch = true)
|
||||
it("should return 4.1.1") {
|
||||
assertEquals("4.1.1", version.semver)
|
||||
}
|
||||
assertEquals("4.1.1", version.semver)
|
||||
}
|
||||
on("increment major and minor") {
|
||||
}
|
||||
describe("increment major and minor") {
|
||||
it("should return 5.1.0") {
|
||||
version.increment(isMajor = true, isMinor = true)
|
||||
it("should return 5.1.0") {
|
||||
assertEquals("5.1.0", version.semver)
|
||||
}
|
||||
assertEquals("5.1.0", version.semver)
|
||||
}
|
||||
on("increment minor and patch") {
|
||||
}
|
||||
describe("increment minor and patch") {
|
||||
it("should return 5.2.1") {
|
||||
version.increment(isMinor = true, isPatch = true)
|
||||
it("should return 5.2.1") {
|
||||
assertEquals("5.2.1", version.semver)
|
||||
}
|
||||
assertEquals("5.2.1", version.semver)
|
||||
}
|
||||
on("increment nothing") {
|
||||
}
|
||||
describe("increment nothing") {
|
||||
it("should still return 5.2.1") {
|
||||
version.increment()
|
||||
it("should still return 5.2.1") {
|
||||
assertEquals("5.2.1", version.semver)
|
||||
}
|
||||
assertEquals("5.2.1", version.semver)
|
||||
}
|
||||
on("reset version") {
|
||||
}
|
||||
describe("reset version") {
|
||||
it("should return 1.0.0") {
|
||||
version.major = "1"
|
||||
version.minor = "0"
|
||||
version.patch = "0"
|
||||
it("should return 1.0.0") {
|
||||
assertEquals("1.0.0", version.semver)
|
||||
}
|
||||
assertEquals("1.0.0", version.semver)
|
||||
}
|
||||
on("add prerelease") {
|
||||
}
|
||||
describe("add prerelease") {
|
||||
it("should return 1.0.0-beta") {
|
||||
version.preRelease = "beta"
|
||||
it("should return 1.0.0-beta") {
|
||||
assertEquals("1.0.0-beta", version.semver)
|
||||
}
|
||||
assertEquals("1.0.0-beta", version.semver)
|
||||
}
|
||||
on("add metadata") {
|
||||
}
|
||||
describe("add metadata") {
|
||||
it("should return 1.0.0-beta+007") {
|
||||
version.buildMeta = "007"
|
||||
it("should return 1.0.0-beta+007") {
|
||||
assertEquals("1.0.0-beta+007", version.semver)
|
||||
}
|
||||
assertEquals("1.0.0-beta+007", version.semver)
|
||||
}
|
||||
on("change prerelease prefix") {
|
||||
}
|
||||
describe("change prerelease prefix") {
|
||||
it("should return 1.0.0--beta+007") {
|
||||
version.preReleasePrefix = "--"
|
||||
it("should return 1.0.0--beta+007") {
|
||||
assertEquals("1.0.0--beta+007", version.semver)
|
||||
}
|
||||
assertEquals("1.0.0--beta+007", version.semver)
|
||||
}
|
||||
on("change meta prefix") {
|
||||
}
|
||||
describe("change meta prefix") {
|
||||
it("should return 1.0.0--beta++007") {
|
||||
version.buildMetaPrefix = "++"
|
||||
it("should return 1.0.0--beta++007") {
|
||||
assertEquals("1.0.0--beta++007", version.semver)
|
||||
}
|
||||
assertEquals("1.0.0--beta++007", version.semver)
|
||||
}
|
||||
on("change separator") {
|
||||
}
|
||||
describe("change separator") {
|
||||
it("should return 1-0-0--beta++007") {
|
||||
version.separator = "-"
|
||||
it("should return 1-0-0--beta++007") {
|
||||
assertEquals("1-0-0--beta++007", version.semver)
|
||||
}
|
||||
assertEquals("1-0-0--beta++007", version.semver)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue