Skip to content

Commit

Permalink
alright, digger tests now run in both js and jvm mode
Browse files Browse the repository at this point in the history
  • Loading branch information
robertfmurdock committed Oct 3, 2024
1 parent 6401862 commit 9266316
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -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<String> = emptySet()
private lateinit var outputFile: String
private lateinit var arguments: List<String>
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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
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

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<String> = emptySet()

private lateinit var arguments: List<String>

@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
Expand Down
4 changes: 3 additions & 1 deletion tools/digger-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ tasks {
dependsOn(testing.suites.named("functionalTest"))
}
publish { finalizedBy("::closeAndReleaseSonatypeStagingRepository") }
named<Test>("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") }
Expand Down
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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")
Expand All @@ -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()
}
}
Original file line number Diff line number Diff line change
@@ -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")
Expand All @@ -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")
Expand All @@ -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()
}
}
9 changes: 8 additions & 1 deletion tools/digger-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ plugins {
}

kotlin {
jvm { withJava() }
jvm {
withJava()
}
js(IR) { nodejs() }
}

Expand All @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -27,6 +30,15 @@ interface AllContributionTestSpec : SetupWithOverrides {
commits = commits,
)

@BeforeTest
fun setupProjectDir() {
projectDir = createTempDirectory()
}

fun tearDown() {
removeDirectory(projectDir)
}

@Test
fun willIncludeAllTagSegments() {
setupWithDefaults()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package com.zegreatrob.tools.cli
package com.zegreatrob.tools.test.git

expect fun createTempDirectory(): String
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package com.zegreatrob.tools.cli
package com.zegreatrob.tools.test.git

expect fun removeDirectory(directoryPath: String)
Original file line number Diff line number Diff line change
@@ -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')")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.zegreatrob.tools.cli
package com.zegreatrob.tools.test.git

import kotlin.js.json

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 9266316

Please sign in to comment.