Skip to content

Commit 10876d4

Browse files
committed
Move buildTools test fixtures to disk
Replace the inline FileLayout DSL strings with real project files under src/test/resources/fixtures, copied into the temp workdir at runtime via classpath resources. A @java@ placeholder covers the parametrized Gradle toolchain cases. Deletes FileLayout.kt and the standalone pom resource.
1 parent 9a25c6d commit 10876d4

54 files changed

Lines changed: 287 additions & 402 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build.sbt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,6 @@ lazy val unit = project
565565
.dependsOn(javacPlugin, cli)
566566
.enablePlugins(BuildInfoPlugin)
567567

568-
// Kotlin/JUnit5 integration tests that drive the scip-java CLI against real
569-
// Maven/Gradle/manual projects. Depends only on `cli` (no munit, no Scala) so
570-
// the test stack matches the now-Kotlin product.
571568
lazy val buildTools = project
572569
.in(file("tests/buildTools"))
573570
.enablePlugins(KotlinPlugin)

tests/buildTools/src/test/kotlin/tests/BuildToolHarness.kt

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import java.io.PrintStream
88
import java.nio.charset.StandardCharsets
99
import java.nio.file.Files
1010
import java.nio.file.Path
11+
import java.nio.file.Paths
12+
import java.nio.file.StandardCopyOption
1113
import java.util.stream.Collectors
1214
import kotlin.test.assertEquals
1315
import kotlin.test.assertNotEquals
@@ -104,6 +106,44 @@ abstract class BuildToolHarness {
104106
*/
105107
private fun newTempBase(): Path = Files.createTempDirectory("buildtools").toRealPath()
106108

109+
/**
110+
* Materialize a test project from the `fixtures/<name>` directory on the
111+
* test classpath into [target], overwriting existing files (e.g. a stub
112+
* `build.gradle` left behind by wrapper generation). When [substitutions]
113+
* is non-empty, each token is textually replaced in every file, which lets a
114+
* single fixture cover parametrized variants (e.g. the JDK in a toolchain).
115+
*/
116+
private fun copyFixture(
117+
fixture: String,
118+
target: Path,
119+
substitutions: Map<String, String>,
120+
) {
121+
val resource = "/fixtures/$fixture"
122+
val url =
123+
BuildToolHarness::class.java.getResource(resource)
124+
?: error("Fixture not found on test classpath: $resource")
125+
val source = Paths.get(url.toURI())
126+
Files.walk(source).use { stream ->
127+
stream.forEach { path ->
128+
val dest = target.resolve(source.relativize(path).toString())
129+
if (Files.isDirectory(path)) {
130+
Files.createDirectories(dest)
131+
} else {
132+
Files.createDirectories(dest.parent)
133+
if (substitutions.isEmpty()) {
134+
Files.copy(path, dest, StandardCopyOption.REPLACE_EXISTING)
135+
} else {
136+
var text = Files.readString(path)
137+
for ((token, value) in substitutions) {
138+
text = text.replace(token, value)
139+
}
140+
Files.writeString(dest, text)
141+
}
142+
}
143+
}
144+
}
145+
}
146+
107147
/** Compare two strings ignoring trailing whitespace. */
108148
protected fun assertNoDiff(obtained: String, expected: String) {
109149
if (obtained.trimEnd() != expected.trimEnd()) {
@@ -116,7 +156,7 @@ abstract class BuildToolHarness {
116156

117157
protected fun checkBuild(
118158
name: String,
119-
original: String,
159+
fixture: String,
120160
expectedScipFiles: Int = 0,
121161
extraArguments: List<String> = emptyList(),
122162
expectedError: ((String) -> Unit)? = null,
@@ -125,6 +165,7 @@ abstract class BuildToolHarness {
125165
prepare: (Path) -> Unit = {},
126166
targetRoot: String? = null,
127167
maxJdk: Int? = null,
168+
substitutions: Map<String, String> = emptyMap(),
128169
): DynamicTest =
129170
dynamicTest(name) {
130171
val supported =
@@ -144,7 +185,7 @@ abstract class BuildToolHarness {
144185
val init = initCommand(workingDirectory)
145186
if (init.isNotEmpty()) exec(init, workingDirectory)
146187

147-
FileLayout.fromString(original, workingDirectory)
188+
copyFixture(fixture, workingDirectory, substitutions)
148189
prepare(workingDirectory)
149190

150191
val targetroot = workingDirectory.resolve(targetRoot ?: "targetroot")
@@ -192,14 +233,14 @@ abstract class BuildToolHarness {
192233
name: String,
193234
arguments: List<String>,
194235
expectedOutput: String,
195-
workingDirectoryLayout: String = "",
236+
fixture: String? = null,
196237
): DynamicTest =
197238
dynamicTest(name) {
198239
val base = newTempBase()
199240
try {
200241
val workingDirectory = Files.createDirectories(base.resolve("workingDirectory"))
201-
if (workingDirectoryLayout.isNotEmpty()) {
202-
FileLayout.fromString(workingDirectoryLayout, workingDirectory)
242+
if (fixture != null) {
243+
copyFixture(fixture, workingDirectory, emptyMap())
203244
}
204245
val (exit, rawOutput) = runScipJava(workingDirectory, arguments)
205246
val output = rawOutput.replace(base.toString(), "")

tests/buildTools/src/test/kotlin/tests/FileLayout.kt

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)