Merge branch 'master' of ssh://git.labs.intellij.net/jet
This commit is contained in:
@@ -16,7 +16,7 @@ import java.util.List;
|
||||
* @author abreslav
|
||||
*/
|
||||
public abstract class JetTestCaseBuilder {
|
||||
private static FilenameFilter emptyFilter = new FilenameFilter() {
|
||||
public static FilenameFilter emptyFilter = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File file, String name) {
|
||||
return true;
|
||||
@@ -43,6 +43,11 @@ public abstract class JetTestCaseBuilder {
|
||||
@NotNull
|
||||
public static TestSuite suiteForDirectory(String baseDataDir, @NotNull final String dataPath, boolean recursive, final FilenameFilter filter, @NotNull NamedTestFactory factory) {
|
||||
TestSuite suite = new TestSuite(dataPath);
|
||||
appendTestsInDirectory(baseDataDir, dataPath, recursive, filter, factory, suite);
|
||||
return suite;
|
||||
}
|
||||
|
||||
public static void appendTestsInDirectory(String baseDataDir, String dataPath, boolean recursive, final FilenameFilter filter, NamedTestFactory factory, TestSuite suite) {
|
||||
final String extensionJet = ".jet";
|
||||
final String extensionKt = ".kt";
|
||||
final FilenameFilter extensionFilter = new FilenameFilter() {
|
||||
@@ -76,7 +81,7 @@ public abstract class JetTestCaseBuilder {
|
||||
List<File> subdirs = Arrays.asList(files);
|
||||
Collections.sort(subdirs);
|
||||
for (File subdir : subdirs) {
|
||||
suite.addTest(suiteForDirectory(baseDataDir, dataPath + "/" + subdir.getName(), recursive, filter, factory));
|
||||
appendTestsInDirectory(baseDataDir, dataPath + "/" + subdir.getName(), recursive, filter, factory, suite);
|
||||
}
|
||||
}
|
||||
List<File> files = Arrays.asList(dir.listFiles(resultFilter));
|
||||
@@ -87,6 +92,5 @@ public abstract class JetTestCaseBuilder {
|
||||
String extension = fileName.endsWith(extensionJet) ? extensionJet : extensionKt;
|
||||
suite.addTest(factory.createTest(dataPath, fileName.substring(0, fileName.length() - extension.length())));
|
||||
}
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public abstract class CodegenTestCase extends JetLiteFixture {
|
||||
}
|
||||
|
||||
protected String generateToText() {
|
||||
GenerationState state = new GenerationState(getProject(), true);
|
||||
GenerationState state = new GenerationState(getProject(), ClassBuilderFactory.TEXT);
|
||||
AnalyzingUtils.checkForSyntacticErrors(myFile);
|
||||
state.compile(myFile);
|
||||
|
||||
@@ -152,7 +152,7 @@ public abstract class CodegenTestCase extends JetLiteFixture {
|
||||
|
||||
protected ClassFileFactory generateClassesInFile() {
|
||||
try {
|
||||
GenerationState state = new GenerationState(getProject(), false);
|
||||
GenerationState state = new GenerationState(getProject(), ClassBuilderFactory.BINARIES);
|
||||
AnalyzingUtils.checkForSyntacticErrors(myFile);
|
||||
state.compile(myFile);
|
||||
|
||||
|
||||
@@ -80,4 +80,55 @@ public class FunctionGenTest extends CodegenTestCase {
|
||||
public void testKt395 () {
|
||||
blackBoxFile("regressions/kt395.jet");
|
||||
}
|
||||
/*
|
||||
public void testFunction () throws InvocationTargetException, IllegalAccessException {
|
||||
loadText("fun Any.foo() : fun(): String {\n" +
|
||||
" return { \"239\" + this }\n" +
|
||||
"}\n" +
|
||||
"fun box() : String {\n" +
|
||||
" return if((10.foo())() == \"23910\") \"OK\" else \"fail\"" +
|
||||
"}" +
|
||||
"");
|
||||
System.out.println(generateToText());
|
||||
Method foo = generateFunction();
|
||||
assertTrue((Boolean) foo.invoke(null, "lala"));
|
||||
assertFalse((Boolean) foo.invoke(null, "mama"));
|
||||
}
|
||||
|
||||
fun Any.foo() : fun() : Unit {
|
||||
return {}
|
||||
}
|
||||
|
||||
fun Any.foo1() : fun(i : Int) : Unit {
|
||||
return {}
|
||||
}
|
||||
|
||||
fun foo2() : fun(i : fun()) : Unit {
|
||||
return {}
|
||||
}
|
||||
|
||||
fun fooT1<T>(t : T) : fun() : T {
|
||||
return {t}
|
||||
}
|
||||
|
||||
fun fooT2<T>() : fun(t : T) : T {
|
||||
return {it}
|
||||
}
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
args.foo()()
|
||||
|
||||
args.foo1()(1)
|
||||
|
||||
foo2()({})
|
||||
(foo2()){}
|
||||
|
||||
val a = fooT1(1)()
|
||||
a : Int
|
||||
|
||||
val b = fooT2<Int>()(1)
|
||||
b : Int
|
||||
fooT2()(1) // : Any?
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.jetbrains.jet.codegen;
|
||||
|
||||
public class SuperGenTest extends CodegenTestCase {
|
||||
public void testBasicProperty () {
|
||||
blackBoxFile("/super/basicproperty.jet");
|
||||
System.out.println(generateToText());
|
||||
}
|
||||
|
||||
public void testTraitProperty () {
|
||||
blackBoxFile("/super/traitproperty.jet");
|
||||
System.out.println(generateToText());
|
||||
}
|
||||
|
||||
public void testBasicMethod () {
|
||||
blackBoxFile("/super/basicmethod.jet");
|
||||
System.out.println(generateToText());
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,15 @@ import junit.framework.TestCase;
|
||||
import org.jetbrains.jet.codegen.ClassFileFactory;
|
||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarInputStream;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
@@ -23,8 +32,9 @@ public class CompileEnvironmentTest extends TestCase {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testSmoke() {
|
||||
environment.setJavaRuntime(CompileEnvironment.findActiveRtJar());
|
||||
public void testSmoke() throws IOException {
|
||||
final File activeRtJar = CompileEnvironment.findRtJar(true);
|
||||
environment.setJavaRuntime(activeRtJar);
|
||||
environment.initializeKotlinRuntime();
|
||||
final String testDataDir = JetParsingTest.getTestDataDir() + "/compiler/smoke/";
|
||||
final IModuleSetBuilder setBuilder = environment.loadModuleScript(testDataDir + "Smoke.kts");
|
||||
@@ -33,5 +43,23 @@ public class CompileEnvironmentTest extends TestCase {
|
||||
final ClassFileFactory factory = environment.compileModule(moduleBuilder, testDataDir);
|
||||
assertNotNull(factory);
|
||||
assertNotNull(factory.asBytes("Smoke/namespace.class"));
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
CompileEnvironment.writeToJar(factory, baos, null, false);
|
||||
JarInputStream is = new JarInputStream(new ByteArrayInputStream(baos.toByteArray()));
|
||||
final List<String> entries = listEntries(is);
|
||||
assertTrue(entries.contains("Smoke/namespace.class"));
|
||||
}
|
||||
|
||||
private List<String> listEntries(JarInputStream is) throws IOException {
|
||||
List<String> entries = new ArrayList<String>();
|
||||
while (true) {
|
||||
final JarEntry jarEntry = is.getNextJarEntry();
|
||||
if (jarEntry == null) {
|
||||
break;
|
||||
}
|
||||
entries.add(jarEntry.getName());
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user