Tests: add some test cases for inheritor search

Refactor inheritor search tests to be generated
This commit is contained in:
Pavel V. Talanov
2017-04-28 17:34:11 +03:00
parent 178e59a6e8
commit 7ef18fe5ba
12 changed files with 145 additions and 23 deletions
@@ -166,6 +166,7 @@ import org.jetbrains.kotlin.resolve.constants.evaluate.AbstractCompileTimeConsta
import org.jetbrains.kotlin.resolve.constraintSystem.AbstractConstraintSystemTest import org.jetbrains.kotlin.resolve.constraintSystem.AbstractConstraintSystemTest
import org.jetbrains.kotlin.samWithReceiver.AbstractSamWithReceiverScriptTest import org.jetbrains.kotlin.samWithReceiver.AbstractSamWithReceiverScriptTest
import org.jetbrains.kotlin.samWithReceiver.AbstractSamWithReceiverTest import org.jetbrains.kotlin.samWithReceiver.AbstractSamWithReceiverTest
import org.jetbrains.kotlin.search.AbstractInheritorsSearchTest
import org.jetbrains.kotlin.serialization.AbstractLocalClassProtoTest import org.jetbrains.kotlin.serialization.AbstractLocalClassProtoTest
import org.jetbrains.kotlin.shortenRefs.AbstractShortenRefsTest import org.jetbrains.kotlin.shortenRefs.AbstractShortenRefsTest
import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.TargetBackend
@@ -551,6 +552,10 @@ fun main(args: Array<String>) {
model("navigation/gotoTestOrCode", pattern = "^(.+)\\.main\\..+\$") model("navigation/gotoTestOrCode", pattern = "^(.+)\\.main\\..+\$")
} }
testClass<AbstractInheritorsSearchTest> {
model("search/inheritance")
}
testClass<AbstractQuickFixMultiFileTest> { testClass<AbstractQuickFixMultiFileTest> {
model("quickfix", pattern = """^(\w+)\.((before\.Main\.\w+)|(test))$""", testMethod = "doTestWithExtraFile") model("quickfix", pattern = """^(\w+)\.((before\.Main\.\w+)|(test))$""", testMethod = "doTestWithExtraFile")
} }
+6
View File
@@ -0,0 +1,6 @@
package a.b
annotation class Anno
// CLASS: java.lang.annotation.Annotation
// SEARCH: class:Anno
+11
View File
@@ -0,0 +1,11 @@
enum class A {
E;
}
// CLASS: java.lang.Enum
// SEARCH: class:A
// IGNORE_CLASSES: java.
// IGNORE_CLASSES: javax.
// IGNORE_CLASSES: sun.
// IGNORE_CLASSES: org.
+12
View File
@@ -0,0 +1,12 @@
package a.b
interface I: J {
}
interface J {
}
// CLASS: a.b.J
// SEARCH: class:I
+7
View File
@@ -0,0 +1,7 @@
object A : B()
open class B {
}
// CLASS: B
// SEARCH: class:A
+9
View File
@@ -0,0 +1,9 @@
class A
// CLASS: java.lang.Object
// SEARCH: class:A
// IGNORE_CLASSES: java.
// IGNORE_CLASSES: javax.
// IGNORE_CLASSES: sun.
// IGNORE_CLASSES: org.
@@ -16,23 +16,15 @@
package org.jetbrains.kotlin.search; package org.jetbrains.kotlin.search;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase; import org.jetbrains.kotlin.idea.test.PluginTestCaseBase;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
public class ClassInheritorsSearchTest extends AbstractSearcherTest { public abstract class AbstractInheritorsSearchTest extends AbstractSearcherTest {
public void doTest(@NotNull String path) throws IOException {
public void testInheritanceFromKotlinClass() throws IOException { checkClassWithDirectives(path);
doTest();
}
public void testInheritanceFromJavaClass() throws IOException {
doTest();
}
private void doTest() throws IOException {
checkClassWithDirectives();
} }
@Override @Override
@@ -59,8 +59,8 @@ public abstract class AbstractSearcherTest extends LightCodeInsightFixtureTestCa
return GlobalSearchScope.projectScope(getProject()); return GlobalSearchScope.projectScope(getProject());
} }
protected void checkResult(Query<?> actual) throws IOException { protected static void checkResult(@NotNull String path, Query<?> actual) throws IOException {
String text = FileUtil.loadFile(new File(getPathToFile()), true); String text = FileUtil.loadFile(new File(path), true);
List<String> classFqnFilters = InTextDirectivesUtils.findListWithPrefixes(text, "// IGNORE_CLASSES: "); List<String> classFqnFilters = InTextDirectivesUtils.findListWithPrefixes(text, "// IGNORE_CLASSES: ");
@@ -87,14 +87,14 @@ public abstract class AbstractSearcherTest extends LightCodeInsightFixtureTestCa
assertOrderedEquals(actualModified, expected); assertOrderedEquals(actualModified, expected);
} }
protected void checkClassWithDirectives() throws IOException { protected void checkClassWithDirectives(@NotNull String path) throws IOException {
myFixture.configureByFile(getFileName()); myFixture.configureByFile(path);
List<String> directives = InTextDirectivesUtils.findListWithPrefixes( List<String> directives = InTextDirectivesUtils.findListWithPrefixes(
FileUtil.loadFile(new File(getPathToFile()), true), "// CLASS: "); FileUtil.loadFile(new File(path), true), "// CLASS: ");
assertFalse("Specify CLASS directive in test file", directives.isEmpty()); assertFalse("Specify CLASS directive in test file", directives.isEmpty());
String superClassName = directives.get(0); String superClassName = directives.get(0);
PsiClass psiClass = getPsiClass(superClassName); PsiClass psiClass = getPsiClass(superClassName);
checkResult(ClassInheritorsSearch.search(psiClass, getProjectScope(), false)); checkResult(path, ClassInheritorsSearch.search(psiClass, getProjectScope(), false));
} }
private static String stringRepresentation(Object member) { private static String stringRepresentation(Object member) {
@@ -84,7 +84,7 @@ public class AnnotatedMembersSearchTest extends AbstractSearcherTest {
PsiBasedClassResolver.Companion.getTrueHits().set(0); PsiBasedClassResolver.Companion.getTrueHits().set(0);
PsiBasedClassResolver.Companion.getFalseHits().set(0); PsiBasedClassResolver.Companion.getFalseHits().set(0);
checkResult(AnnotatedMembersSearch.search(psiClass, getProjectScope())); checkResult(getPathToFile(), AnnotatedMembersSearch.search(psiClass, getProjectScope()));
Integer optimizedTrue = InTextDirectivesUtils.getPrefixedInt(fileText, "// OPTIMIZED_TRUE:"); Integer optimizedTrue = InTextDirectivesUtils.getPrefixedInt(fileText, "// OPTIMIZED_TRUE:");
if (optimizedTrue != null) { if (optimizedTrue != null) {
@@ -34,10 +34,10 @@ class DefinitionsSearchTest : AbstractSearcherTest() {
assertFalse("Specify CLASS directive in test file", directives.isEmpty()) assertFalse("Specify CLASS directive in test file", directives.isEmpty())
val superClassName = directives[0] val superClassName = directives[0]
val psiClass = getPsiClass(superClassName) val psiClass = getPsiClass(superClassName)
checkResult(DefinitionsScopedSearch.search(psiClass)) checkResult(getPathToFile(), DefinitionsScopedSearch.search(psiClass))
val origin = (psiClass as? KtLightClass)?.kotlinOrigin!! val origin = (psiClass as? KtLightClass)?.kotlinOrigin!!
checkResult(DefinitionsScopedSearch.search(origin)) checkResult(getPathToFile(), DefinitionsScopedSearch.search(origin))
} }
override fun getTestDataPath(): String { override fun getTestDataPath(): String {
@@ -0,0 +1,80 @@
/*
* Copyright 2010-2017 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.kotlin.search;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.JUnit3RunnerWithInners;
import org.jetbrains.kotlin.test.KotlinTestUtils;
import org.jetbrains.kotlin.test.TargetBackend;
import org.jetbrains.kotlin.test.TestMetadata;
import org.junit.runner.RunWith;
import java.io.File;
import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/testData/search/inheritance")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public class InheritorsSearchTestGenerated extends AbstractInheritorsSearchTest {
public void testAllFilesPresentInInheritance() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/search/inheritance"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("annotationClass.kt")
public void testAnnotationClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/search/inheritance/annotationClass.kt");
doTest(fileName);
}
@TestMetadata("enum.kt")
public void testEnum() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/search/inheritance/enum.kt");
doTest(fileName);
}
@TestMetadata("interfaces.kt")
public void testInterfaces() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/search/inheritance/interfaces.kt");
doTest(fileName);
}
@TestMetadata("object.kt")
public void testObject() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/search/inheritance/object.kt");
doTest(fileName);
}
@TestMetadata("simpleClass.kt")
public void testSimpleClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/search/inheritance/simpleClass.kt");
doTest(fileName);
}
@TestMetadata("testInheritanceFromJavaClass.kt")
public void testTestInheritanceFromJavaClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/search/inheritance/testInheritanceFromJavaClass.kt");
doTest(fileName);
}
@TestMetadata("testInheritanceFromKotlinClass.kt")
public void testTestInheritanceFromKotlinClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/search/inheritance/testInheritanceFromKotlinClass.kt");
doTest(fileName);
}
}
@@ -51,7 +51,7 @@ public class JUnitMembersSearcherTest extends AbstractSearcherTest {
} }
private void doJUnit3test() throws IOException { private void doJUnit3test() throws IOException {
checkClassWithDirectives(); checkClassWithDirectives(getPathToFile());
} }
private void doJUnit4test() throws IOException { private void doJUnit4test() throws IOException {
@@ -61,7 +61,7 @@ public class JUnitMembersSearcherTest extends AbstractSearcherTest {
assertFalse("Specify ANNOTATION directive in test file", directives.isEmpty()); assertFalse("Specify ANNOTATION directive in test file", directives.isEmpty());
String annotationClassName = directives.get(0); String annotationClassName = directives.get(0);
PsiClass psiClass = getPsiClass(annotationClassName); PsiClass psiClass = getPsiClass(annotationClassName);
checkResult(AnnotatedMembersSearch.search(psiClass, getProjectScope())); checkResult(getPathToFile(), AnnotatedMembersSearch.search(psiClass, getProjectScope()));
} }
@Override @Override