From 1263919e3905610cac34518513464197b7ac7188 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Mon, 14 Jan 2013 22:07:32 +0400 Subject: [PATCH] Test for property from top level object #KT-3187 Fixed --- .../duplicateLibraries/DuplicateLibTest-1.jar | Bin 0 -> 1163 bytes .../duplicateLibraries/DuplicateLibTest-2.jar | Bin 0 -> 1163 bytes .../duplicateLibraries/DuplicateLibraries.kt | 5 + .../duplicateLibraries/DuplicateLibraries.txt | 3 + .../duplicateLibraries/DuplicateTest.kt.txt | 3 + ...actCompileKotlinAgainstCustomJavaTest.java | 91 ++++++++++++++++++ ...mpileKotlinAgainstCustomJavaGenerated.java | 56 +++++++++++ .../jet/generators/tests/GenerateTests.java | 8 ++ 8 files changed, 166 insertions(+) create mode 100644 compiler/testData/compileKotlinAgainstCustomJava/duplicateLibraries/DuplicateLibTest-1.jar create mode 100644 compiler/testData/compileKotlinAgainstCustomJava/duplicateLibraries/DuplicateLibTest-2.jar create mode 100644 compiler/testData/compileKotlinAgainstCustomJava/duplicateLibraries/DuplicateLibraries.kt create mode 100644 compiler/testData/compileKotlinAgainstCustomJava/duplicateLibraries/DuplicateLibraries.txt create mode 100644 compiler/testData/compileKotlinAgainstCustomJava/duplicateLibraries/DuplicateTest.kt.txt create mode 100644 compiler/tests/org/jetbrains/jet/jvm/compiler/AbstractCompileKotlinAgainstCustomJavaTest.java create mode 100644 compiler/tests/org/jetbrains/jet/jvm/compiler/CompileKotlinAgainstCustomJavaGenerated.java diff --git a/compiler/testData/compileKotlinAgainstCustomJava/duplicateLibraries/DuplicateLibTest-1.jar b/compiler/testData/compileKotlinAgainstCustomJava/duplicateLibraries/DuplicateLibTest-1.jar new file mode 100644 index 0000000000000000000000000000000000000000..9299cfd1ae026b0ff7a1f93619298728c4bde47f GIT binary patch literal 1163 zcmWIWW@Zs#-~htAi}airkN_703qx^oQD#AjUUo_Gzf%khYo~hW-!|Ym{{E*(lmA`i zYugU9@!Uv!5teXT?&zlDh6$=_Q+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ileKotlinAgainstCustomJava/duplicateLibraries/DuplicateLibTest-2.jar b/compiler/testData/compileKotlinAgainstCustomJava/duplicateLibraries/DuplicateLibTest-2.jar new file mode 100644 index 0000000000000000000000000000000000000000..9299cfd1ae026b0ff7a1f93619298728c4bde47f GIT binary patch literal 1163 zcmWIWW@Zs#-~htAi}airkN_703qx^oQD#AjUUo_Gzf%khYo~hW-!|Ym{{E*(lmA`i zYugU9@!Uv!5teXT?&zlDh6$=_Q+2)BJj;38>b{>WymUii+rkwk8y$u0Kj{Zfx%Mh~ z%Ut)PZ86$evYuO~__)RJ7+>Eq(dBC39`4l5+)qC}%(>fYx5i0Xo&U=EnO@l+=82qU z+w=c{-aaMo!h&zz$?j~CwpB~JE>Hg@t-SHylUFYiqxCp;^!=LaY9W7M&2g2pDPLwP zPun!@(X^FYt-c<((-d=0>g>THkEtEfO>T2{hU}~34_}}iZLd3jx_{XDxEEak)#VG% zstPPFh-4J~zAQ4Q_Rh1!(32mHgJY*2^ig=`vxJQ)XTw2-&tG^awcq-cH+h#CcXz@4 zy)z4Dsyy17A#IVOwfgwaj01~V8*6;tIlbByI!hw_oRaUsmt6Jlmb`U|bbooz{gz#r znpv&&g3yhV3tz;a-uc+VGon_eMEJhF$$dl5_4PC67QbrR!S;W`z4x=D-c@gnwm45crK4V$yu6Om*^2H7(Z2058o#d-`zomD1^^3rM3FaSZWyZgG1H9QeJ|*pZ zeVCDfA&{McApjWtT;NE5iWdDGK+%%a;*!j~bbXL2NFsTRrb-4$RY-n;Pik3ej(<{C zYI2EQa!z7#ajCzrH?yHY?agi5cIR&0c8gzhkH!l2@V(nOltiYmIxc-+7<+lruC&u? z(I3(~+nbu~56G+fZTq5RW#F0iY_GX~{QdXy8P07ue8I#?dgZZywKlv*d|b>AcXId& z_AE4eX#CE7&a%^aeG9DwkL?#ryQyU`<(JXLXFpCFykRSwv*gr?^oO&jubhx268$Ij z$kum8JEHnT%`=rGULAZd%A(PuWOvQ7sKV)m?aD0=wNy&1f85q7466$AEIv2E+Cs+Q z&HwjGYCBbUedmKN^pDDxFYf56um_z^ zRMDH##cMvvL~_q=3ty*;(7b>F6n` zS+@dza+U75p<;9TgYKi78ubS%XDt5N_O0n@g0*$Gk!iLU$uj45`G7mNpj zy?`F5Lp*FRzX=86`*EhkX|kZ-0_ak`yXf%A{8KP1f>IH*MQOi0;n<} XbYV*s0p6@^Al1x3xCcn@WCrm7pcl<% literal 0 HcmV?d00001 diff --git a/compiler/testData/compileKotlinAgainstCustomJava/duplicateLibraries/DuplicateLibraries.kt b/compiler/testData/compileKotlinAgainstCustomJava/duplicateLibraries/DuplicateLibraries.kt new file mode 100644 index 00000000000..5472bfb0085 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomJava/duplicateLibraries/DuplicateLibraries.kt @@ -0,0 +1,5 @@ +package test + +import testing.* + +val testObjectProperty = TopLevelObject \ No newline at end of file diff --git a/compiler/testData/compileKotlinAgainstCustomJava/duplicateLibraries/DuplicateLibraries.txt b/compiler/testData/compileKotlinAgainstCustomJava/duplicateLibraries/DuplicateLibraries.txt new file mode 100644 index 00000000000..7f3327e25b9 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomJava/duplicateLibraries/DuplicateLibraries.txt @@ -0,0 +1,3 @@ +package test + +internal val testObjectProperty : testing.TopLevelObject diff --git a/compiler/testData/compileKotlinAgainstCustomJava/duplicateLibraries/DuplicateTest.kt.txt b/compiler/testData/compileKotlinAgainstCustomJava/duplicateLibraries/DuplicateTest.kt.txt new file mode 100644 index 00000000000..e3b8606e6af --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomJava/duplicateLibraries/DuplicateTest.kt.txt @@ -0,0 +1,3 @@ +package testing + +object TopLevelObject \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/AbstractCompileKotlinAgainstCustomJavaTest.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/AbstractCompileKotlinAgainstCustomJavaTest.java new file mode 100644 index 00000000000..9982f0808be --- /dev/null +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/AbstractCompileKotlinAgainstCustomJavaTest.java @@ -0,0 +1,91 @@ +/* + * Copyright 2010-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.jvm.compiler; + +import com.google.common.base.Predicates; +import com.google.common.collect.Lists; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.psi.PsiFile; +import com.intellij.util.ArrayUtil; +import org.jetbrains.jet.ConfigurationKind; +import org.jetbrains.jet.JetTestUtils; +import org.jetbrains.jet.TestJdkKind; +import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment; +import org.jetbrains.jet.config.CompilerConfiguration; +import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor; +import org.jetbrains.jet.lang.psi.JetFile; +import org.jetbrains.jet.lang.resolve.AnalyzerScriptParameter; +import org.jetbrains.jet.lang.resolve.BindingContext; +import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM; +import org.jetbrains.jet.lang.resolve.name.FqName; +import org.jetbrains.jet.test.TestCaseWithTmpdir; +import org.jetbrains.jet.test.util.NamespaceComparator; +import org.junit.Assert; + +import java.io.File; +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.regex.Pattern; + +import static org.jetbrains.jet.test.util.NamespaceComparator.compareNamespaceWithFile; + +public abstract class AbstractCompileKotlinAgainstCustomJavaTest extends TestCaseWithTmpdir { + protected void doTest(String ktFilePath) throws Exception { + Assert.assertTrue(ktFilePath.endsWith(".kt")); + + File ktFile = new File(ktFilePath); + String testFileWithoutExtension = FileUtil.getNameWithoutExtension(ktFile); + + checkCompiledNamespace(ktFile, LoadDescriptorUtil.TEST_PACKAGE_FQNAME, + new File(ktFile.getParentFile(), testFileWithoutExtension + ".txt")); + } + + private void checkCompiledNamespace(File ktFile, FqName namespaceFqn, File expectedFile) throws IOException { + JetCoreEnvironment environment = getEnvironment(ktFile); + Project project = environment.getProject(); + + List jetFiles = Collections.singletonList(JetTestUtils.loadJetFile(project, ktFile)); + + BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration( + project, jetFiles, Collections.emptyList(), + Predicates.alwaysTrue()).getBindingContext(); + + NamespaceDescriptor namespaceDescriptor = bindingContext.get(BindingContext.FQNAME_TO_NAMESPACE_DESCRIPTOR, namespaceFqn); + assertNotNull("Failed to find namespace: " + namespaceFqn, namespaceDescriptor); + + compareNamespaceWithFile(namespaceDescriptor, NamespaceComparator.DONT_INCLUDE_METHODS_OF_OBJECT, expectedFile); + } + + private JetCoreEnvironment getEnvironment(File ktFile) { + File dir = ktFile.getParentFile(); + + List jarFiles = FileUtil.findFilesByMask(Pattern.compile("^.*\\.jar$"), dir); + + CopyOnWriteArrayList extras = Lists.newCopyOnWriteArrayList(); + extras.addAll(jarFiles); + extras.add(JetTestUtils.getAnnotationsJar()); + extras.add(dir); + + CompilerConfiguration configurationWithADirInClasspath = JetTestUtils.compilerConfigurationForTests( + ConfigurationKind.ALL, TestJdkKind.MOCK_JDK, ArrayUtil.toObjectArray(extras, File.class)); + + return new JetCoreEnvironment(getTestRootDisposable(), configurationWithADirInClasspath); + } +} diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileKotlinAgainstCustomJavaGenerated.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileKotlinAgainstCustomJavaGenerated.java new file mode 100644 index 00000000000..6a68daafa71 --- /dev/null +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileKotlinAgainstCustomJavaGenerated.java @@ -0,0 +1,56 @@ +/* + * Copyright 2010-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jetbrains.jet.jvm.compiler; + +import junit.framework.Assert; +import junit.framework.Test; +import junit.framework.TestSuite; + +import java.io.File; +import org.jetbrains.jet.JetTestUtils; +import org.jetbrains.jet.test.InnerTestClasses; +import org.jetbrains.jet.test.TestMetadata; + +import org.jetbrains.jet.jvm.compiler.AbstractCompileKotlinAgainstCustomJavaTest; + +/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */ +@TestMetadata("compiler/testData/compileKotlinAgainstCustomJava") +@InnerTestClasses({CompileKotlinAgainstCustomJavaGenerated.DuplicateLibraries.class}) +public class CompileKotlinAgainstCustomJavaGenerated extends AbstractCompileKotlinAgainstCustomJavaTest { + public void testAllFilesPresentInCompileKotlinAgainstCustomJava() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/compileKotlinAgainstCustomJava"), "kt", true); + } + + @TestMetadata("compiler/testData/compileKotlinAgainstCustomJava/duplicateLibraries") + public static class DuplicateLibraries extends AbstractCompileKotlinAgainstCustomJavaTest { + public void testAllFilesPresentInDuplicateLibraries() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/compileKotlinAgainstCustomJava/duplicateLibraries"), "kt", true); + } + + @TestMetadata("DuplicateLibraries.kt") + public void testDuplicateLibraries() throws Exception { + doTest("compiler/testData/compileKotlinAgainstCustomJava/duplicateLibraries/DuplicateLibraries.kt"); + } + + } + + public static Test suite() { + TestSuite suite = new TestSuite("CompileKotlinAgainstCustomJavaGenerated"); + suite.addTestSuite(CompileKotlinAgainstCustomJavaGenerated.class); + suite.addTestSuite(DuplicateLibraries.class); + return suite; + } +} diff --git a/generators/org/jetbrains/jet/generators/tests/GenerateTests.java b/generators/org/jetbrains/jet/generators/tests/GenerateTests.java index 4dfaad6e8f0..efaec0eeb26 100644 --- a/generators/org/jetbrains/jet/generators/tests/GenerateTests.java +++ b/generators/org/jetbrains/jet/generators/tests/GenerateTests.java @@ -29,6 +29,7 @@ import org.jetbrains.jet.codegen.flags.AbstractWriteFlagsTest; import org.jetbrains.jet.codegen.generated.AbstractCodegenTest; import org.jetbrains.jet.jvm.compiler.AbstractCompileJavaAgainstKotlinTest; import org.jetbrains.jet.jvm.compiler.AbstractCompileKotlinAgainstKotlinTest; +import org.jetbrains.jet.jvm.compiler.AbstractCompileKotlinAgainstCustomJavaTest; import org.jetbrains.jet.jvm.compiler.AbstractLoadCompiledKotlinTest; import org.jetbrains.jet.jvm.compiler.AbstractLoadJavaTest; import org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveDescriptorRendererTest; @@ -174,6 +175,13 @@ public class GenerateTests { testModel("compiler/testData/compileKotlinAgainstKotlin", true, "A.kt", "doTest") ); + generateTest( + "compiler/tests/", + "CompileKotlinAgainstCustomJavaGenerated", + AbstractCompileKotlinAgainstCustomJavaTest.class, + testModel("compiler/testData/compileKotlinAgainstCustomJava") + ); + generateTest( "compiler/tests/", "LazyResolveDescriptorRendererTestGenerated",