From 8ee8ddd99708a16be1ceacef7712aa183a2b8ba3 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Mon, 8 Apr 2013 17:51:41 +0400 Subject: [PATCH] Enable completion test from custom jar-libraries --- .../jet/generators/tests/GenerateTests.java | 7 ++ .../AbstractJavaWithLibCompletionTest.java | 85 +++++++++++++++++++ .../JetFixtureCompletionBaseTestCase.java | 9 -- .../JetJavaLibCompletionTestGenerated.java | 49 +++++++++++ 4 files changed, 141 insertions(+), 9 deletions(-) create mode 100644 idea/tests/org/jetbrains/jet/completion/AbstractJavaWithLibCompletionTest.java create mode 100644 idea/tests/org/jetbrains/jet/completion/JetJavaLibCompletionTestGenerated.java diff --git a/generators/org/jetbrains/jet/generators/tests/GenerateTests.java b/generators/org/jetbrains/jet/generators/tests/GenerateTests.java index b29d80c050d..c151f588f64 100644 --- a/generators/org/jetbrains/jet/generators/tests/GenerateTests.java +++ b/generators/org/jetbrains/jet/generators/tests/GenerateTests.java @@ -28,6 +28,7 @@ import org.jetbrains.jet.codegen.defaultConstructor.AbstractDefaultConstructorCo import org.jetbrains.jet.codegen.flags.AbstractWriteFlagsTest; import org.jetbrains.jet.codegen.generated.AbstractBlackBoxCodegenTest; import org.jetbrains.jet.completion.AbstractJavaCompletionTest; +import org.jetbrains.jet.completion.AbstractJavaWithLibCompletionTest; import org.jetbrains.jet.completion.AbstractJetJSCompletionTest; import org.jetbrains.jet.jvm.compiler.*; import org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveDescriptorRendererTest; @@ -241,6 +242,12 @@ public class GenerateTests { testModel("idea/testData/completion/basic/java", false, "doTest") ); + generateTest( + "idea/tests", + "JetJavaLibCompletionTestGenerated", + AbstractJavaWithLibCompletionTest.class, + testModel("idea/testData/completion/basic/custom", false, "doTestWithJar")); + generateTest( "idea/tests/", "QuickFixMultiFileTestGenerated", diff --git a/idea/tests/org/jetbrains/jet/completion/AbstractJavaWithLibCompletionTest.java b/idea/tests/org/jetbrains/jet/completion/AbstractJavaWithLibCompletionTest.java new file mode 100644 index 00000000000..3b82869cff5 --- /dev/null +++ b/idea/tests/org/jetbrains/jet/completion/AbstractJavaWithLibCompletionTest.java @@ -0,0 +1,85 @@ +/* + * 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.completion; + +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; +import com.intellij.openapi.module.StdModuleTypes; +import com.intellij.openapi.projectRoots.Sdk; +import com.intellij.openapi.roots.ContentEntry; +import com.intellij.openapi.roots.ModifiableRootModel; +import com.intellij.openapi.roots.OrderRootType; +import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEditor; +import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.testFramework.LightProjectDescriptor; +import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.plugin.PluginTestCaseBase; +import org.jetbrains.jet.testing.ConfigLibraryUtil; + +import java.io.File; + +public abstract class AbstractJavaWithLibCompletionTest extends JetFixtureCompletionBaseTestCase { + public void doTestWithJar(String testPath) { + NewLibraryEditor editor = new NewLibraryEditor(); + editor.setName("doTestWithJarLib"); + + File fullDirectoryPath = new File(testPath).getParentFile(); + String jarLibName = getTestName(false) + ".jar"; + + File jarFile = new File(fullDirectoryPath, jarLibName); + assert jarFile.exists() : "Library file should exist: " + jarFile.getAbsolutePath(); + + editor.addRoot(VfsUtil.getUrlForLibraryRoot(jarFile), OrderRootType.CLASSES); + + try { + ConfigLibraryUtil.configureLibrary(myModule, getProjectDescriptor().getSdk(), editor); + CodeInsightTestFixtureImpl.ensureIndexesUpToDate(getProject()); + + doTest(testPath); + } + finally { + ConfigLibraryUtil.unConfigureLibrary(myModule, getProjectDescriptor().getSdk(), editor.getName()); + } + } + + @NotNull + @Override + protected LightProjectDescriptor getProjectDescriptor() { + return new LightProjectDescriptor() { + @Override + public ModuleType getModuleType() { + return StdModuleTypes.JAVA; + } + + @Override + public Sdk getSdk() { + return PluginTestCaseBase.jdkFromIdeaHome(); + } + + @Override + public void configureModule(Module module, ModifiableRootModel model, ContentEntry contentEntry) { + // Do nothing + } + }; + } + + @Override + public ExpectedCompletionUtils.Platform getPlatform() { + return ExpectedCompletionUtils.Platform.JAVA; + } +} diff --git a/idea/tests/org/jetbrains/jet/completion/JetFixtureCompletionBaseTestCase.java b/idea/tests/org/jetbrains/jet/completion/JetFixtureCompletionBaseTestCase.java index 24141d98b8d..288ea708a06 100644 --- a/idea/tests/org/jetbrains/jet/completion/JetFixtureCompletionBaseTestCase.java +++ b/idea/tests/org/jetbrains/jet/completion/JetFixtureCompletionBaseTestCase.java @@ -19,10 +19,7 @@ package org.jetbrains.jet.completion; import com.intellij.codeInsight.CodeInsightSettings; import com.intellij.codeInsight.completion.CompletionType; import com.intellij.codeInsight.lookup.LookupElement; -import com.intellij.testFramework.LightProjectDescriptor; import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.plugin.JetStdJSProjectDescriptor; public abstract class JetFixtureCompletionBaseTestCase extends LightCodeInsightFixtureTestCase { private boolean autocompleteSetting; @@ -79,10 +76,4 @@ public abstract class JetFixtureCompletionBaseTestCase extends LightCodeInsightF itemsNumber.intValue(), items.length); } } - - @NotNull - @Override - protected LightProjectDescriptor getProjectDescriptor() { - return JetStdJSProjectDescriptor.INSTANCE; - } } diff --git a/idea/tests/org/jetbrains/jet/completion/JetJavaLibCompletionTestGenerated.java b/idea/tests/org/jetbrains/jet/completion/JetJavaLibCompletionTestGenerated.java new file mode 100644 index 00000000000..df60683327f --- /dev/null +++ b/idea/tests/org/jetbrains/jet/completion/JetJavaLibCompletionTestGenerated.java @@ -0,0 +1,49 @@ +/* + * 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.completion; + +import junit.framework.Assert; +import junit.framework.Test; +import junit.framework.TestSuite; + +import java.io.File; +import java.util.regex.Pattern; +import org.jetbrains.jet.JetTestUtils; +import org.jetbrains.jet.test.InnerTestClasses; +import org.jetbrains.jet.test.TestMetadata; + +import org.jetbrains.jet.completion.AbstractJavaWithLibCompletionTest; + +/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("idea/testData/completion/basic/custom") +public class JetJavaLibCompletionTestGenerated extends AbstractJavaWithLibCompletionTest { + public void testAllFilesPresentInCustom() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/completion/basic/custom"), Pattern.compile("^(.+)\\.kt$"), false); + } + + @TestMetadata("TopLevelNonImportedExtFun.kt") + public void testTopLevelNonImportedExtFun() throws Exception { + doTestWithJar("idea/testData/completion/basic/custom/TopLevelNonImportedExtFun.kt"); + } + + @TestMetadata("TopLevelNonImportedFun.kt") + public void testTopLevelNonImportedFun() throws Exception { + doTestWithJar("idea/testData/completion/basic/custom/TopLevelNonImportedFun.kt"); + } + +}