Revert "refactor tests". I've broken tests again.
This reverts commit 8db2617701.
This commit is contained in:
@@ -16,8 +16,10 @@ import org.jetbrains.jet.codegen.ClassBuilderFactory;
|
|||||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||||
import org.jetbrains.jet.codegen.GenerationState;
|
import org.jetbrains.jet.codegen.GenerationState;
|
||||||
import org.jetbrains.jet.compiler.CompileEnvironment;
|
import org.jetbrains.jet.compiler.CompileEnvironment;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||||
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.plugin.JetLanguage;
|
import org.jetbrains.jet.plugin.JetLanguage;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
@@ -26,6 +28,7 @@ import javax.tools.JavaFileObject;
|
|||||||
import javax.tools.StandardJavaFileManager;
|
import javax.tools.StandardJavaFileManager;
|
||||||
import javax.tools.ToolProvider;
|
import javax.tools.ToolProvider;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -48,6 +51,35 @@ public class CompileJavaAgainstKotlinTest extends UsefulTestCase {
|
|||||||
this.javaFile = new File(ktFile.getPath().replaceFirst("\\.kt", ".java"));
|
this.javaFile = new File(ktFile.getPath().replaceFirst("\\.kt", ".java"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void createMockCoreEnvironment() {
|
||||||
|
jetCoreEnvironment = new JetCoreEnvironment(myTestRootDisposable);
|
||||||
|
|
||||||
|
final File rtJar = new File(JetTestCaseBuilder.getHomeDirectory(), "compiler/testData/mockJDK-1.7/jre/lib/rt.jar");
|
||||||
|
jetCoreEnvironment.addToClasspath(rtJar);
|
||||||
|
jetCoreEnvironment.addToClasspath(new File(JetTestCaseBuilder.getHomeDirectory(), "compiler/testData/mockJDK-1.7/jre/lib/annotations.jar"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mkdirs(File file) throws IOException {
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!file.mkdirs()) {
|
||||||
|
throw new IOException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void rmrf(File file) {
|
||||||
|
if (file != null) {
|
||||||
|
File[] children = file.listFiles();
|
||||||
|
if (children != null) {
|
||||||
|
for (File child : children) {
|
||||||
|
rmrf(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return ktFile.getName();
|
return ktFile.getName();
|
||||||
@@ -57,20 +89,26 @@ public class CompileJavaAgainstKotlinTest extends UsefulTestCase {
|
|||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
tmpdir = new File("tmp/" + this.getClass().getSimpleName() + "." + this.getName());
|
tmpdir = new File("tmp/" + this.getClass().getSimpleName() + "." + this.getName());
|
||||||
JetTestUtils.recreateDirectory(tmpdir);
|
rmrf(tmpdir);
|
||||||
|
mkdirs(tmpdir);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
Disposer.dispose(myTestRootDisposable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void runTest() throws Throwable {
|
protected void runTest() throws Throwable {
|
||||||
jetCoreEnvironment = JetTestUtils.createEnvironmentWithMockJdk(myTestRootDisposable);
|
createMockCoreEnvironment();
|
||||||
|
|
||||||
LanguageASTFactory.INSTANCE.addExplicitExtension(JavaLanguage.INSTANCE, new JavaASTFactory());
|
LanguageASTFactory.INSTANCE.addExplicitExtension(JavaLanguage.INSTANCE, new JavaASTFactory());
|
||||||
|
|
||||||
|
|
||||||
String text = FileUtil.loadFile(ktFile);
|
String text = FileUtil.loadFile(ktFile);
|
||||||
|
|
||||||
LightVirtualFile virtualFile = new LightVirtualFile(ktFile.getName(), JetLanguage.INSTANCE, text);
|
LightVirtualFile virtualFile = new LightVirtualFile("Hello.kt", JetLanguage.INSTANCE, text);
|
||||||
virtualFile.setCharset(CharsetToolkit.UTF8_CHARSET);
|
virtualFile.setCharset(CharsetToolkit.UTF8_CHARSET);
|
||||||
JetFile psiFile = (JetFile) ((PsiFileFactoryImpl) PsiFileFactory.getInstance(jetCoreEnvironment.getProject())).trySetupPsiForFile(virtualFile, JetLanguage.INSTANCE, true, false);
|
JetFile psiFile = (JetFile) ((PsiFileFactoryImpl) PsiFileFactory.getInstance(jetCoreEnvironment.getProject())).trySetupPsiForFile(virtualFile, JetLanguage.INSTANCE, true, false);
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,10 @@ public abstract class JetLiteFixture extends UsefulTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void createEnvironmentWithMockJdk() {
|
protected void createEnvironmentWithMockJdk() {
|
||||||
myEnvironment = JetTestUtils.createEnvironmentWithMockJdk(getTestRootDisposable());
|
myEnvironment = new JetCoreEnvironment(getTestRootDisposable());
|
||||||
|
final File rtJar = new File(JetTestCaseBuilder.getHomeDirectory(), "compiler/testData/mockJDK-1.7/jre/lib/rt.jar");
|
||||||
|
myEnvironment.addToClasspath(rtJar);
|
||||||
|
myEnvironment.addToClasspath(new File(JetTestCaseBuilder.getHomeDirectory(), "compiler/testData/mockJDK-1.7/jre/lib/annotations.jar"));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void createEnvironmentWithFullJdk() {
|
protected void createEnvironmentWithFullJdk() {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package org.jetbrains.jet;
|
package org.jetbrains.jet;
|
||||||
|
|
||||||
import com.intellij.openapi.Disposable;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||||
@@ -14,8 +13,6 @@ import org.jetbrains.jet.util.slicedmap.ReadOnlySlice;
|
|||||||
import org.jetbrains.jet.util.slicedmap.SlicedMap;
|
import org.jetbrains.jet.util.slicedmap.SlicedMap;
|
||||||
import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
@@ -131,40 +128,4 @@ public class JetTestUtils {
|
|||||||
public static BindingContext analyzeNamespace(@NotNull JetNamespace namespace, @NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
public static BindingContext analyzeNamespace(@NotNull JetNamespace namespace, @NotNull JetControlFlowDataTraceFactory flowDataTraceFactory) {
|
||||||
return AnalyzerFacade.analyzeOneNamespaceWithJavaIntegration(namespace, flowDataTraceFactory);
|
return AnalyzerFacade.analyzeOneNamespaceWithJavaIntegration(namespace, flowDataTraceFactory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static JetCoreEnvironment createEnvironmentWithMockJdk(Disposable disposable) {
|
|
||||||
JetCoreEnvironment environment = new JetCoreEnvironment(disposable);
|
|
||||||
final File rtJar = new File(JetTestCaseBuilder.getHomeDirectory(), "compiler/testData/mockJDK-1.7/jre/lib/rt.jar");
|
|
||||||
environment.addToClasspath(rtJar);
|
|
||||||
environment.addToClasspath(new File(JetTestCaseBuilder.getHomeDirectory(), "compiler/testData/mockJDK-1.7/jre/lib/annotations.jar"));
|
|
||||||
return environment;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static void mkdirs(File file) throws IOException {
|
|
||||||
if (file.isDirectory()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!file.mkdirs()) {
|
|
||||||
throw new IOException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void rmrf(File file) {
|
|
||||||
if (file != null) {
|
|
||||||
File[] children = file.listFiles();
|
|
||||||
if (children != null) {
|
|
||||||
for (File child : children) {
|
|
||||||
rmrf(child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
file.delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void recreateDirectory(File dir) throws IOException {
|
|
||||||
rmrf(dir);
|
|
||||||
mkdirs(dir);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.jetbrains.jet;
|
package org.jetbrains.jet;
|
||||||
|
|
||||||
|
import com.intellij.lang.ASTFactory;
|
||||||
import com.intellij.lang.LanguageASTFactory;
|
import com.intellij.lang.LanguageASTFactory;
|
||||||
import com.intellij.lang.java.JavaLanguage;
|
import com.intellij.lang.java.JavaLanguage;
|
||||||
import com.intellij.openapi.Disposable;
|
import com.intellij.openapi.Disposable;
|
||||||
@@ -34,7 +35,9 @@ import org.jetbrains.jet.plugin.JetLanguage;
|
|||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -62,20 +65,54 @@ public class ReadClassDataTest extends UsefulTestCase {
|
|||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
tmpdir = new File("tmp/" + this.getClass().getSimpleName() + "." + this.getName());
|
tmpdir = new File("tmp/" + this.getClass().getSimpleName() + "." + this.getName());
|
||||||
JetTestUtils.recreateDirectory(tmpdir);
|
rmrf(tmpdir);
|
||||||
|
mkdirs(tmpdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
Disposer.dispose(myTestRootDisposable);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mkdirs(File file) throws IOException {
|
||||||
|
if (file.isDirectory()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!file.mkdirs()) {
|
||||||
|
throw new IOException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void rmrf(File file) {
|
||||||
|
if (file != null) {
|
||||||
|
File[] children = file.listFiles();
|
||||||
|
if (children != null) {
|
||||||
|
for (File child : children) {
|
||||||
|
rmrf(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createMockCoreEnvironment() {
|
||||||
|
jetCoreEnvironment = new JetCoreEnvironment(myTestRootDisposable);
|
||||||
|
|
||||||
|
final File rtJar = new File(JetTestCaseBuilder.getHomeDirectory(), "compiler/testData/mockJDK-1.7/jre/lib/rt.jar");
|
||||||
|
jetCoreEnvironment.addToClasspath(rtJar);
|
||||||
|
jetCoreEnvironment.addToClasspath(new File(JetTestCaseBuilder.getHomeDirectory(), "compiler/testData/mockJDK-1.7/jre/lib/annotations.jar"));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void runTest() throws Exception {
|
public void runTest() throws Exception {
|
||||||
jetCoreEnvironment = JetTestUtils.createEnvironmentWithMockJdk(myTestRootDisposable);
|
createMockCoreEnvironment();
|
||||||
|
|
||||||
LanguageASTFactory.INSTANCE.addExplicitExtension(JavaLanguage.INSTANCE, new JavaASTFactory());
|
LanguageASTFactory.INSTANCE.addExplicitExtension(JavaLanguage.INSTANCE, new JavaASTFactory());
|
||||||
|
|
||||||
|
|
||||||
String text = FileUtil.loadFile(testFile);
|
String text = FileUtil.loadFile(testFile);
|
||||||
|
|
||||||
LightVirtualFile virtualFile = new LightVirtualFile(testFile.getName(), JetLanguage.INSTANCE, text);
|
LightVirtualFile virtualFile = new LightVirtualFile("Hello.kt", JetLanguage.INSTANCE, text);
|
||||||
virtualFile.setCharset(CharsetToolkit.UTF8_CHARSET);
|
virtualFile.setCharset(CharsetToolkit.UTF8_CHARSET);
|
||||||
JetFile psiFile = (JetFile) ((PsiFileFactoryImpl) PsiFileFactory.getInstance(jetCoreEnvironment.getProject())).trySetupPsiForFile(virtualFile, JetLanguage.INSTANCE, true, false);
|
JetFile psiFile = (JetFile) ((PsiFileFactoryImpl) PsiFileFactory.getInstance(jetCoreEnvironment.getProject())).trySetupPsiForFile(virtualFile, JetLanguage.INSTANCE, true, false);
|
||||||
|
|
||||||
@@ -92,10 +129,11 @@ public class ReadClassDataTest extends UsefulTestCase {
|
|||||||
Assert.assertEquals("test", namespaceFromSource.getName());
|
Assert.assertEquals("test", namespaceFromSource.getName());
|
||||||
|
|
||||||
Disposer.dispose(myTestRootDisposable);
|
Disposer.dispose(myTestRootDisposable);
|
||||||
|
|
||||||
|
|
||||||
jetCoreEnvironment = JetTestUtils.createEnvironmentWithMockJdk(myTestRootDisposable);
|
|
||||||
|
createMockCoreEnvironment();
|
||||||
|
|
||||||
jetCoreEnvironment.addToClasspath(tmpdir);
|
jetCoreEnvironment.addToClasspath(tmpdir);
|
||||||
|
|
||||||
JetSemanticServices jetSemanticServices = JetSemanticServices.createSemanticServices(jetCoreEnvironment.getProject());
|
JetSemanticServices jetSemanticServices = JetSemanticServices.createSemanticServices(jetCoreEnvironment.getProject());
|
||||||
|
|||||||
Reference in New Issue
Block a user