locked.properties now created in user.home (NTFS/FAT32 workaround)

This commit is contained in:
Erik C. Thauvin 2020-07-20 06:27:21 -07:00
parent e71f4f60ee
commit 34cedc21e6

View file

@ -36,229 +36,234 @@ import org.gradle.api.GradleException
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.gherkin.Feature
import java.io.File
import java.util.Properties
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
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<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
)
)
)
}
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<GradleException>("2.1.1a") {
Utils.parseSemVer("2.1.1a", version)
}
assertFailsWith<GradleException>("2a.1.1") {
Utils.parseSemVer("2a.1.1", version)
}
assertFailsWith<GradleException>("2.1a.1") {
Utils.parseSemVer("2.1a.1", version)
}
assertFailsWith<GradleException>("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<GradleException> {
Utils.loadProperties(File(locked, propsFile.name))
}
locked.delete()
}
}
Scenario("Save to locked properties") {
lateinit var propsLocked: File
Given("the locked properties") {
propsLocked = File("locked.properties")
propsLocked.createNewFile()
propsLocked.setReadOnly()
config.properties = propsLocked.name
}
Then("saving the locked properties file") {
assertFailsWith<GradleException> {
Scenario("Save/Load Properties") {
When("saving the property") {
config.properties = propsFile.name
Utils.saveProperties(projectDir, 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("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")
}
}
Then("foo properties file should exists and be readable") {
assertEquals(fooProps.canReadFile(), fooProps.canRead() && fooProps.isFile)
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
)
)
)
}
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))
}
}
When("loading the foo properties file") {
props = Utils.loadProperties(fooProps)
fooProps.delete()
fooDir.delete()
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<GradleException>("2.1.1a") {
Utils.parseSemVer("2.1.1a", version)
}
assertFailsWith<GradleException>("2a.1.1") {
Utils.parseSemVer("2a.1.1", version)
}
assertFailsWith<GradleException>("2.1a.1") {
Utils.parseSemVer("2.1a.1", version)
}
assertFailsWith<GradleException>("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")
}
}
Then("version in foo properties should be the same") {
assertEquals(props.getProperty(config.semverKey), version.semver)
Scenario("Load locked properties") {
lateinit var locked: File
Given("the locked location") {
locked = File("locked")
}
Then("loading locked properties") {
assertFailsWith<GradleException> {
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") {
assertFailsWith<GradleException> {
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)
}
}
}
}
})
)