From 04c83b25d49236d83b5db41d89336d4ba2a9591f Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Thu, 10 Jan 2013 14:12:26 +0400 Subject: [PATCH] Added test for obsolete bug. #KT-3186 obsolete --- ...thJdkAndRuntimeLightProjectDescriptor.java | 2 +- .../NavigateToLibraryRegressionTest.java | 2 +- .../NavigateToStdlibSourceRegressionTest.java | 78 +++++++++++++++++++ 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 idea/tests/org/jetbrains/jet/plugin/libraries/NavigateToStdlibSourceRegressionTest.java diff --git a/idea/tests/org/jetbrains/jet/plugin/JetWithJdkAndRuntimeLightProjectDescriptor.java b/idea/tests/org/jetbrains/jet/plugin/JetWithJdkAndRuntimeLightProjectDescriptor.java index f5689273eea..00c54103c6c 100644 --- a/idea/tests/org/jetbrains/jet/plugin/JetWithJdkAndRuntimeLightProjectDescriptor.java +++ b/idea/tests/org/jetbrains/jet/plugin/JetWithJdkAndRuntimeLightProjectDescriptor.java @@ -29,7 +29,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.jet.codegen.forTestCompile.ForTestCompileRuntime; public class JetWithJdkAndRuntimeLightProjectDescriptor implements LightProjectDescriptor { - private JetWithJdkAndRuntimeLightProjectDescriptor() { + protected JetWithJdkAndRuntimeLightProjectDescriptor() { } public static final JetWithJdkAndRuntimeLightProjectDescriptor INSTANCE = new JetWithJdkAndRuntimeLightProjectDescriptor(); diff --git a/idea/tests/org/jetbrains/jet/plugin/libraries/NavigateToLibraryRegressionTest.java b/idea/tests/org/jetbrains/jet/plugin/libraries/NavigateToLibraryRegressionTest.java index 994782c7dc8..6230e75335a 100644 --- a/idea/tests/org/jetbrains/jet/plugin/libraries/NavigateToLibraryRegressionTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/libraries/NavigateToLibraryRegressionTest.java @@ -66,7 +66,7 @@ public class NavigateToLibraryRegressionTest extends LightCodeInsightFixtureTest return JetWithJdkAndRuntimeLightProjectDescriptor.INSTANCE; } - private PsiElement configureAndResolve(String text) { + protected PsiElement configureAndResolve(String text) { myFixture.configureByText(JetFileType.INSTANCE, text); PsiReference ref = myFixture.getFile().findReferenceAt(myFixture.getCaretOffset()); //noinspection ConstantConditions diff --git a/idea/tests/org/jetbrains/jet/plugin/libraries/NavigateToStdlibSourceRegressionTest.java b/idea/tests/org/jetbrains/jet/plugin/libraries/NavigateToStdlibSourceRegressionTest.java new file mode 100644 index 00000000000..101c5835611 --- /dev/null +++ b/idea/tests/org/jetbrains/jet/plugin/libraries/NavigateToStdlibSourceRegressionTest.java @@ -0,0 +1,78 @@ +/* + * 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.plugin.libraries; + +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.roots.ContentEntry; +import com.intellij.openapi.roots.ModifiableRootModel; +import com.intellij.openapi.roots.OrderRootType; +import com.intellij.openapi.roots.libraries.Library; +import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.psi.PsiElement; +import com.intellij.testFramework.LightPlatformTestCase; +import com.intellij.testFramework.LightProjectDescriptor; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.plugin.JetWithJdkAndRuntimeLightProjectDescriptor; + +import java.io.File; + +public class NavigateToStdlibSourceRegressionTest extends NavigateToLibraryRegressionTest { + /** + * Regression test against KT-3186 + */ + public void testRefToAssertEquals() { + PsiElement navigationElement = configureAndResolve("import kotlin.test.assertEquals; val x = assertEquals(1, 2)"); + assertEquals("Test.kt", navigationElement.getContainingFile().getName()); + } + + @Override + protected void tearDown() throws Exception { + // Workaround for IDEA's bug during tests. + // After tests IDEA disposes VirtualFiles within LocalFileSystem, but doesn't rebuild indices. + // This causes library source files to be impossible to find via indices + super.tearDown(); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + LightPlatformTestCase.closeAndDeleteProject(); + } + }); + } + + @NotNull + @Override + protected LightProjectDescriptor getProjectDescriptor() { + return ProjectDescriptorWithStdlibSources.INSTANCE; + } + + private static class ProjectDescriptorWithStdlibSources extends JetWithJdkAndRuntimeLightProjectDescriptor { + public static final ProjectDescriptorWithStdlibSources INSTANCE = new ProjectDescriptorWithStdlibSources(); + + @Override + public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @Nullable ContentEntry contentEntry) { + super.configureModule(module, model, contentEntry); + + Library library = model.getModuleLibraryTable().getLibraryByName("ktl"); + assert library != null; + Library.ModifiableModel modifiableModel = library.getModifiableModel(); + modifiableModel.addRoot(VfsUtil.getUrlForLibraryRoot(new File("libraries/stdlib/src")), OrderRootType.SOURCES); + modifiableModel.commit(); + } + } +}