Skip to content

Commit

Permalink
tests: Extract RemigrateTest
Browse files Browse the repository at this point in the history
* Speed up parallel test execution by extracting a rather long-running
  test into a separate test class (RemigrateTest).
* RemigrateTest: remove output forwarding.
  • Loading branch information
sergej-koscejev committed Jun 28, 2024
1 parent 62ca270 commit fd660b4
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 37 deletions.
76 changes: 76 additions & 0 deletions src/test/kotlin/test/migration/RemigrateTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package test.migration

import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.TaskOutcome
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TemporaryFolder
import support.extractTestProject
import java.io.File

class RemigrateTest {
@Rule
@JvmField
val testProjectDir: TemporaryFolder = TemporaryFolder()
private lateinit var settingsFile: File
private lateinit var buildFile: File
private lateinit var mpsTestPrjLocation: File

@Before
fun setup() {
settingsFile = testProjectDir.newFile("settings.gradle.kts")
settingsFile.writeText(
"""
rootProject.name = "hello-world"
""".trimIndent()
)
buildFile = testProjectDir.newFile("build.gradle.kts")
mpsTestPrjLocation = testProjectDir.newFolder("mps-prj")
extractProject("test-project")
}

private fun extractProject(name: String) = extractTestProject(name, mpsTestPrjLocation)

@Test
fun `Remigrate task works`() {
buildFile.writeText(
"""
import de.itemis.mps.gradle.tasks.Remigrate
plugins {
id("de.itemis.mps.gradle.common")
}
repositories {
mavenCentral()
maven("https://artifacts.itemis.cloud/repository/maven-mps")
}
val mps = configurations.create("mps")
dependencies {
mps("com.jetbrains:mps:2021.3.2")
}
val resolveMps by tasks.registering(Sync::class) {
from(Callable { zipTree(mps.singleFile) })
into(layout.buildDirectory.dir("mps"))
}
val remigrate by tasks.registering(Remigrate::class) {
projectDirectories.from("$mpsTestPrjLocation")
mpsHome.set(layout.dir(resolveMps.map { it.destinationDir }))
}
""".trimIndent()
)

val result = gradleRunner().withArguments("remigrate").build()

assertEquals(TaskOutcome.SUCCESS, result.task(":remigrate")?.outcome)
}

private fun gradleRunner(): GradleRunner = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withPluginClasspath()
}
37 changes: 0 additions & 37 deletions src/test/kotlin/test/migration/RunMigrationsTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -211,43 +211,6 @@ class RunMigrationsTest {
assertEquals(TaskOutcome.SUCCESS, result.task(":migrate")?.outcome)
}

@Test
fun `Remigrate task works`() {
buildFile.writeText(
"""
import de.itemis.mps.gradle.tasks.Remigrate
plugins {
id("de.itemis.mps.gradle.common")
}
repositories {
mavenCentral()
maven("https://artifacts.itemis.cloud/repository/maven-mps")
}
val mps = configurations.create("mps")
dependencies {
mps("com.jetbrains:mps:2021.3.2")
}
val resolveMps by tasks.registering(Sync::class) {
from(Callable { zipTree(mps.singleFile) })
into(layout.buildDirectory.dir("mps"))
}
val remigrate by tasks.registering(Remigrate::class) {
projectDirectories.from("$mpsTestPrjLocation")
mpsHome.set(layout.dir(resolveMps.map { it.destinationDir }))
}
""".trimIndent()
)

val result = gradleRunner().withArguments("remigrate").forwardOutput().build()

assertEquals(TaskOutcome.SUCCESS, result.task(":remigrate")?.outcome)
}

private fun gradleRunner(): GradleRunner = GradleRunner.create()
.withProjectDir(testProjectDir.root)
.withPluginClasspath()
Expand Down

0 comments on commit fd660b4

Please sign in to comment.