Tests: add runtime (and runtime sources) to some tests that rely on being able to resolve references to built ins

This commit is contained in:
Pavel V. Talanov
2015-12-10 17:22:45 +03:00
parent 539b84b561
commit a667aa2f71
50 changed files with 81 additions and 16 deletions
@@ -1,3 +1,4 @@
/*
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
@@ -23,6 +24,7 @@ import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.util.io.FileUtilRt;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.test.MockLibraryUtil;
import org.jetbrains.kotlin.utils.PathUtil;
import java.io.File;
@@ -31,31 +33,41 @@ public class JdkAndMockLibraryProjectDescriptor extends KotlinLightProjectDescri
private final String sourcesPath;
private final boolean withSources;
private final boolean withRuntime;
private final boolean isJsLibrary;
public JdkAndMockLibraryProjectDescriptor(String sourcesPath, boolean withSources) {
this(sourcesPath, withSources, false);
this(sourcesPath, withSources, false, false);
}
public JdkAndMockLibraryProjectDescriptor(String sourcesPath, boolean withSources, boolean isJsLibrary) {
public JdkAndMockLibraryProjectDescriptor(String sourcesPath, boolean withSources, boolean withRuntime, boolean isJsLibrary) {
this.sourcesPath = sourcesPath;
this.withSources = withSources;
this.withRuntime = withRuntime;
this.isJsLibrary = isJsLibrary;
}
@Override
public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model) {
File libraryJar = MockLibraryUtil.compileLibraryToJar(sourcesPath, LIBRARY_NAME, withSources, isJsLibrary);
String jarUrl = "jar://" + FileUtilRt.toSystemIndependentName(libraryJar.getAbsolutePath()) + "!/";
String jarUrl = getJarUrl(libraryJar);
Library.ModifiableModel libraryModel = model.getModuleLibraryTable().getModifiableModel().createLibrary(LIBRARY_NAME).getModifiableModel();
libraryModel.addRoot(jarUrl, OrderRootType.CLASSES);
if (withRuntime) {
libraryModel.addRoot(getJarUrl(PathUtil.getKotlinPathsForDistDirectory().getRuntimePath()), OrderRootType.CLASSES);
}
if (withSources) {
libraryModel.addRoot(jarUrl + "src/", OrderRootType.SOURCES);
}
libraryModel.commit();
}
@NotNull
private static String getJarUrl(@NotNull File libraryJar) {
return "jar://" + FileUtilRt.toSystemIndependentName(libraryJar.getAbsolutePath()) + "!/";
}
@Override
public boolean equals(Object o) {
@@ -65,15 +77,19 @@ public class JdkAndMockLibraryProjectDescriptor extends KotlinLightProjectDescri
JdkAndMockLibraryProjectDescriptor that = (JdkAndMockLibraryProjectDescriptor) o;
if (withSources != that.withSources) return false;
if (sourcesPath != null ? !sourcesPath.equals(that.sourcesPath) : that.sourcesPath != null) return false;
if (withRuntime != that.withRuntime) return false;
if (isJsLibrary != that.isJsLibrary) return false;
if (!sourcesPath.equals(that.sourcesPath)) return false;
return true;
}
@Override
public int hashCode() {
int result = sourcesPath != null ? sourcesPath.hashCode() : 0;
int result = sourcesPath.hashCode();
result = 31 * result + (withSources ? 1 : 0);
result = 31 * result + (withRuntime ? 1 : 0);
result = 31 * result + (isJsLibrary ? 1 : 0);
return result;
}
}
@@ -2,6 +2,7 @@
// ACTION: Create extension function 'Foo'
// ACTION: Rename reference
// ERROR: Unresolved reference: Foo
// WITH_RUNTIME
fun test() {
val a = 2.<caret>Foo(1)
@@ -2,6 +2,7 @@
// ACTION: Create extension function 'Foo'
// ACTION: Rename reference
// ERROR: Unresolved reference: Foo
// WITH_RUNTIME
class A<T>(val items: List<T>) {
fun test() = items.<caret>Foo<Int, String>(2, "2")
@@ -1,4 +1,5 @@
// "Create extension function 'plus'" "true"
// WITH_RUNTIME
class A<T>(val n: T)
@@ -1,4 +1,5 @@
// "Create extension function 'plus'" "true"
// WITH_RUNTIME
class A<T>(val n: T)
@@ -1,4 +1,5 @@
// "Create extension function '!u00A0'" "true"
// WITH_RUNTIME
fun test() {
val t: Int = 1 <caret>`!u00A0` 2
@@ -1,4 +1,5 @@
// "Create extension function '!u00A0'" "true"
// WITH_RUNTIME
fun test() {
val t: Int = 1 `!u00A0` 2
@@ -1,4 +1,5 @@
// "Create extension function 'foo'" "true"
// WITH_RUNTIME
fun test() {
val a: Int = Unit.<caret>foo(2)
@@ -1,4 +1,5 @@
// "Create extension function 'foo'" "true"
// WITH_RUNTIME
fun test() {
val a: Int = Unit.foo(2)
@@ -1,4 +1,5 @@
// "Create extension function 'foo'" "true"
// WITH_RUNTIME
class A<T>(val n: T)
@@ -1,4 +1,5 @@
// "Create extension function 'foo'" "true"
// WITH_RUNTIME
class A<T>(val n: T)
@@ -1,4 +1,5 @@
// "Create extension function 'foo'" "true"
// WITH_RUNTIME
class A<T>(val items: List<T>) {
fun test(): Int {
@@ -1,4 +1,5 @@
// "Create extension function 'foo'" "true"
// WITH_RUNTIME
class A<T>(val items: List<T>) {
fun test(): Int {
@@ -1,4 +1,5 @@
// "Create extension function 'foo'" "true"
// WITH_RUNTIME
class A<T>(val items: List<T>) {
fun test(): Int {
@@ -1,4 +1,5 @@
// "Create extension function 'foo'" "true"
// WITH_RUNTIME
class A<T>(val items: List<T>) {
fun test(): Int {
@@ -1,4 +1,5 @@
// "Create extension function 'foo'" "true"
// WITH_RUNTIME
class A<T>(val items: List<T>) {
fun test(): Int {
@@ -1,4 +1,5 @@
// "Create extension function 'foo'" "true"
// WITH_RUNTIME
class A<T>(val items: List<T>) {
fun test(): Int {
@@ -1,4 +1,5 @@
// "Create extension function 'foo'" "true"
// WITH_RUNTIME
fun <T, U> T.map(f: T.() -> U) = f()
fun consume(s: String) {}
@@ -1,4 +1,5 @@
// "Create extension function 'foo'" "true"
// WITH_RUNTIME
fun <T, U> T.map(f: T.() -> U) = f()
fun consume(s: String) {}
@@ -1,4 +1,5 @@
// "Create extension function 'component2'" "true"
// WITH_RUNTIME
class FooIterator<T> {
operator fun hasNext(): Boolean { return false }
operator fun next(): Any {
@@ -1,4 +1,5 @@
// "Create extension function 'component2'" "true"
// WITH_RUNTIME
class FooIterator<T> {
operator fun hasNext(): Boolean { return false }
operator fun next(): Any {
@@ -1,4 +1,5 @@
// "Create extension function 'get'" "true"
// WITH_RUNTIME
fun x (y: Any) {
val z: Any = y<caret>[""]
@@ -1,4 +1,5 @@
// "Create extension function 'get'" "true"
// WITH_RUNTIME
fun x (y: Any) {
val z: Any = y[""]
@@ -1,4 +1,5 @@
// "Create extension function 'invoke'" "true"
// WITH_RUNTIME
class A<T>(val n: T)
@@ -1,4 +1,5 @@
// "Create extension function 'invoke'" "true"
// WITH_RUNTIME
class A<T>(val n: T)
@@ -1,4 +1,5 @@
// "Create extension function 'set'" "true"
// WITH_RUNTIME
class Foo<T> {
fun <T> x (y: Any, w: java.util.ArrayList<T>) {
@@ -1,6 +1,7 @@
import java.util.ArrayList
// "Create extension function 'set'" "true"
// WITH_RUNTIME
class Foo<T> {
fun <T> x (y: Any, w: java.util.ArrayList<T>) {
@@ -1,4 +1,5 @@
// "Create extension function 'unaryMinus'" "true"
// WITH_RUNTIME
fun test() {
val a = <caret>-false
@@ -1,4 +1,5 @@
// "Create extension function 'unaryMinus'" "true"
// WITH_RUNTIME
fun test() {
val a = -false
@@ -1,5 +1,6 @@
// "Create secondary constructor" "false"
// ERROR: Too many arguments for public constructor Any() defined in kotlin.Any
// WITH_RUNTIME
interface T {
@@ -2,6 +2,7 @@
// ERROR: Unresolved reference: foo
// ACTION: Create extension function 'foo'
// ACTION: Replace infix call with ordinary call
// WITH_RUNTIME
fun refer() {
1 <caret>foo 2
}
@@ -2,6 +2,7 @@
// ERROR: Unresolved reference: foo
// ACTION: Create extension function 'foo'
// ACTION: Replace infix call with ordinary call
// WITH_RUNTIME
fun refer() {
1 <caret>foo 2
}
@@ -2,6 +2,7 @@
// ACTION: Create extension property 'foo'
// ACTION: Rename reference
// ERROR: Unresolved reference: foo
// WITH_RUNTIME
class A<T>(val n: T)
@@ -2,6 +2,7 @@
// ERROR: Unresolved reference: foo
// ACTION: Create extension function 'foo'
// ACTION: Replace infix call with ordinary call
// WITH_RUNTIME
fun refer() {
1 <caret>foo 2
}
@@ -1,5 +1,6 @@
// "Create extension property 'foo'" "true"
// ERROR: Property must be initialized
// WITH_RUNTIME
fun test() {
val a: Int = Unit.<caret>foo
@@ -1,5 +1,6 @@
// "Create extension property 'foo'" "true"
// ERROR: Property must be initialized
// WITH_RUNTIME
val Unit.foo: Int
@@ -1,5 +1,6 @@
// "Create extension property 'foo'" "true"
// ERROR: Property must be initialized
// WITH_RUNTIME
class A<T>(val n: T)
@@ -1,5 +1,6 @@
// "Create extension property 'foo'" "true"
// ERROR: Property must be initialized
// WITH_RUNTIME
class A<T>(val n: T)
@@ -1,5 +1,6 @@
// "Create extension property 'foo'" "true"
// ERROR: Property must be initialized
// WITH_RUNTIME
class A<T>(val n: T)
@@ -1,5 +1,6 @@
// "Create extension property 'foo'" "true"
// ERROR: Property must be initialized
// WITH_RUNTIME
class A<T>(val n: T)
@@ -1,5 +1,6 @@
// PARAM_DESCRIPTOR: public fun Bar.foo(): kotlin.Unit defined in root package
// PARAM_TYPES: Bar, Foo, kotlin.Any
// WITH_RUNTIME
open class Foo
class Bar : Foo()
@@ -1,5 +1,6 @@
// PARAM_DESCRIPTOR: public fun Bar.foo(): kotlin.Unit defined in root package
// PARAM_TYPES: Bar, Foo, kotlin.Any
// WITH_RUNTIME
open class Foo
class Bar : Foo()
+1 -1
View File
@@ -1,6 +1,6 @@
val a: <caret>Number? = null
// CONTEXT: public abstract fun toDouble(): <ref-caret>Double
// RUNTIME
// RUNTIME_WITH_SOURCES
// REF: (kotlin).Double
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.idea;
import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess;
import com.intellij.testFramework.codeInsight.hierarchy.HierarchyViewTestBase;
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil;
import org.jetbrains.kotlin.test.KotlinTestUtils;
public abstract class KotlinHierarchyViewTestBase extends HierarchyViewTestBase {
@@ -25,10 +26,12 @@ public abstract class KotlinHierarchyViewTestBase extends HierarchyViewTestBase
protected void setUp() throws Exception {
super.setUp();
VfsRootAccess.allowRootAccess(KotlinTestUtils.getHomeDirectory());
ConfigLibraryUtil.configureKotlinRuntime(myModule);
}
@Override
protected void tearDown() throws Exception {
ConfigLibraryUtil.unConfigureKotlinRuntime(myModule);
VfsRootAccess.disallowRootAccess(KotlinTestUtils.getHomeDirectory());
super.tearDown();
}
@@ -73,7 +73,7 @@ public class NavigateFromLibrarySourcesTest: LightCodeInsightFixtureTestCase() {
}
override fun getProjectDescriptor(): LightProjectDescriptor {
return JdkAndMockLibraryProjectDescriptor(PluginTestCaseBase.getTestDataPathBase() + "/decompiler/navigation/fromLibSource", true)
return JdkAndMockLibraryProjectDescriptor(PluginTestCaseBase.getTestDataPathBase() + "/decompiler/navigation/fromLibSource", true, true, false)
}
private fun checkNavigationElement(element: PsiElement, expectedFqName: String) {
@@ -54,7 +54,7 @@ public abstract class AbstractDecompiledTextBaseTest(
if (isAllFilesPresentInTest()) {
return KotlinLightProjectDescriptor.INSTANCE
}
return JdkAndMockLibraryProjectDescriptor(TEST_DATA_PATH + "/" + getTestName(false), false, isJsLibrary)
return JdkAndMockLibraryProjectDescriptor(TEST_DATA_PATH + "/" + getTestName(false), false, false, isJsLibrary)
}
private fun checkThatFileWasParsedCorrectly(clsFile: PsiFile) {
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.asJava.KtLightClass;
import org.jetbrains.kotlin.asJava.KtLightMethod;
import org.jetbrains.kotlin.asJava.LightClassUtil;
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase;
import org.jetbrains.kotlin.idea.test.KotlinLightProjectDescriptor;
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor;
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase;
import org.jetbrains.kotlin.name.SpecialNames;
import org.jetbrains.kotlin.psi.*;
@@ -34,7 +34,7 @@ public class KotlinJavaFacadeTest extends KotlinLightCodeInsightFixtureTestCase
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return KotlinLightProjectDescriptor.INSTANCE;
return KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE;
}
@Override
@@ -39,7 +39,6 @@ import kotlin.CollectionsKt;
import kotlin.StringsKt;
import kotlin.jvm.functions.Function1;
import org.apache.commons.lang.SystemUtils;
import org.codehaus.plexus.util.FileUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.idea.KotlinLightQuickFixTestCase;
@@ -167,23 +166,25 @@ public abstract class AbstractQuickFixTest extends KotlinLightQuickFixTestCase {
}
//endregion
private static void configureRuntimeIfNeeded(@NotNull String beforeFileName) {
private static void configureRuntimeIfNeeded(@NotNull String beforeFileName) throws IOException {
if (beforeFileName.endsWith("JsRuntime.kt")) {
// Without the following line of code subsequent tests with js-runtime will be prone to failure due "outdated stub in index" error.
FileBasedIndex.getInstance().requestRebuild(StubUpdatingIndex.INDEX_ID);
ConfigLibraryUtil.configureKotlinJsRuntimeAndSdk(getModule(), getFullJavaJDK());
}
else if (beforeFileName.endsWith("Runtime.kt")) {
else if (beforeFileName.endsWith("Runtime.kt") ||
InTextDirectivesUtils.isDirectiveDefined(FileUtil.loadFile(new File(beforeFileName)), "WITH_RUNTIME")) {
ConfigLibraryUtil.configureKotlinRuntimeAndSdk(getModule(), getFullJavaJDK());
}
}
private void unConfigureRuntimeIfNeeded(@NotNull String beforeFileName) {
private void unConfigureRuntimeIfNeeded(@NotNull String beforeFileName) throws IOException {
if (beforeFileName.endsWith("JsRuntime.kt")) {
ConfigLibraryUtil.unConfigureKotlinJsRuntimeAndSdk(getModule(), getProjectJDK());
}
else if (beforeFileName.endsWith("Runtime.kt")) {
else if (beforeFileName.endsWith("Runtime.kt") ||
InTextDirectivesUtils.isDirectiveDefined(FileUtil.loadFile(new File(beforeFileName)), "WITH_RUNTIME")) {
ConfigLibraryUtil.unConfigureKotlinRuntimeAndSdk(getModule(), getProjectJDK());
}
}
@@ -28,6 +28,6 @@ public abstract class AbstractReferenceResolveWithLibTest extends AbstractRefere
if (PluginTestCaseBase.isAllFilesPresentTest(getTestName(true))) {
return null;
}
return new JdkAndMockLibraryProjectDescriptor(TEST_DATA_PATH + "/" + getTestName(true) + "Src", false);
return new JdkAndMockLibraryProjectDescriptor(TEST_DATA_PATH + "/" + getTestName(true) + "Src", false, true, false);
}
}
@@ -28,11 +28,15 @@ import com.intellij.openapi.fileEditor.impl.text.TextEditorProvider
import org.jetbrains.kotlin.test.KotlinTestUtils
import org.jetbrains.kotlin.test.InTextDirectivesUtils
import com.intellij.openapi.ui.Queryable.PrintInfo
import com.intellij.testFramework.LightProjectDescriptor
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
import org.jetbrains.kotlin.test.util.configureWithExtraFile
public abstract class AbstractKotlinFileStructureTest : KotlinLightCodeInsightFixtureTestCase() {
override fun getTestDataPath() = PluginTestCaseBase.getTestDataPathBase() + "/structureView/fileStructure"
override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
public fun doTest(path: String) {
myFixture.configureWithExtraFile(path)