Test for property from top level object

#KT-3187 Fixed
This commit is contained in:
Nikolay Krasko
2013-01-14 22:07:32 +04:00
parent d14f382db9
commit 1263919e39
8 changed files with 166 additions and 0 deletions
@@ -0,0 +1,5 @@
package test
import testing.*
val testObjectProperty = TopLevelObject
@@ -0,0 +1,3 @@
package test
internal val testObjectProperty : testing.TopLevelObject
@@ -0,0 +1,3 @@
package testing
object TopLevelObject
@@ -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<JetFile> jetFiles = Collections.singletonList(JetTestUtils.loadJetFile(project, ktFile));
BindingContext bindingContext = AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
project, jetFiles, Collections.<AnalyzerScriptParameter>emptyList(),
Predicates.<PsiFile>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<File> jarFiles = FileUtil.findFilesByMask(Pattern.compile("^.*\\.jar$"), dir);
CopyOnWriteArrayList<File> 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);
}
}
@@ -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;
}
}
@@ -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",