|
1 | 1 | /* |
2 | | - * Copyright (C) 2023-2025 DiffPlug |
| 2 | + * Copyright (C) 2023-2026 DiffPlug |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
@@ -177,13 +177,13 @@ open class HarnessKotest() : FunSpec() { |
177 | 177 | fun content() = lines.subList(startInclusive, endInclusive + 1).joinToString("\n") |
178 | 178 | fun setContent(mustBe: String) { |
179 | 179 | FS_SYSTEM.write(subprojectFolder.resolve(subpath)) { |
180 | | - for (i in 0 ..< startInclusive) { |
| 180 | + for (i in 0..<startInclusive) { |
181 | 181 | writeUtf8(lines[i]) |
182 | 182 | writeUtf8("\n") |
183 | 183 | } |
184 | 184 | writeUtf8(mustBe) |
185 | 185 | writeUtf8("\n") |
186 | | - for (i in endInclusive + 1 ..< lines.size) { |
| 186 | + for (i in endInclusive + 1..<lines.size) { |
187 | 187 | writeUtf8(lines[i]) |
188 | 188 | writeUtf8("\n") |
189 | 189 | } |
@@ -223,7 +223,25 @@ open class HarnessKotest() : FunSpec() { |
223 | 223 | return FS_SYSTEM.read(pathStr.toPath()) { AssertionError(readUtf8()) } |
224 | 224 | } |
225 | 225 | } |
226 | | - private fun testName() = "UT_${thisClassName()}" |
| 226 | + private fun testName(): String { |
| 227 | + val simpleClassName = "UT_${thisClassName()}" |
| 228 | + val matches = |
| 229 | + FS_SYSTEM.listRecursively(subprojectFolder) |
| 230 | + .filter { it.name == "$simpleClassName.kt" && !it.toString().contains("build") } |
| 231 | + .toList() |
| 232 | + if (matches.size == 1) { |
| 233 | + FS_SYSTEM.read(matches[0]) { |
| 234 | + while (!exhausted()) { |
| 235 | + val line = readUtf8Line() ?: break |
| 236 | + if (line.startsWith("package ")) { |
| 237 | + val pkg = line.removePrefix("package ").trim() |
| 238 | + return "$pkg.$simpleClassName" |
| 239 | + } |
| 240 | + } |
| 241 | + } |
| 242 | + } |
| 243 | + return simpleClassName |
| 244 | + } |
227 | 245 | fun gradleWriteSS() { |
228 | 246 | gradlew("test", "-PunderTest=true", "-Pselfie=overwrite", "--tests", testName())?.let { |
229 | 247 | throw AssertionError("Expected write snapshots to succeed, but it failed", it) |
|
0 commit comments