Try 0 and 1 starting lines in Kapt location mapping tests
This commit is contained in:
+21
-12
@@ -355,22 +355,27 @@ open class Kapt3IT : Kapt3BaseIT() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testLocationMapping() {
|
fun testLocationMapping() {
|
||||||
fun String.modifyNumbers(fn: (Int) -> Int): String =
|
|
||||||
replace("\\d+".toRegex()) { fn(it.value.toInt()).toString() }
|
|
||||||
|
|
||||||
val project = Project("locationMapping", directoryPrefix = "kapt2")
|
val project = Project("locationMapping", directoryPrefix = "kapt2")
|
||||||
val regex = "((Test\\.java)|(test\\.kt)):(\\d+): error: GenError element".toRegex()
|
val regex = "((Test\\.java)|(test\\.kt)):(\\d+): error: GenError element".toRegex()
|
||||||
|
|
||||||
fun CompiledProject.getErrorMessages(): String =
|
fun CompiledProject.getErrorMessages(): String =
|
||||||
regex.findAll(output)
|
regex.findAll(output).map { it.value }.joinToString("\n")
|
||||||
.map { it.value }
|
|
||||||
.joinToString("\n") { if (isWindows) it.modifyNumbers { it + 1 } else it }
|
fun genJavaErrorString(vararg lines: Int) =
|
||||||
|
lines.joinToString("\n") { "Test.java:$it: error: GenError element" }
|
||||||
|
|
||||||
|
fun genKotlinErrorString(vararg lines: Int) =
|
||||||
|
lines.joinToString("\n") { "test.kt:$it: error: GenError element" }
|
||||||
|
|
||||||
project.build("build") {
|
project.build("build") {
|
||||||
assertFailed()
|
assertFailed()
|
||||||
|
val actual = getErrorMessages()
|
||||||
val expected = arrayOf(9, 17).joinToString("\n") { "Test.java:$it: error: GenError element" }
|
// try as 0 starting lines first, then as 1 starting line
|
||||||
Assert.assertEquals(expected, getErrorMessages())
|
try {
|
||||||
|
Assert.assertEquals(genJavaErrorString(9, 17), actual)
|
||||||
|
} catch (e: AssertionError) {
|
||||||
|
Assert.assertEquals(genJavaErrorString(10, 18), actual)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
project.projectDir.getFileByName("build.gradle").modify {
|
project.projectDir.getFileByName("build.gradle").modify {
|
||||||
@@ -379,9 +384,13 @@ open class Kapt3IT : Kapt3BaseIT() {
|
|||||||
|
|
||||||
project.build("build") {
|
project.build("build") {
|
||||||
assertFailed()
|
assertFailed()
|
||||||
|
val actual = getErrorMessages()
|
||||||
val expected = arrayOf(3, 7).joinToString("\n") { "test.kt:$it: error: GenError element" }
|
// try as 0 starting lines first, then as 1 starting line
|
||||||
Assert.assertEquals(expected, getErrorMessages())
|
try {
|
||||||
|
Assert.assertEquals(genKotlinErrorString(2, 6), actual)
|
||||||
|
} catch (e: AssertionError) {
|
||||||
|
Assert.assertEquals(genKotlinErrorString(3, 7), actual)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user