testing stdlib as part of the build. separate class
This commit is contained in:
@@ -111,82 +111,4 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user