Move blackBox() methods to AbstractBlackBoxCodegenTest
This commit is contained in:
committed by
Alexander Udalov
parent
b485c7ae26
commit
fe96a0172d
@@ -22,10 +22,8 @@ import com.intellij.testFramework.UsefulTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.ConfigurationKind;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.TestJdkKind;
|
||||
import org.jetbrains.jet.cli.jvm.JVMConfigurationKeys;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||
@@ -36,7 +34,6 @@ import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.codegen.CodegenTestUtil.*;
|
||||
@@ -96,14 +93,6 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
||||
myFiles = CodegenTestFiles.create(myEnvironment.getProject(), names);
|
||||
}
|
||||
|
||||
protected void loadFilesByFullPath(@NotNull String... fullNames) {
|
||||
String[] names = new String[fullNames.length];
|
||||
for (int i = 0; i < fullNames.length; i++) {
|
||||
names[i] = fullNames[i].substring("compiler/testData/codegen/".length());
|
||||
}
|
||||
loadFiles(names);
|
||||
}
|
||||
|
||||
protected void loadFile() {
|
||||
loadFile(getPrefix() + "/" + getTestName(true) + ".kt");
|
||||
}
|
||||
@@ -113,53 +102,6 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
protected void blackBoxFileByFullPath(@NotNull String filename) {
|
||||
loadFileByFullPath(filename);
|
||||
blackBox();
|
||||
}
|
||||
|
||||
protected void blackBoxMultiFile(@NotNull String... filenames) {
|
||||
loadFiles(filenames);
|
||||
blackBox();
|
||||
}
|
||||
|
||||
protected void blackBoxMultiFileByFullPath(@NotNull String... filenames) {
|
||||
loadFilesByFullPath(filenames);
|
||||
blackBox();
|
||||
}
|
||||
|
||||
private void blackBox() {
|
||||
ClassFileFactory factory = generateClassesInFile();
|
||||
GeneratedClassLoader loader = createClassLoader(factory);
|
||||
|
||||
JetFile firstFile = myFiles.getPsiFiles().get(0);
|
||||
String fqName = NamespaceCodegen.getJVMClassNameForKotlinNs(JetPsiUtil.getFQName(firstFile)).getFqName().getFqName();
|
||||
|
||||
try {
|
||||
Class<?> namespaceClass = loader.loadClass(fqName);
|
||||
Method method = namespaceClass.getMethod("box");
|
||||
|
||||
String r = (String) method.invoke(null);
|
||||
assertEquals("OK", r);
|
||||
} catch (Throwable e) {
|
||||
System.out.println(generateToText());
|
||||
ExceptionUtils.rethrow(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void blackBoxFileWithJavaByFullPath(@NotNull String ktFile) {
|
||||
blackBoxFileWithJava(ktFile.substring("compiler/testData/codegen/".length()));
|
||||
}
|
||||
|
||||
protected void blackBoxFileWithJava(@NotNull String ktFile) {
|
||||
File javaClassesTempDirectory = CodegenTestUtil.compileJava(ktFile.replaceFirst("\\.kt$", ".java"));
|
||||
|
||||
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
||||
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), javaClassesTempDirectory));
|
||||
|
||||
blackBoxMultiFile(ktFile);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected GeneratedClassLoader createClassLoader(@NotNull ClassFileFactory factory) {
|
||||
if (initializedClassLoader != null) {
|
||||
|
||||
+51
-2
@@ -21,12 +21,23 @@ import com.intellij.util.Processor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.ConfigurationKind;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.TestJdkKind;
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
|
||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||
import org.jetbrains.jet.codegen.CodegenTestCase;
|
||||
import org.jetbrains.jet.codegen.GeneratedClassLoader;
|
||||
import org.jetbrains.jet.codegen.NamespaceCodegen;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.utils.ExceptionUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.codegen.CodegenTestUtil.compileJava;
|
||||
|
||||
public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
|
||||
public void doTest(@NotNull String filename) {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||
@@ -51,12 +62,50 @@ public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
|
||||
@Override
|
||||
public boolean process(File file) {
|
||||
if (file.getName().endsWith(".kt")) {
|
||||
files.add(file.getPath());
|
||||
files.add(file.getPath().substring("compiler/testData/codegen/".length()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
blackBoxMultiFileByFullPath(files.toArray(new String[files.size()]));
|
||||
loadFiles(files.toArray(new String[files.size()]));
|
||||
blackBox();
|
||||
}
|
||||
|
||||
|
||||
private void blackBoxFileWithJavaByFullPath(@NotNull String ktFileFullPath) {
|
||||
String ktFile = ktFileFullPath.substring("compiler/testData/codegen/".length());
|
||||
File javaClassesTempDirectory = compileJava(ktFile.replaceFirst("\\.kt$", ".java"));
|
||||
|
||||
myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests(
|
||||
ConfigurationKind.JDK_ONLY, TestJdkKind.MOCK_JDK, JetTestUtils.getAnnotationsJar(), javaClassesTempDirectory));
|
||||
|
||||
loadFile(ktFile);
|
||||
blackBox();
|
||||
}
|
||||
|
||||
private void blackBoxFileByFullPath(@NotNull String filename) {
|
||||
loadFileByFullPath(filename);
|
||||
blackBox();
|
||||
}
|
||||
|
||||
private void blackBox() {
|
||||
ClassFileFactory factory = generateClassesInFile();
|
||||
GeneratedClassLoader loader = createClassLoader(factory);
|
||||
|
||||
// If there are many files, the first of them should contain the 'box(): String' function
|
||||
JetFile firstFile = myFiles.getPsiFiles().get(0);
|
||||
String fqName = NamespaceCodegen.getJVMClassNameForKotlinNs(JetPsiUtil.getFQName(firstFile)).getFqName().getFqName();
|
||||
|
||||
try {
|
||||
Class<?> namespaceClass = loader.loadClass(fqName);
|
||||
Method method = namespaceClass.getMethod("box");
|
||||
|
||||
String r = (String) method.invoke(null);
|
||||
assertEquals("OK", r);
|
||||
} catch (Throwable e) {
|
||||
System.out.println(generateToText());
|
||||
ExceptionUtils.rethrow(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user