Minor. Review fixes
This commit is contained in:
+5
-19
@@ -16,17 +16,13 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.codegen
|
package org.jetbrains.kotlin.codegen
|
||||||
|
|
||||||
import com.google.common.io.Files
|
|
||||||
import com.intellij.openapi.util.text.StringUtil
|
import com.intellij.openapi.util.text.StringUtil
|
||||||
import com.intellij.util.containers.ContainerUtil
|
|
||||||
import junit.framework.TestCase
|
import junit.framework.TestCase
|
||||||
import org.jetbrains.kotlin.backend.common.output.OutputFileCollection
|
import org.jetbrains.kotlin.backend.common.output.OutputFileCollection
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
import org.jetbrains.kotlin.utils.rethrow
|
import org.jetbrains.kotlin.utils.rethrow
|
||||||
import org.jetbrains.org.objectweb.asm.*
|
import org.jetbrains.org.objectweb.asm.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
|
||||||
import java.nio.charset.Charset
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.regex.Pattern
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
@@ -36,7 +32,6 @@ import java.util.regex.Pattern
|
|||||||
|
|
||||||
abstract class AbstractCheckLocalVariablesTableTest : CodegenTestCase() {
|
abstract class AbstractCheckLocalVariablesTableTest : CodegenTestCase() {
|
||||||
|
|
||||||
@Throws(Exception::class)
|
|
||||||
override fun doMultiFileTest(wholeFile: File, files: List<CodegenTestCase.TestFile>, javaFilesDir: File?) {
|
override fun doMultiFileTest(wholeFile: File, files: List<CodegenTestCase.TestFile>, javaFilesDir: File?) {
|
||||||
compile(files, javaFilesDir)
|
compile(files, javaFilesDir)
|
||||||
|
|
||||||
@@ -48,7 +43,7 @@ abstract class AbstractCheckLocalVariablesTableTest : CodegenTestCase() {
|
|||||||
val methodName = split[1]
|
val methodName = split[1]
|
||||||
|
|
||||||
val outputFiles = (classFileFactory as OutputFileCollection).asList()
|
val outputFiles = (classFileFactory as OutputFileCollection).asList()
|
||||||
val outputFile = ContainerUtil.find(outputFiles, { file -> file.relativePath.matches(classFileRegex.toRegex()) })
|
val outputFile = outputFiles.first { file -> file.relativePath.matches(classFileRegex.toRegex()) }
|
||||||
|
|
||||||
val pathsString = outputFiles.joinToString { it.relativePath }
|
val pathsString = outputFiles.joinToString { it.relativePath }
|
||||||
assertNotNull("Couldn't find class file for pattern $classFileRegex in: $pathsString", outputFile)
|
assertNotNull("Couldn't find class file for pattern $classFileRegex in: $pathsString", outputFile)
|
||||||
@@ -69,7 +64,7 @@ abstract class AbstractCheckLocalVariablesTableTest : CodegenTestCase() {
|
|||||||
) {
|
) {
|
||||||
KotlinTestUtils.assertEqualsToFile(
|
KotlinTestUtils.assertEqualsToFile(
|
||||||
testFile,
|
testFile,
|
||||||
text.substring(0, text.indexOf("// VARIABLE : ")) + getActualVariablesAsString(
|
text.substringBefore("// VARIABLE : ") + getActualVariablesAsString(
|
||||||
actualLocalVariables
|
actualLocalVariables
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -86,10 +81,8 @@ abstract class AbstractCheckLocalVariablesTableTest : CodegenTestCase() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Throws(IOException::class)
|
|
||||||
private fun parseClassAndMethodSignature(testFile: File): String {
|
private fun parseClassAndMethodSignature(testFile: File): String {
|
||||||
val lines = Files.readLines(testFile, Charset.forName("utf-8"))
|
for (line in testFile.readLines()) {
|
||||||
for (line in lines) {
|
|
||||||
val methodMatcher = methodPattern.matcher(line)
|
val methodMatcher = methodPattern.matcher(line)
|
||||||
if (methodMatcher.matches()) {
|
if (methodMatcher.matches()) {
|
||||||
return methodMatcher.group(1)
|
return methodMatcher.group(1)
|
||||||
@@ -101,17 +94,10 @@ abstract class AbstractCheckLocalVariablesTableTest : CodegenTestCase() {
|
|||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private fun getActualVariablesAsString(list: List<LocalVariable>): String {
|
private fun getActualVariablesAsString(list: List<LocalVariable>) = list.joinToString("\n")
|
||||||
val builder = StringBuilder()
|
|
||||||
for (variable in list) {
|
|
||||||
builder.append(variable.toString()).append("\n")
|
|
||||||
}
|
|
||||||
return builder.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
private val methodPattern = Pattern.compile("^// METHOD : *(.*)")
|
private val methodPattern = Pattern.compile("^// METHOD : *(.*)")
|
||||||
|
|
||||||
@Throws(Exception::class)
|
|
||||||
private fun readLocalVariable(cr: ClassReader, methodName: String): List<LocalVariable> {
|
private fun readLocalVariable(cr: ClassReader, methodName: String): List<LocalVariable> {
|
||||||
|
|
||||||
class Visitor : ClassVisitor(Opcodes.ASM5) {
|
class Visitor : ClassVisitor(Opcodes.ASM5) {
|
||||||
@@ -138,7 +124,7 @@ abstract class AbstractCheckLocalVariablesTableTest : CodegenTestCase() {
|
|||||||
|
|
||||||
cr.accept(visitor, ClassReader.SKIP_FRAMES)
|
cr.accept(visitor, ClassReader.SKIP_FRAMES)
|
||||||
|
|
||||||
TestCase.assertFalse("method not found: $methodName", visitor.readVariables.size == 0)
|
TestCase.assertFalse("method not found: $methodName", visitor.readVariables.isEmpty())
|
||||||
|
|
||||||
return visitor.readVariables
|
return visitor.readVariables
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
|||||||
import org.jetbrains.kotlin.test.ConfigurationKind
|
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||||
import org.junit.ComparisonFailure
|
import org.junit.ComparisonFailure
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.charset.Charset
|
|
||||||
|
|
||||||
abstract class AbstractIrCheckLocalVariablesTableTest : AbstractCheckLocalVariablesTableTest() {
|
abstract class AbstractIrCheckLocalVariablesTableTest : AbstractCheckLocalVariablesTableTest() {
|
||||||
|
|
||||||
@@ -21,7 +20,7 @@ abstract class AbstractIrCheckLocalVariablesTableTest : AbstractCheckLocalVariab
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun extractConfigurationKind(files: MutableList<TestFile>): ConfigurationKind {
|
override fun extractConfigurationKind(files: MutableList<TestFile>): ConfigurationKind {
|
||||||
return ConfigurationKind.ALL;
|
return ConfigurationKind.ALL
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun doCompare(
|
override fun doCompare(
|
||||||
@@ -47,7 +46,7 @@ abstract class AbstractIrCheckLocalVariablesTableTest : AbstractCheckLocalVariab
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getExpectedVariablesAsList(testFile: File): List<String> {
|
private fun getExpectedVariablesAsList(testFile: File): List<String> {
|
||||||
return testFile.readLines(Charset.forName("utf-8"))
|
return testFile.readLines()
|
||||||
.filter { line -> line.startsWith("// VARIABLE ") }
|
.filter { line -> line.startsWith("// VARIABLE ") }
|
||||||
.filter { !it.contains("NAME=\$i\$") }
|
.filter { !it.contains("NAME=\$i\$") }
|
||||||
.map { line -> line.replaceFirst("INDEX=\\d+".toRegex(), "INDEX=*") } // Ignore index
|
.map { line -> line.replaceFirst("INDEX=\\d+".toRegex(), "INDEX=*") } // Ignore index
|
||||||
|
|||||||
Reference in New Issue
Block a user