diff --git a/command-line-tools/digger-cli/src/commonTest/kotlin/com/zegreatrob/tools/digger/cli/AllContributionDataTest.kt b/command-line-tools/digger-cli/src/commonTest/kotlin/com/zegreatrob/tools/digger/cli/AllContributionDataTest.kt index 19267ef4..e93c03bf 100644 --- a/command-line-tools/digger-cli/src/commonTest/kotlin/com/zegreatrob/tools/digger/cli/AllContributionDataTest.kt +++ b/command-line-tools/digger-cli/src/commonTest/kotlin/com/zegreatrob/tools/digger/cli/AllContributionDataTest.kt @@ -1,28 +1,21 @@ package com.zegreatrob.tools.digger.cli import com.github.ajalt.clikt.testing.test -import com.zegreatrob.tools.cli.createTempDirectory import com.zegreatrob.tools.cli.readFromFile -import com.zegreatrob.tools.cli.removeDirectory import com.zegreatrob.tools.digger.AllContributionTestSpec +import kotlin.test.BeforeTest class AllContributionDataTest : AllContributionTestSpec { override lateinit var projectDir: String override val addFileNames: Set = emptySet() - private lateinit var outputFile: String private lateinit var arguments: List + private val outputFile: String get() = "$projectDir/temp-file.json" - @kotlin.test.BeforeTest + @BeforeTest fun setup() { - projectDir = createTempDirectory() arguments = emptyList() - outputFile = "$projectDir/temp-file.json" - } - - fun tearDown() { - removeDirectory(projectDir) } override fun setupWithDefaults() { diff --git a/command-line-tools/digger-cli/src/commonTest/kotlin/com/zegreatrob/tools/digger/cli/CurrentContributionDataTest.kt b/command-line-tools/digger-cli/src/commonTest/kotlin/com/zegreatrob/tools/digger/cli/CurrentContributionDataTest.kt index 0974286c..90b3b57d 100644 --- a/command-line-tools/digger-cli/src/commonTest/kotlin/com/zegreatrob/tools/digger/cli/CurrentContributionDataTest.kt +++ b/command-line-tools/digger-cli/src/commonTest/kotlin/com/zegreatrob/tools/digger/cli/CurrentContributionDataTest.kt @@ -1,9 +1,7 @@ package com.zegreatrob.tools.digger.cli import com.github.ajalt.clikt.testing.test -import com.zegreatrob.tools.cli.createTempDirectory import com.zegreatrob.tools.cli.readFromFile -import com.zegreatrob.tools.cli.removeDirectory import com.zegreatrob.tools.digger.CurrentContributionTestSpec import kotlin.test.BeforeTest import kotlin.test.assertEquals @@ -11,23 +9,15 @@ import kotlin.test.assertEquals class CurrentContributionDataTest : CurrentContributionTestSpec { override lateinit var projectDir: String - - private lateinit var outputFile: String - + private val outputFile: String get() = "$projectDir/temp-file.json" override val addFileNames: Set = emptySet() - private lateinit var arguments: List @BeforeTest fun setup() { - projectDir = createTempDirectory() arguments = emptyList() - outputFile = "$projectDir/temp-file.json" } - fun tearDown() { - removeDirectory(projectDir) - } override fun setupWithDefaults() { arguments += "--output-file=$outputFile" arguments += projectDir diff --git a/tools/digger-plugin/build.gradle.kts b/tools/digger-plugin/build.gradle.kts index 52929fa8..884ab585 100644 --- a/tools/digger-plugin/build.gradle.kts +++ b/tools/digger-plugin/build.gradle.kts @@ -53,8 +53,10 @@ tasks { dependsOn(testing.suites.named("functionalTest")) } publish { finalizedBy("::closeAndReleaseSonatypeStagingRepository") } - named("test") { + withType(Test::class) { useJUnitPlatform() + environment("GIT_CONFIG_GLOBAL", "/dev/null") + environment("GIT_CONFIG_SYSTEM", "/dev/null") } formatKotlinMain { exclude { spec -> spec.file.absolutePath.contains("generated-sources") } diff --git a/tools/digger-plugin/src/functionalTest/kotlin/com/zegreatrob/tools/digger/AllContributionFunctionalTest.kt b/tools/digger-plugin/src/functionalTest/kotlin/com/zegreatrob/tools/digger/AllContributionFunctionalTest.kt index 2c188ef6..255a3902 100644 --- a/tools/digger-plugin/src/functionalTest/kotlin/com/zegreatrob/tools/digger/AllContributionFunctionalTest.kt +++ b/tools/digger-plugin/src/functionalTest/kotlin/com/zegreatrob/tools/digger/AllContributionFunctionalTest.kt @@ -1,24 +1,28 @@ package com.zegreatrob.tools.digger import org.gradle.testkit.runner.GradleRunner -import org.junit.jupiter.api.io.TempDir import java.io.File class AllContributionFunctionalTest : AllContributionTestSpec { - @field:TempDir - override lateinit var projectDir: File + override lateinit var projectDir: String - private val buildFile by lazy { projectDir.resolve("build.gradle.kts") } - private val allOutput by lazy { projectDir.resolve("build/digger/all.json") } - private val settingsFile by lazy { projectDir.resolve("settings.gradle") } - private val ignoreFile by lazy { projectDir.resolve(".gitignore") } + private val buildFile by lazy { "$projectDir/build.gradle.kts" } + private val allOutput by lazy { "$projectDir/build/digger/all.json" } + private val settingsFile by lazy { "$projectDir/settings.gradle" } + private val ignoreFile by lazy { "$projectDir/.gitignore" } - override val addFileNames by lazy { setOf(settingsFile.name, buildFile.name, ignoreFile.name) } + override val addFileNames by lazy { + setOf( + settingsFile.split("/").last(), + buildFile.split("/").last(), + ignoreFile.split("/").last(), + ) + } override fun setupWithDefaults() { - settingsFile.writeText("") - ignoreFile.writeText(".gradle") - buildFile.writeText( + File(settingsFile).writeText("") + File(ignoreFile).writeText(".gradle") + File(buildFile).writeText( """ plugins { id("com.zegreatrob.tools.digger") @@ -37,9 +41,9 @@ class AllContributionFunctionalTest : AllContributionTestSpec { easeRegex: String?, tagRegex: String?, ) { - settingsFile.writeText("") - ignoreFile.writeText(".gradle") - buildFile.writeText( + File(settingsFile).writeText("") + File(ignoreFile).writeText(".gradle") + File(buildFile).writeText( """ plugins { id("com.zegreatrob.tools.digger") @@ -63,8 +67,8 @@ class AllContributionFunctionalTest : AllContributionTestSpec { .forwardOutput() .withPluginClasspath() .withArguments("allContributionData", "-q") - .withProjectDir(projectDir) + .withProjectDir(File(projectDir)) .build() - return allOutput.readText() + return File(allOutput).readText() } } diff --git a/tools/digger-plugin/src/functionalTest/kotlin/com/zegreatrob/tools/digger/CurrentContributionFunctionalTest.kt b/tools/digger-plugin/src/functionalTest/kotlin/com/zegreatrob/tools/digger/CurrentContributionFunctionalTest.kt index 4bfa8e10..d1dd3e11 100644 --- a/tools/digger-plugin/src/functionalTest/kotlin/com/zegreatrob/tools/digger/CurrentContributionFunctionalTest.kt +++ b/tools/digger-plugin/src/functionalTest/kotlin/com/zegreatrob/tools/digger/CurrentContributionFunctionalTest.kt @@ -1,23 +1,27 @@ package com.zegreatrob.tools.digger import org.gradle.testkit.runner.GradleRunner -import org.junit.jupiter.api.io.TempDir import java.io.File class CurrentContributionFunctionalTest : CurrentContributionTestSpec { - @field:TempDir - override lateinit var projectDir: File + override lateinit var projectDir: String - private val buildFile by lazy { projectDir.resolve("build.gradle.kts") } - private val settingsFile by lazy { projectDir.resolve("settings.gradle") } - private val ignoreFile by lazy { projectDir.resolve(".gitignore") } + private val buildFile by lazy { "$projectDir/build.gradle.kts" } + private val settingsFile by lazy { "$projectDir/settings.gradle" } + private val ignoreFile by lazy { "$projectDir/.gitignore" } - override val addFileNames by lazy { setOf(settingsFile.name, buildFile.name, ignoreFile.name) } + override val addFileNames by lazy { + setOf( + settingsFile.split("/").last(), + buildFile.split("/").last(), + ignoreFile.split("/").last(), + ) + } override fun setupWithDefaults() { - settingsFile.writeText("") - ignoreFile.writeText(".gradle") - buildFile.writeText( + File(settingsFile).writeText("") + File(ignoreFile).writeText(".gradle") + File(buildFile).writeText( """ plugins { id("com.zegreatrob.tools.digger") @@ -36,9 +40,9 @@ class CurrentContributionFunctionalTest : CurrentContributionTestSpec { easeRegex: String?, tagRegex: String?, ) { - settingsFile.writeText("") - ignoreFile.writeText(".gradle") - buildFile.writeText( + File(settingsFile).writeText("") + File(ignoreFile).writeText(".gradle") + File(buildFile).writeText( """ plugins { id("com.zegreatrob.tools.digger") @@ -58,13 +62,13 @@ class CurrentContributionFunctionalTest : CurrentContributionTestSpec { } override fun runCurrentContributionData(): String { - val currentOutput by lazy { projectDir.resolve("build/digger/current.json") } + val currentOutput by lazy { "$projectDir/build/digger/current.json" } GradleRunner.create() .forwardOutput() .withPluginClasspath() .withArguments("currentContributionData", "-q") - .withProjectDir(projectDir) + .withProjectDir(File(projectDir)) .build() - return currentOutput.readText() + return File(currentOutput).readText() } } diff --git a/tools/digger-test/build.gradle.kts b/tools/digger-test/build.gradle.kts index a462d32a..d418c22e 100644 --- a/tools/digger-test/build.gradle.kts +++ b/tools/digger-test/build.gradle.kts @@ -3,7 +3,9 @@ plugins { } kotlin { - jvm { withJava() } + jvm { + withJava() + } js(IR) { nodejs() } } @@ -16,5 +18,10 @@ dependencies { "jvmMainImplementation"(kotlin("test-junit5", embeddedKotlinVersion)) "jvmMainImplementation"("org.junit.jupiter:junit-jupiter-api") "jvmMainImplementation"("org.junit.jupiter:junit-jupiter-engine") +} +tasks { + withType(Test::class) { + useJUnitPlatform() + } } diff --git a/tools/digger-test/src/commonMain/kotlin/com/zegreatrob/tools/digger/AllContributionTestSpec.kt b/tools/digger-test/src/commonMain/kotlin/com/zegreatrob/tools/digger/AllContributionTestSpec.kt index 6d1a721a..5d39869f 100644 --- a/tools/digger-test/src/commonMain/kotlin/com/zegreatrob/tools/digger/AllContributionTestSpec.kt +++ b/tools/digger-test/src/commonMain/kotlin/com/zegreatrob/tools/digger/AllContributionTestSpec.kt @@ -5,13 +5,16 @@ import com.zegreatrob.tools.adapter.git.TagRef import com.zegreatrob.tools.digger.model.Contribution import com.zegreatrob.tools.test.git.addCommitWithMessage import com.zegreatrob.tools.test.git.addTag +import com.zegreatrob.tools.test.git.createTempDirectory import com.zegreatrob.tools.test.git.defaultAuthors import com.zegreatrob.tools.test.git.delayLongEnoughToAffectGitDate import com.zegreatrob.tools.test.git.ffOnlyInBranch import com.zegreatrob.tools.test.git.initializeGitRepo import com.zegreatrob.tools.test.git.mergeInBranch +import com.zegreatrob.tools.test.git.removeDirectory import com.zegreatrob.tools.test.git.switchToNewBranch import kotlinx.coroutines.test.runTest +import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals @@ -27,6 +30,15 @@ interface AllContributionTestSpec : SetupWithOverrides { commits = commits, ) + @BeforeTest + fun setupProjectDir() { + projectDir = createTempDirectory() + } + + fun tearDown() { + removeDirectory(projectDir) + } + @Test fun willIncludeAllTagSegments() { setupWithDefaults() diff --git a/tools/digger-test/src/commonMain/kotlin/com/zegreatrob/tools/digger/CurrentContributionTestSpec.kt b/tools/digger-test/src/commonMain/kotlin/com/zegreatrob/tools/digger/CurrentContributionTestSpec.kt index 4e69d5c3..e63da499 100644 --- a/tools/digger-test/src/commonMain/kotlin/com/zegreatrob/tools/digger/CurrentContributionTestSpec.kt +++ b/tools/digger-test/src/commonMain/kotlin/com/zegreatrob/tools/digger/CurrentContributionTestSpec.kt @@ -6,11 +6,13 @@ import com.zegreatrob.tools.digger.json.ContributionParser.parseContribution import com.zegreatrob.tools.digger.model.Contribution import com.zegreatrob.tools.test.git.addCommitWithMessage import com.zegreatrob.tools.test.git.addTag +import com.zegreatrob.tools.test.git.createTempDirectory import com.zegreatrob.tools.test.git.defaultAuthors import com.zegreatrob.tools.test.git.delayLongEnoughToAffectGitDate import com.zegreatrob.tools.test.git.getEnvironmentVariable import com.zegreatrob.tools.test.git.initializeGitRepo import com.zegreatrob.tools.test.git.mergeInBranch +import com.zegreatrob.tools.test.git.removeDirectory import com.zegreatrob.tools.test.git.sleep import com.zegreatrob.tools.test.git.switchToNewBranch import kotlinx.coroutines.test.runTest @@ -25,6 +27,15 @@ interface CurrentContributionTestSpec : SetupWithOverrides { fun setupWithDefaults() fun runCurrentContributionData(): String + @BeforeTest + fun setupProjectDir() { + projectDir = createTempDirectory() + } + + fun tearDown() { + removeDirectory(projectDir) + } + @BeforeTest fun checkPrerequisites() { assertEquals( diff --git a/tools/git-adapter/src/jvmTest/kotlin/com/zegreatrob/tools/adapter/git/GitAdapterTest.kt b/tools/git-adapter/src/jvmTest/kotlin/com/zegreatrob/tools/adapter/git/GitAdapterTest.kt index 9c819279..0c885fbb 100644 --- a/tools/git-adapter/src/jvmTest/kotlin/com/zegreatrob/tools/adapter/git/GitAdapterTest.kt +++ b/tools/git-adapter/src/jvmTest/kotlin/com/zegreatrob/tools/adapter/git/GitAdapterTest.kt @@ -3,6 +3,7 @@ package com.zegreatrob.tools.adapter.git import com.zegreatrob.tools.test.git.addCommitWithMessage import com.zegreatrob.tools.test.git.delayLongEnoughToAffectGitDate import com.zegreatrob.tools.test.git.initializeGitRepo +import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.io.TempDir import java.io.File @@ -27,7 +28,7 @@ class GitAdapterTest { ) @Test - fun `will include all tag segments from newest to oldest`() { + fun `will include all tag segments from newest to oldest`() = runTest { val gitAdapter = initializeGitRepo(commits = listOf("here's a message")) gitAdapter.config("user.name", "Test") gitAdapter.config("user.email", "Test") diff --git a/tools/cli-tools/src/commonMain/kotlin/com/zegreatrob/tools/cli/CreateTempDirectory.kt b/tools/git-test/src/commonMain/kotlin/com/zegreatrob/tools/test/git/CreateTempDirectory.kt similarity index 52% rename from tools/cli-tools/src/commonMain/kotlin/com/zegreatrob/tools/cli/CreateTempDirectory.kt rename to tools/git-test/src/commonMain/kotlin/com/zegreatrob/tools/test/git/CreateTempDirectory.kt index 315b2e99..a0df90b1 100644 --- a/tools/cli-tools/src/commonMain/kotlin/com/zegreatrob/tools/cli/CreateTempDirectory.kt +++ b/tools/git-test/src/commonMain/kotlin/com/zegreatrob/tools/test/git/CreateTempDirectory.kt @@ -1,3 +1,3 @@ -package com.zegreatrob.tools.cli +package com.zegreatrob.tools.test.git expect fun createTempDirectory(): String diff --git a/tools/cli-tools/src/commonMain/kotlin/com/zegreatrob/tools/cli/RemoveDirectory.kt b/tools/git-test/src/commonMain/kotlin/com/zegreatrob/tools/test/git/RemoveDirectory.kt similarity index 57% rename from tools/cli-tools/src/commonMain/kotlin/com/zegreatrob/tools/cli/RemoveDirectory.kt rename to tools/git-test/src/commonMain/kotlin/com/zegreatrob/tools/test/git/RemoveDirectory.kt index 59450fcb..0f96ae3e 100644 --- a/tools/cli-tools/src/commonMain/kotlin/com/zegreatrob/tools/cli/RemoveDirectory.kt +++ b/tools/git-test/src/commonMain/kotlin/com/zegreatrob/tools/test/git/RemoveDirectory.kt @@ -1,3 +1,3 @@ -package com.zegreatrob.tools.cli +package com.zegreatrob.tools.test.git expect fun removeDirectory(directoryPath: String) diff --git a/tools/cli-tools/src/jsMain/kotlin/com/zegreatrob/tools/cli/CreateTempDirectory.js.kt b/tools/git-test/src/jsMain/kotlin/com/zegreatrob/tools/test/git/CreateTempDirectory.js.kt similarity index 86% rename from tools/cli-tools/src/jsMain/kotlin/com/zegreatrob/tools/cli/CreateTempDirectory.js.kt rename to tools/git-test/src/jsMain/kotlin/com/zegreatrob/tools/test/git/CreateTempDirectory.js.kt index 9cb7539c..7baf7a20 100644 --- a/tools/cli-tools/src/jsMain/kotlin/com/zegreatrob/tools/cli/CreateTempDirectory.js.kt +++ b/tools/git-test/src/jsMain/kotlin/com/zegreatrob/tools/test/git/CreateTempDirectory.js.kt @@ -1,4 +1,4 @@ -package com.zegreatrob.tools.cli +package com.zegreatrob.tools.test.git private val fs = js("require('node:fs')") private val path = js("require('node:path')") diff --git a/tools/cli-tools/src/jsMain/kotlin/com/zegreatrob/tools/cli/RemoveDirectory.js.kt b/tools/git-test/src/jsMain/kotlin/com/zegreatrob/tools/test/git/RemoveDirectory.js.kt similarity index 83% rename from tools/cli-tools/src/jsMain/kotlin/com/zegreatrob/tools/cli/RemoveDirectory.js.kt rename to tools/git-test/src/jsMain/kotlin/com/zegreatrob/tools/test/git/RemoveDirectory.js.kt index efd1b871..d61d246f 100644 --- a/tools/cli-tools/src/jsMain/kotlin/com/zegreatrob/tools/cli/RemoveDirectory.js.kt +++ b/tools/git-test/src/jsMain/kotlin/com/zegreatrob/tools/test/git/RemoveDirectory.js.kt @@ -1,4 +1,4 @@ -package com.zegreatrob.tools.cli +package com.zegreatrob.tools.test.git import kotlin.js.json diff --git a/tools/cli-tools/src/jvmMain/kotlin/com/zegreatrob/tools/cli/CreateTempDirectory.jvm.kt b/tools/git-test/src/jvmMain/kotlin/com/zegreatrob/tools/test/git/CreateTempDirectory.jvm.kt similarity index 81% rename from tools/cli-tools/src/jvmMain/kotlin/com/zegreatrob/tools/cli/CreateTempDirectory.jvm.kt rename to tools/git-test/src/jvmMain/kotlin/com/zegreatrob/tools/test/git/CreateTempDirectory.jvm.kt index 37e0afef..322e9128 100644 --- a/tools/cli-tools/src/jvmMain/kotlin/com/zegreatrob/tools/cli/CreateTempDirectory.jvm.kt +++ b/tools/git-test/src/jvmMain/kotlin/com/zegreatrob/tools/test/git/CreateTempDirectory.jvm.kt @@ -1,4 +1,4 @@ -package com.zegreatrob.tools.cli +package com.zegreatrob.tools.test.git import java.nio.file.Files import kotlin.io.path.absolutePathString diff --git a/tools/cli-tools/src/jvmMain/kotlin/com/zegreatrob/tools/cli/RemoveDirectory.jvm.kt b/tools/git-test/src/jvmMain/kotlin/com/zegreatrob/tools/test/git/RemoveDirectory.jvm.kt similarity index 80% rename from tools/cli-tools/src/jvmMain/kotlin/com/zegreatrob/tools/cli/RemoveDirectory.jvm.kt rename to tools/git-test/src/jvmMain/kotlin/com/zegreatrob/tools/test/git/RemoveDirectory.jvm.kt index 807152e7..5f789e85 100644 --- a/tools/cli-tools/src/jvmMain/kotlin/com/zegreatrob/tools/cli/RemoveDirectory.jvm.kt +++ b/tools/git-test/src/jvmMain/kotlin/com/zegreatrob/tools/test/git/RemoveDirectory.jvm.kt @@ -1,4 +1,4 @@ -package com.zegreatrob.tools.cli +package com.zegreatrob.tools.test.git import java.nio.file.Files import java.nio.file.Paths