Drop package facades: update compiler tests.

This commit is contained in:
Dmitry Petrov
2015-10-14 14:17:43 +03:00
parent 3502c393fc
commit e7fb7483c5
89 changed files with 167 additions and 192 deletions
@@ -118,8 +118,8 @@ public class KotlinLightClassCoherenceTest extends KotlinAsJavaTestBase {
}
}
public void testPackage() throws Exception {
doTest("test.TestPackage");
public void testFileFacade() throws Exception {
doTest("test.PackageKt");
}
public void testNoModifiers() throws Exception {
@@ -163,7 +163,7 @@ public abstract class KotlinLightClassStructureTest extends KotlinAsJavaTestBase
}
public void testPackage() throws Exception {
checkModifiers("test.TestPackage", PUBLIC, FINAL, DEPRECATED);
checkModifiers("test.PackageKt", PUBLIC, FINAL);
}
}
@@ -177,8 +177,8 @@ public abstract class KotlinLightClassStructureTest extends KotlinAsJavaTestBase
assertTrue(findMethodsOfClass("test.C").length == 2);
}
public void testPackageWithErrors() {
assertTrue(findMethodsOfClass("test.TestPackage").length == 1);
public void testFileFacadeWithErrors() {
assertTrue(findMethodsOfClass("test.CodeWithErrorsKt").length == 1);
}
private PsiMethod[] findMethodsOfClass(String qualifiedName) {
@@ -38,14 +38,14 @@ public class CliCommonTest extends CliBaseTest {
public void simple() throws Exception {
executeCompilerCompareOutputJVM();
Assert.assertTrue(new File(tmpdir.getTmpDir(), PackageClassUtils.getPackageClassName(FqName.ROOT) + ".class").isFile());
Assert.assertTrue(new File(tmpdir.getTmpDir(), "SimpleKt.class").isFile());
}
@Test
public void duplicateSources() throws Exception {
executeCompilerCompareOutputJVM();
Assert.assertTrue(new File(tmpdir.getTmpDir(), PackageClassUtils.getPackageClassName(FqName.ROOT) + ".class").isFile());
Assert.assertTrue(new File(tmpdir.getTmpDir(), "SimpleKt.class").isFile());
}
@Test
@@ -44,7 +44,7 @@ public class K2JvmCliTest extends CliBaseTest {
public void nonExistingClassPathAndAnnotationsPath() throws Exception {
executeCompilerCompareOutputJVM();
Assert.assertTrue(new File(tmpdir.getTmpDir(), PackageClassUtils.getPackageClassName(FqName.ROOT) + ".class").isFile());
Assert.assertTrue(new File(tmpdir.getTmpDir(), "SimpleKt.class").isFile());
}
@Test
@@ -103,7 +103,7 @@ public class CompilerDaemonTest : KotlinIntegrationTestBase() {
TestCase.assertTrue("Expecting that compilation 1 ($compileTime1 ms) is at least two times longer than compilation 2 ($compileTime2 ms)",
compileTime1 > compileTime2 * 2)
logFile.delete()
run("hello.run", "-cp", jar, "Hello.HelloPackage")
run("hello.run", "-cp", jar, "Hello.HelloKt")
}
finally {
if (!daemonShotDown)
@@ -51,21 +51,21 @@ public class CompilerSmokeTest extends KotlinIntegrationTestBase {
String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar";
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "hello.kt", "-d", jar));
run("hello.run", "-cp", jar, "Hello.HelloPackage");
run("hello.run", "-cp", jar, "Hello.HelloKt");
}
public void testHelloAppFQMain() throws Exception {
String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar";
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "hello.kt", "-d", jar));
run("hello.run", "-cp", jar, "Hello.HelloPackage");
run("hello.run", "-cp", jar, "Hello.HelloKt");
}
public void testHelloAppVarargMain() throws Exception {
String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar";
assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "hello.kt", "-d", jar));
run("hello.run", "-cp", jar, "Hello.HelloPackage");
run("hello.run", "-cp", jar, "Hello.HelloKt");
}
public void testCompilationFailed() throws Exception {
@@ -49,7 +49,7 @@ public abstract class AbstractCompileKotlinAgainstInlineKotlinTest : AbstractCom
try {
factory1 = compileA(File(files[1]))
factory2 = compileB(File(files[0]))
invokeBox()
invokeBox(files[0])
}
catch (e: Throwable) {
var result = ""
@@ -30,8 +30,7 @@ import org.jetbrains.kotlin.codegen.GenerationUtils;
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
import org.jetbrains.kotlin.config.CompilerConfiguration;
import org.jetbrains.kotlin.load.kotlin.ModuleVisibilityManager;
import org.jetbrains.kotlin.load.kotlin.PackageClassUtils;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils;
import org.jetbrains.kotlin.psi.JetFile;
import org.jetbrains.kotlin.test.ConfigurationKind;
import org.jetbrains.kotlin.test.JetTestUtils;
@@ -59,29 +58,31 @@ public abstract class AbstractCompileKotlinAgainstKotlinTest extends TestCaseWit
public void doTest(@NotNull String fileName) throws Exception {
compileA(new File(fileName));
compileB(new File(fileName.replaceFirst("A\\.kt$", "B.kt")));
invokeMain();
String fileNameB = fileName.replaceFirst("A\\.kt$", "B.kt");
compileB(new File(fileNameB));
invokeMain(fileNameB);
}
private void invokeMain() throws Exception {
Method main = generatedClass().getMethod("main", String[].class);
private void invokeMain(@NotNull String fileName) throws Exception {
Method main = generatedClass(fileName).getMethod("main", String[].class);
main.invoke(null, new Object[] {ArrayUtil.EMPTY_STRING_ARRAY});
}
protected void invokeBox() throws Exception {
Method box = generatedClass().getMethod("box");
protected void invokeBox(@NotNull String fileName) throws Exception {
Method box = generatedClass(fileName).getMethod("box");
String result = (String) box.invoke(null);
assertEquals("OK", result);
}
@NotNull
private Class<?> generatedClass() throws Exception {
private Class<?> generatedClass(@NotNull String fileName) throws Exception {
URLClassLoader classLoader = new URLClassLoader(
new URL[]{ bDir.toURI().toURL(), aDir.toURI().toURL() },
ForTestCompileRuntime.runtimeAndReflectJarClassLoader()
);
return classLoader.loadClass(PackageClassUtils.getPackageClassName(FqName.ROOT));
String fileLastName = new File(fileName).getName();
return classLoader.loadClass(PackagePartClassUtils.getFilePartShortName(fileLastName));
}
protected ClassFileFactory compileA(@NotNull File ktAFile) throws IOException {
@@ -37,7 +37,7 @@ public abstract class AbstractCompileKotlinAgainstMultifileKotlinTest : Abstract
try {
factory1 = compileA(File(files[1]))
factory2 = compileB(File(files[0]))
invokeBox()
invokeBox(files[0])
}
catch (e: Throwable) {
var result = ""
@@ -46,8 +46,8 @@ public class CompileEnvironmentTest extends TestCase {
File[] files = out.listFiles();
Arrays.sort(files);
assertEquals(2, files.length);
assertEquals(1, files[0].listFiles().length);//META-INF
assertEquals(2, files[1].listFiles().length);//Smoke package
assertEquals(1, files[0].listFiles().length); //META-INF
assertEquals(1, files[1].listFiles().length); // SmokeKt
}
finally {
FileUtil.delete(tempDir);
@@ -140,13 +140,17 @@ public abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdi
val packageScopes = arrayListOf<JetScope>()
val classes = arrayListOf<ClassDescriptor>()
var shouldAddPackageView = false
for (classFile in allClassFiles) {
val className = classFile.relativeTo(tmpdir).substringBeforeLast(".class").replace('/', '.').replace('\\', '.')
val klass = classLoader.loadClass(className).sure { "Couldn't load class $className" }
val header = ReflectKotlinClass.create(klass)?.getClassHeader()
if (header?.kind == KotlinClassHeader.Kind.PACKAGE_FACADE || header?.kind == KotlinClassHeader.Kind.FILE_FACADE) {
if (header?.kind == KotlinClassHeader.Kind.PACKAGE_FACADE ||
header?.kind == KotlinClassHeader.Kind.FILE_FACADE ||
header?.kind == KotlinClassHeader.Kind.MULTIFILE_CLASS
) {
val packageView = module.getPackage(LoadDescriptorUtil.TEST_PACKAGE_FQNAME)
if (!packageScopes.contains(packageView.memberScope)) {
packageScopes.add(packageView.memberScope)