testing stdlib as part of the build
This commit is contained in:
@@ -118,7 +118,7 @@ public class CodegenUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void addSuperTypes(JetType type, Set<JetType> set) {
|
||||
public static void addSuperTypes(JetType type, Set<JetType> set) {
|
||||
set.add(type);
|
||||
|
||||
for (JetType jetType : type.getConstructor().getSupertypes()) {
|
||||
|
||||
@@ -30,6 +30,11 @@ public class CompileSession {
|
||||
private final List<JetFile> mySourceFiles = new ArrayList<JetFile>();
|
||||
private final List<JetFile> myLibrarySourceFiles = new ArrayList<JetFile>();
|
||||
private List<String> myErrors = new ArrayList<String>();
|
||||
|
||||
public BindingContext getMyBindingContext() {
|
||||
return myBindingContext;
|
||||
}
|
||||
|
||||
private BindingContext myBindingContext;
|
||||
|
||||
public CompileSession(JetCoreEnvironment environment) {
|
||||
|
||||
@@ -1,9 +1,36 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
import com.intellij.openapi.util.ClassLoaderUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.local.CoreLocalFileSystem;
|
||||
import com.intellij.testFramework.TestRunnerUtil;
|
||||
import gnu.trove.THashSet;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestResult;
|
||||
import junit.framework.TestSuite;
|
||||
import junit.textui.TestRunner;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.compiler.CompileEnvironment;
|
||||
import org.jetbrains.jet.compiler.CompileSession;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||
|
||||
import java.beans.beancontext.BeanContext;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author alex.tkachman
|
||||
@@ -84,4 +111,82 @@ public class StdlibTest extends CodegenTestCase {
|
||||
public void testKt274 () {
|
||||
// blackBoxFile("regressions/kt274.kt");
|
||||
}
|
||||
|
||||
public void testTestlib () {
|
||||
try {
|
||||
CompileSession session = new CompileSession(myEnvironment);
|
||||
CompileEnvironment.initializeKotlinRuntime(myEnvironment);
|
||||
URLClassLoader classLoader = (URLClassLoader) TestCase.class.getClassLoader();
|
||||
CoreLocalFileSystem localFileSystem = myEnvironment.getLocalFileSystem();
|
||||
for(URL url: classLoader.getURLs()) {
|
||||
if(url.getProtocol().equals("file") && url.getPath().contains("junit")) {
|
||||
File file = new File(URLDecoder.decode(url.getPath()));
|
||||
if(file.exists()) {
|
||||
myEnvironment.addToClasspath(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
VirtualFile path = localFileSystem.findFileByPath(JetParsingTest.getTestDataDir() + "/../../testlib/test");
|
||||
session.addSources(path);
|
||||
session.addStdLibSources(true);
|
||||
|
||||
if (!session.analyze(System.out)) {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
|
||||
ClassFileFactory classFileFactory = session.generate();
|
||||
GeneratedClassLoader loader = new GeneratedClassLoader(classFileFactory);
|
||||
|
||||
JetTypeMapper typeMapper = new JetTypeMapper(classFileFactory.state.getStandardLibrary(), session.getMyBindingContext());
|
||||
TestSuite suite = new TestSuite("StandardLibrary");
|
||||
try {
|
||||
for(JetFile jetFile : session.getSourceFileNamespaces()) {
|
||||
for(JetDeclaration decl : jetFile.getDeclarations()) {
|
||||
if(decl instanceof JetClass) {
|
||||
JetClass jetClass = (JetClass) decl;
|
||||
|
||||
ClassDescriptor descriptor = (ClassDescriptor) session.getMyBindingContext().get(BindingContext.DECLARATION_TO_DESCRIPTOR, jetClass);
|
||||
Set<JetType> allSuperTypes = new THashSet<JetType>();
|
||||
CodegenUtil.addSuperTypes(descriptor.getDefaultType(), allSuperTypes);
|
||||
|
||||
for(JetType type : allSuperTypes) {
|
||||
String internalName = typeMapper.mapType(type).getInternalName();
|
||||
if(internalName.equals("junit/framework/Test")) {
|
||||
String name = typeMapper.mapType(descriptor.getDefaultType()).getInternalName();
|
||||
System.out.println(name);
|
||||
Class<TestCase> aClass = (Class<TestCase>) loader.loadClass(name.replace('/', '.'));
|
||||
if((aClass.getModifiers() & Modifier.ABSTRACT) == 0
|
||||
&& (aClass.getModifiers() & Modifier.PUBLIC) != 0) {
|
||||
try {
|
||||
Constructor<TestCase> constructor = aClass.getConstructor();
|
||||
if(constructor != null && (constructor.getModifiers() & Modifier.PUBLIC) != 0) {
|
||||
suite.addTestSuite(aClass);
|
||||
}
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
typeMapper = null;
|
||||
}
|
||||
|
||||
TestResult testResult = TestRunner.run(suite);
|
||||
assertEquals(0, testResult.errorCount());
|
||||
assertEquals(0, testResult.failureCount());
|
||||
|
||||
|
||||
} catch (RuntimeException e) {
|
||||
System.out.println(generateToText());
|
||||
throw e;
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.junit.runner.*
|
||||
import org.junit.runner.notification.*
|
||||
import junit.framework.*
|
||||
|
||||
class BuiltTest<T>(name: String, val builder: TestBuilder<T>, val test: BuiltTest<T>.() -> Unit) : TestCase(name) {
|
||||
protected class BuiltTest<T>(name: String, val builder: TestBuilder<T>, val test: BuiltTest<T>.() -> Unit) : TestCase(name) {
|
||||
private var myState: T? = null
|
||||
|
||||
var state : T
|
||||
|
||||
Reference in New Issue
Block a user