Cleanup of CheckLocalVariablesTableTest
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
||||
data class someClass(val a: Double, val b: Double)
|
||||
|
||||
// METHOD : copy(DD)LsomeClass;
|
||||
// METHOD : someClass.copy(DD)LsomeClass;
|
||||
// VARIABLE : NAME=this TYPE=LsomeClass; INDEX=0
|
||||
// VARIABLE : NAME=a TYPE=D INDEX=1
|
||||
// VARIABLE : NAME=b TYPE=D INDEX=3
|
||||
+1
-1
@@ -4,6 +4,6 @@ fun foo1() {
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD : invoke(I)V
|
||||
// METHOD : _DefaultPackage$foo1$1.invoke(I)V
|
||||
// VARIABLE : NAME=this TYPE=L_DefaultPackage$foo1$1; INDEX=0
|
||||
// VARIABLE : NAME=it TYPE=I INDEX=1
|
||||
+1
-1
@@ -6,6 +6,6 @@ fun foo() {
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD : invoke(I)V
|
||||
// METHOD : _DefaultPackage$foo$1$1.invoke(I)V
|
||||
// VARIABLE : NAME=this TYPE=L_DefaultPackage$foo$1$1; INDEX=0
|
||||
// VARIABLE : NAME=it TYPE=I INDEX=1
|
||||
+1
-1
@@ -4,5 +4,5 @@ fun foo() {
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD : invoke()V
|
||||
// METHOD : _DefaultPackage$foo$a$1.invoke()V
|
||||
// VARIABLE : NAME=this TYPE=L_DefaultPackage$foo$a$1; INDEX=0
|
||||
+1
-1
@@ -3,5 +3,5 @@ fun foo() {
|
||||
}
|
||||
}
|
||||
|
||||
// METHOD : invoke()V
|
||||
// METHOD : _DefaultPackage$foo$1.invoke()V
|
||||
// VARIABLE : NAME=this TYPE=L_DefaultPackage$foo$1; INDEX=0
|
||||
+41
-31
@@ -17,8 +17,11 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.google.common.io.Files;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.asm4.*;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
@@ -69,34 +72,41 @@ public abstract class AbstractCheckLocalVariablesTableTest extends TestCaseWithT
|
||||
|
||||
OutputFileCollection outputFiles = GenerationUtils.compileFileGetClassFileFactoryForTest(psiFile);
|
||||
|
||||
String modifiedTestName = ktFile.getName().replace(".kt", ".class");
|
||||
boolean isClassFound = false;
|
||||
for (OutputFile outputFile : outputFiles.asList()) {
|
||||
if (outputFile.getRelativePath().equals(modifiedTestName)) {
|
||||
isClassFound = true;
|
||||
ClassReader cr = new ClassReader(outputFile.asByteArray());
|
||||
List<LocalVariable> expectedLocalVariables = parseExpectations();
|
||||
List<LocalVariable> actualLocalVariables = readLocalVariable(cr, parseMethodName());
|
||||
String classAndMethod = parseClassAndMethodSignature();
|
||||
String[] split = classAndMethod.split("\\.");
|
||||
assert split.length == 2 : "Exactly one dot is expected: " + classAndMethod;
|
||||
final String classFileRegex = StringUtil.escapeToRegexp(split[0] + ".class").replace("\\*", ".+");
|
||||
String methodName = split[1];
|
||||
|
||||
assertEquals("Count of variables are different", expectedLocalVariables.size(), actualLocalVariables.size());
|
||||
|
||||
int index = 0;
|
||||
for (LocalVariable expectedVariable : expectedLocalVariables) {
|
||||
LocalVariable actualVariable = actualLocalVariables.get(index);
|
||||
assertEquals("Names are different", expectedVariable.name, actualVariable.name);
|
||||
assertEquals("Types are different", expectedVariable.type, actualVariable.type);
|
||||
assertEquals("Indexes are different", expectedVariable.index, actualVariable.index);
|
||||
index++;
|
||||
}
|
||||
OutputFile outputFile = ContainerUtil.find(outputFiles.asList(), new Condition<OutputFile>() {
|
||||
@Override
|
||||
public boolean value(OutputFile outputFile) {
|
||||
return outputFile.getRelativePath().matches(classFileRegex);
|
||||
}
|
||||
});
|
||||
|
||||
String pathsString = StringUtil.join(outputFiles.asList(), new Function<OutputFile, String>() {
|
||||
@Override
|
||||
public String fun(OutputFile file) {
|
||||
return file.getRelativePath();
|
||||
}
|
||||
}, ", ");
|
||||
assertNotNull("Couldn't find class file for pattern " + classFileRegex + " in: " + pathsString, outputFile);
|
||||
|
||||
ClassReader cr = new ClassReader(outputFile.asByteArray());
|
||||
List<LocalVariable> expectedLocalVariables = parseExpectations();
|
||||
List<LocalVariable> actualLocalVariables = readLocalVariable(cr, methodName);
|
||||
|
||||
assertEquals("Count of variables are different", expectedLocalVariables.size(), actualLocalVariables.size());
|
||||
|
||||
int index = 0;
|
||||
for (LocalVariable expectedVariable : expectedLocalVariables) {
|
||||
LocalVariable actualVariable = actualLocalVariables.get(index);
|
||||
assertEquals("Names are different", expectedVariable.name, actualVariable.name);
|
||||
assertEquals("Types are different for " + expectedVariable.name, expectedVariable.type, actualVariable.type);
|
||||
assertEquals("Indexes are different", expectedVariable.index, actualVariable.index);
|
||||
index++;
|
||||
}
|
||||
|
||||
if (!isClassFound) {
|
||||
throw new AssertionError("file name should be the same as class name. File name is " + modifiedTestName);
|
||||
}
|
||||
|
||||
|
||||
Disposer.dispose(myTestRootDisposable);
|
||||
}
|
||||
|
||||
|
||||
@@ -152,17 +162,17 @@ public abstract class AbstractCheckLocalVariablesTableTest extends TestCaseWithT
|
||||
}
|
||||
}
|
||||
|
||||
private String parseMethodName() throws IOException {
|
||||
@NotNull
|
||||
private String parseClassAndMethodSignature() throws IOException {
|
||||
List<String> lines = Files.readLines(ktFile, Charset.forName("utf-8"));
|
||||
for (int i = 0; i < lines.size(); ++i) {
|
||||
Matcher methodMatcher = methodPattern.matcher(lines.get(i));
|
||||
for (String line : lines) {
|
||||
Matcher methodMatcher = methodPattern.matcher(line);
|
||||
if (methodMatcher.matches()) {
|
||||
return methodMatcher.group(1);
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue("method instructions not found", false);
|
||||
return null;
|
||||
throw new AssertionError("method instructions not found");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+15
-15
@@ -36,29 +36,29 @@ public class CheckLocalVariablesTableTestGenerated extends AbstractCheckLocalVar
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/checkLocalVariablesTable"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("someClass.kt")
|
||||
public void testSomeClass() throws Exception {
|
||||
doTest("compiler/testData/checkLocalVariablesTable/someClass.kt");
|
||||
@TestMetadata("copyFunction.kt")
|
||||
public void testCopyFunction() throws Exception {
|
||||
doTest("compiler/testData/checkLocalVariablesTable/copyFunction.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("_DefaultPackage$foo$1.kt")
|
||||
public void test_DefaultPackage$foo$1() throws Exception {
|
||||
doTest("compiler/testData/checkLocalVariablesTable/_DefaultPackage$foo$1.kt");
|
||||
@TestMetadata("itInLambda.kt")
|
||||
public void testItInLambda() throws Exception {
|
||||
doTest("compiler/testData/checkLocalVariablesTable/itInLambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("_DefaultPackage$foo$1$1.kt")
|
||||
public void test_DefaultPackage$foo$1$1() throws Exception {
|
||||
doTest("compiler/testData/checkLocalVariablesTable/_DefaultPackage$foo$1$1.kt");
|
||||
@TestMetadata("itInReturnedLambda.kt")
|
||||
public void testItInReturnedLambda() throws Exception {
|
||||
doTest("compiler/testData/checkLocalVariablesTable/itInReturnedLambda.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("_DefaultPackage$foo$a$1.kt")
|
||||
public void test_DefaultPackage$foo$a$1() throws Exception {
|
||||
doTest("compiler/testData/checkLocalVariablesTable/_DefaultPackage$foo$a$1.kt");
|
||||
@TestMetadata("lambdaAsVar.kt")
|
||||
public void testLambdaAsVar() throws Exception {
|
||||
doTest("compiler/testData/checkLocalVariablesTable/lambdaAsVar.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("_DefaultPackage$foo1$1.kt")
|
||||
public void test_DefaultPackage$foo1$1() throws Exception {
|
||||
doTest("compiler/testData/checkLocalVariablesTable/_DefaultPackage$foo1$1.kt");
|
||||
@TestMetadata("localFun.kt")
|
||||
public void testLocalFun() throws Exception {
|
||||
doTest("compiler/testData/checkLocalVariablesTable/localFun.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user