Migrate AbstractLineNumberTest to CodegenTestCase stuff
This commit is contained in:
+17
-60
@@ -17,90 +17,55 @@
|
|||||||
package org.jetbrains.kotlin.codegen;
|
package org.jetbrains.kotlin.codegen;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
import kotlin.Pair;
|
|
||||||
import kotlin.collections.CollectionsKt;
|
import kotlin.collections.CollectionsKt;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.backend.common.output.OutputFile;
|
import org.jetbrains.kotlin.backend.common.output.OutputFile;
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
|
||||||
import org.jetbrains.kotlin.psi.KtFile;
|
import org.jetbrains.kotlin.psi.KtFile;
|
||||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||||
import org.jetbrains.kotlin.test.TestCaseWithTmpdir;
|
|
||||||
import org.jetbrains.kotlin.test.TestJdkKind;
|
|
||||||
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
|
import org.jetbrains.kotlin.utils.ExceptionUtilsKt;
|
||||||
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.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public abstract class AbstractLineNumberTest extends TestCaseWithTmpdir {
|
public abstract class AbstractLineNumberTest extends CodegenTestCase {
|
||||||
private static final String LINE_NUMBER_FUN = "lineNumber";
|
private static final String LINE_NUMBER_FUN = "lineNumber";
|
||||||
private static final Pattern TEST_LINE_NUMBER_PATTERN = Pattern.compile("^.*test." + LINE_NUMBER_FUN + "\\(\\).*$");
|
private static final Pattern TEST_LINE_NUMBER_PATTERN = Pattern.compile("^.*test." + LINE_NUMBER_FUN + "\\(\\).*$");
|
||||||
|
|
||||||
@NotNull
|
private static TestFile createLineNumberDeclaration() {
|
||||||
private KotlinCoreEnvironment createEnvironment() {
|
return new TestFile(
|
||||||
return KotlinCoreEnvironment.createForTests(
|
LINE_NUMBER_FUN + ".kt",
|
||||||
myTestRootDisposable,
|
"package test;\n\npublic fun " + LINE_NUMBER_FUN + "(): Int = 0\n"
|
||||||
KotlinTestUtils.newConfiguration(
|
|
||||||
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, KotlinTestUtils.getAnnotationsJar(), tmpdir
|
|
||||||
),
|
|
||||||
EnvironmentConfigFiles.JVM_CONFIG_FILES
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setUp() throws Exception {
|
protected void doMultiFileTest(
|
||||||
super.setUp();
|
@NotNull File wholeFile, @NotNull List<TestFile> files, @Nullable File javaFilesDir
|
||||||
|
) {
|
||||||
KotlinCoreEnvironment environment = createEnvironment();
|
boolean isCustomTest = wholeFile.getParentFile().getName().equalsIgnoreCase("custom");
|
||||||
KtFile psiFile = KotlinTestUtils.createFile(
|
if (!isCustomTest) {
|
||||||
LINE_NUMBER_FUN + ".kt",
|
files.add(createLineNumberDeclaration());
|
||||||
"package test;\n\npublic fun " + LINE_NUMBER_FUN + "(): Int = 0\n",
|
|
||||||
environment.getProject()
|
|
||||||
);
|
|
||||||
|
|
||||||
GenerationUtils.compileFileTo(psiFile, environment, tmpdir);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private Pair<KtFile, KotlinCoreEnvironment> createPsiFile(@NotNull String filename) {
|
|
||||||
File file = new File(filename);
|
|
||||||
KotlinCoreEnvironment environment = createEnvironment();
|
|
||||||
|
|
||||||
String text;
|
|
||||||
try {
|
|
||||||
text = FileUtil.loadFile(file, true);
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
throw ExceptionUtilsKt.rethrow(e);
|
|
||||||
}
|
}
|
||||||
|
compile(files, javaFilesDir);
|
||||||
|
|
||||||
return new Pair<>(KotlinTestUtils.createFile(file.getName(), text, environment.getProject()), environment);
|
KtFile psiFile = CollectionsKt.single(myFiles.getPsiFiles(), file -> file.getName().equals(wholeFile.getName()));
|
||||||
}
|
|
||||||
|
|
||||||
private void doTest(@NotNull String filename, boolean custom) {
|
|
||||||
Pair<KtFile, KotlinCoreEnvironment> fileAndEnv = createPsiFile(filename);
|
|
||||||
KtFile psiFile = fileAndEnv.getFirst();
|
|
||||||
KotlinCoreEnvironment environment = fileAndEnv.getSecond();
|
|
||||||
|
|
||||||
ClassFileFactory classFileFactory = GenerationUtils.compileFile(psiFile, environment);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (custom) {
|
if (isCustomTest) {
|
||||||
List<String> actualLineNumbers = extractActualLineNumbersFromBytecode(classFileFactory, false);
|
List<String> actualLineNumbers = extractActualLineNumbersFromBytecode(classFileFactory, false);
|
||||||
String text = psiFile.getText();
|
String text = psiFile.getText();
|
||||||
String newFileText = text.substring(0, text.indexOf("// ")) + getActualLineNumbersAsString(actualLineNumbers);
|
String newFileText = text.substring(0, text.indexOf("// ")) + getActualLineNumbersAsString(actualLineNumbers);
|
||||||
KotlinTestUtils.assertEqualsToFile(new File(filename), newFileText);
|
KotlinTestUtils.assertEqualsToFile(wholeFile, newFileText);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
List<String> expectedLineNumbers = extractSelectedLineNumbersFromSource(psiFile);
|
List<String> expectedLineNumbers = extractSelectedLineNumbersFromSource(psiFile);
|
||||||
List<String> actualLineNumbers = extractActualLineNumbersFromBytecode(classFileFactory, true);
|
List<String> actualLineNumbers = extractActualLineNumbersFromBytecode(classFileFactory, true);
|
||||||
|
assertFalse( "Missed 'lineNumbers' calls in test data", expectedLineNumbers.isEmpty());
|
||||||
assertSameElements(actualLineNumbers, expectedLineNumbers);
|
assertSameElements(actualLineNumbers, expectedLineNumbers);
|
||||||
}
|
}
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
@@ -132,14 +97,6 @@ public abstract class AbstractLineNumberTest extends TestCaseWithTmpdir {
|
|||||||
return actualLineNumbers;
|
return actualLineNumbers;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doTest(String path) {
|
|
||||||
doTest(path, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void doTestCustom(String path) {
|
|
||||||
doTest(path, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static List<String> extractSelectedLineNumbersFromSource(@NotNull KtFile file) {
|
private static List<String> extractSelectedLineNumbersFromSource(@NotNull KtFile file) {
|
||||||
String fileContent = file.getText();
|
String fileContent = file.getText();
|
||||||
|
|||||||
+76
-79
@@ -17,104 +17,101 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
|
@TestMetadata("compiler/testData/lineNumber")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
public class LineNumberTestGenerated extends AbstractLineNumberTest {
|
public class LineNumberTestGenerated extends AbstractLineNumberTest {
|
||||||
@TestMetadata("compiler/testData/lineNumber")
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
}
|
||||||
public static class LineNumber extends AbstractLineNumberTest {
|
|
||||||
private void runTest(String testDataFilePath) throws Exception {
|
|
||||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testAllFilesPresentInLineNumber() throws Exception {
|
public void testAllFilesPresentInLineNumber() throws Exception {
|
||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/lineNumber"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, false);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/lineNumber"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("anonymousFunction.kt")
|
@TestMetadata("anonymousFunction.kt")
|
||||||
public void testAnonymousFunction() throws Exception {
|
public void testAnonymousFunction() throws Exception {
|
||||||
runTest("compiler/testData/lineNumber/anonymousFunction.kt");
|
runTest("compiler/testData/lineNumber/anonymousFunction.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("class.kt")
|
@TestMetadata("class.kt")
|
||||||
public void testClass() throws Exception {
|
public void testClass() throws Exception {
|
||||||
runTest("compiler/testData/lineNumber/class.kt");
|
runTest("compiler/testData/lineNumber/class.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("classObject.kt")
|
@TestMetadata("classObject.kt")
|
||||||
public void testClassObject() throws Exception {
|
public void testClassObject() throws Exception {
|
||||||
runTest("compiler/testData/lineNumber/classObject.kt");
|
runTest("compiler/testData/lineNumber/classObject.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("defaultParameter.kt")
|
@TestMetadata("defaultParameter.kt")
|
||||||
public void testDefaultParameter() throws Exception {
|
public void testDefaultParameter() throws Exception {
|
||||||
runTest("compiler/testData/lineNumber/defaultParameter.kt");
|
runTest("compiler/testData/lineNumber/defaultParameter.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("enum.kt")
|
@TestMetadata("enum.kt")
|
||||||
public void testEnum() throws Exception {
|
public void testEnum() throws Exception {
|
||||||
runTest("compiler/testData/lineNumber/enum.kt");
|
runTest("compiler/testData/lineNumber/enum.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("for.kt")
|
@TestMetadata("for.kt")
|
||||||
public void testFor() throws Exception {
|
public void testFor() throws Exception {
|
||||||
runTest("compiler/testData/lineNumber/for.kt");
|
runTest("compiler/testData/lineNumber/for.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("if.kt")
|
@TestMetadata("if.kt")
|
||||||
public void testIf() throws Exception {
|
public void testIf() throws Exception {
|
||||||
runTest("compiler/testData/lineNumber/if.kt");
|
runTest("compiler/testData/lineNumber/if.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("inlineSimpleCall.kt")
|
@TestMetadata("inlineSimpleCall.kt")
|
||||||
public void testInlineSimpleCall() throws Exception {
|
public void testInlineSimpleCall() throws Exception {
|
||||||
runTest("compiler/testData/lineNumber/inlineSimpleCall.kt");
|
runTest("compiler/testData/lineNumber/inlineSimpleCall.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("localFunction.kt")
|
@TestMetadata("localFunction.kt")
|
||||||
public void testLocalFunction() throws Exception {
|
public void testLocalFunction() throws Exception {
|
||||||
runTest("compiler/testData/lineNumber/localFunction.kt");
|
runTest("compiler/testData/lineNumber/localFunction.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("object.kt")
|
@TestMetadata("object.kt")
|
||||||
public void testObject() throws Exception {
|
public void testObject() throws Exception {
|
||||||
runTest("compiler/testData/lineNumber/object.kt");
|
runTest("compiler/testData/lineNumber/object.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("propertyAccessor.kt")
|
@TestMetadata("propertyAccessor.kt")
|
||||||
public void testPropertyAccessor() throws Exception {
|
public void testPropertyAccessor() throws Exception {
|
||||||
runTest("compiler/testData/lineNumber/propertyAccessor.kt");
|
runTest("compiler/testData/lineNumber/propertyAccessor.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("psvm.kt")
|
@TestMetadata("psvm.kt")
|
||||||
public void testPsvm() throws Exception {
|
public void testPsvm() throws Exception {
|
||||||
runTest("compiler/testData/lineNumber/psvm.kt");
|
runTest("compiler/testData/lineNumber/psvm.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("simpleSmap.kt")
|
@TestMetadata("simpleSmap.kt")
|
||||||
public void testSimpleSmap() throws Exception {
|
public void testSimpleSmap() throws Exception {
|
||||||
runTest("compiler/testData/lineNumber/simpleSmap.kt");
|
runTest("compiler/testData/lineNumber/simpleSmap.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("topLevel.kt")
|
@TestMetadata("topLevel.kt")
|
||||||
public void testTopLevel() throws Exception {
|
public void testTopLevel() throws Exception {
|
||||||
runTest("compiler/testData/lineNumber/topLevel.kt");
|
runTest("compiler/testData/lineNumber/topLevel.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("trait.kt")
|
@TestMetadata("trait.kt")
|
||||||
public void testTrait() throws Exception {
|
public void testTrait() throws Exception {
|
||||||
runTest("compiler/testData/lineNumber/trait.kt");
|
runTest("compiler/testData/lineNumber/trait.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("tryCatch.kt")
|
@TestMetadata("tryCatch.kt")
|
||||||
public void testTryCatch() throws Exception {
|
public void testTryCatch() throws Exception {
|
||||||
runTest("compiler/testData/lineNumber/tryCatch.kt");
|
runTest("compiler/testData/lineNumber/tryCatch.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("while.kt")
|
@TestMetadata("while.kt")
|
||||||
public void testWhile() throws Exception {
|
public void testWhile() throws Exception {
|
||||||
runTest("compiler/testData/lineNumber/while.kt");
|
runTest("compiler/testData/lineNumber/while.kt");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/lineNumber/custom")
|
@TestMetadata("compiler/testData/lineNumber/custom")
|
||||||
@@ -122,7 +119,7 @@ public class LineNumberTestGenerated extends AbstractLineNumberTest {
|
|||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
public static class Custom extends AbstractLineNumberTest {
|
public static class Custom extends AbstractLineNumberTest {
|
||||||
private void runTest(String testDataFilePath) throws Exception {
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
KotlinTestUtils.runTest(this::doTestCustom, TargetBackend.ANY, testDataFilePath);
|
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAllFilesPresentInCustom() throws Exception {
|
public void testAllFilesPresentInCustom() throws Exception {
|
||||||
|
|||||||
@@ -336,8 +336,7 @@ fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testClass<AbstractLineNumberTest> {
|
testClass<AbstractLineNumberTest> {
|
||||||
model("lineNumber", recursive = false)
|
model("lineNumber")
|
||||||
model("lineNumber/custom", testMethod = "doTestCustom")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
testClass<AbstractLocalClassProtoTest> {
|
testClass<AbstractLocalClassProtoTest> {
|
||||||
|
|||||||
Reference in New Issue
Block a user