Refactoring: Use generators for highlighting tests

- Store options for test in file
- Change default for namesHighlightingTest
- Combine highlighting and deprecated tests
This commit is contained in:
Nikolay Krasko
2013-09-30 19:54:50 +04:00
parent 62be09df87
commit f09ba64234
23 changed files with 270 additions and 240 deletions
@@ -36,6 +36,9 @@ import org.jetbrains.jet.descriptors.serialization.AbstractDescriptorSerializati
import org.jetbrains.jet.editor.quickDoc.AbstractJetQuickDocProviderTest;
import org.jetbrains.jet.findUsages.AbstractJetFindUsagesTest;
import org.jetbrains.jet.formatter.AbstractJetFormatterTest;
import org.jetbrains.jet.generators.tests.generator.SimpleTestClassModel;
import org.jetbrains.jet.generators.tests.generator.TestClassModel;
import org.jetbrains.jet.generators.tests.generator.TestGenerator;
import org.jetbrains.jet.jvm.compiler.*;
import org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveDescriptorRendererTest;
import org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveNamespaceComparingTest;
@@ -48,7 +51,7 @@ import org.jetbrains.jet.plugin.codeInsight.unwrap.AbstractUnwrapRemoveTest;
import org.jetbrains.jet.plugin.configuration.AbstractConfigureProjectByChangingFileTest;
import org.jetbrains.jet.plugin.folding.AbstractKotlinFoldingTest;
import org.jetbrains.jet.plugin.hierarchy.AbstractHierarchyTest;
import org.jetbrains.jet.plugin.highlighter.AbstractDeprecatedHighlightingTest;
import org.jetbrains.jet.plugin.highlighter.AbstractHighlightingTest;
import org.jetbrains.jet.plugin.intentions.AbstractCodeTransformationTest;
import org.jetbrains.jet.plugin.navigation.JetAbstractGotoSuperTest;
import org.jetbrains.jet.plugin.quickfix.AbstractQuickFixMultiFileTest;
@@ -59,9 +62,6 @@ import org.jetbrains.jet.resolve.AbstractResolveBaseTest;
import org.jetbrains.jet.resolve.AbstractResolveTest;
import org.jetbrains.jet.resolve.AbstractResolveWithLibTest;
import org.jetbrains.jet.safeDelete.AbstractJetSafeDeleteTest;
import org.jetbrains.jet.generators.tests.generator.SimpleTestClassModel;
import org.jetbrains.jet.generators.tests.generator.TestClassModel;
import org.jetbrains.jet.generators.tests.generator.TestGenerator;
import java.io.File;
import java.io.IOException;
@@ -334,9 +334,9 @@ public class GenerateTests {
generateTest(
"idea/tests/",
"DeprecatedHighlightingTestGenerated",
AbstractDeprecatedHighlightingTest.class,
testModel("idea/testData/highlighter/deprecated")
"HighlightingTestGenerated",
AbstractHighlightingTest.class,
testModel("idea/testData/highlighter")
);
generateTest(
@@ -52,18 +52,19 @@ import java.util.List;
import java.util.Set;
public class JetPsiChecker implements Annotator, HighlightRangeExtension {
private static boolean namesHighlightingTest;
private static final Logger LOG = Logger.getInstance(JetPsiChecker.class);
private static boolean isNamesHighlightingEnabled = true;
private HighlightingPassCache passCache = null;
@TestOnly
public static void setNamesHighlightingTest(boolean namesHighlightingTest) {
JetPsiChecker.namesHighlightingTest = namesHighlightingTest;
public static void setNamesHighlightingEnabled(boolean namesHighlightingEnabled) {
isNamesHighlightingEnabled = namesHighlightingEnabled;
}
static boolean isNamesHighlightingEnabled() {
return !ApplicationManager.getApplication().isUnitTestMode() || namesHighlightingTest;
public static boolean isNamesHighlightingEnabled() {
return isNamesHighlightingEnabled;
}
static void highlightName(@NotNull AnnotationHolder holder,
+3 -1
View File
@@ -24,4 +24,6 @@ class <info textAttributesKey="KOTLIN_CLASS">Foo</info>(val <info textAttributes
<info textAttributesKey="KOTLIN_KEYWORD">set</info>(<info textAttributesKey="KOTLIN_PARAMETER">value</info>) {
<info textAttributesKey="KOTLIN_PARAMETER">value</info>
}
}
}
// NO_CHECK_WARNINGS
@@ -15,3 +15,6 @@ fun test() {
class Test(): <warning descr="'test.MyClass' is deprecated. Use A instead">MyClass</warning>() {}
class Test2(param: <warning descr="'test.MyClass' is deprecated. Use A instead">MyClass</warning>) {}
// NO_CHECK_INFOS
// NO_CHECK_WEAK_WARNINGS
@@ -18,4 +18,7 @@ trait MyTrait {
deprecated("Use A instead") class object {
val test: String = ""
}
}
}
// NO_CHECK_INFOS
// NO_CHECK_WEAK_WARNINGS
@@ -15,4 +15,7 @@ class MyClass() {
class object {
deprecated("Use A instead") fun test3() {}
}
}
}
// NO_CHECK_INFOS
// NO_CHECK_WEAK_WARNINGS
+4 -1
View File
@@ -7,4 +7,7 @@ fun test() {
val x2 = MyClass()
<warning descr="'fun get(i: MyClass)' is deprecated. Use A instead">x1[x2]</warning>
}
}
// NO_CHECK_INFOS
// NO_CHECK_WEAK_WARNINGS
@@ -16,4 +16,7 @@ class MyClass() {
deprecated("Use A instead") public val test3: String = ""
[deprecated("Use A instead")] get
}
}
// NO_CHECK_INFOS
// NO_CHECK_WEAK_WARNINGS
+4 -1
View File
@@ -8,4 +8,7 @@ fun test() {
var x3 = MyClass()
x3<warning descr="'fun inc()' is deprecated. Use A instead">++</warning>
x3.i
}
}
// NO_CHECK_INFOS
// NO_CHECK_WEAK_WARNINGS
@@ -6,4 +6,7 @@ deprecated("Use A instead") fun MyRunnable.invoke() {
fun test() {
val m = MyRunnable()
<warning descr="'fun invoke()' is deprecated. Use A instead">m()</warning>
}
}
// NO_CHECK_INFOS
// NO_CHECK_WEAK_WARNINGS
@@ -35,4 +35,7 @@ fun test() {
x1 <warning descr="'fun equals(i: jet.Any?)' is deprecated. Use A instead">==</warning> x2
x1 <warning descr="'fun equals(i: jet.Any?)' is deprecated. Use A instead">!=</warning> x2
x1 <warning descr="'fun compareTo(i: MyClass)' is deprecated. Use A instead">></warning> x2
}
}
// NO_CHECK_INFOS
// NO_CHECK_WEAK_WARNINGS
@@ -19,4 +19,7 @@ class MyClass() {
deprecated("Use A instead") val test3: String = ""
deprecated("Use A instead") var test6: String = ""
}
}
}
// NO_CHECK_INFOS
// NO_CHECK_WEAK_WARNINGS
@@ -16,3 +16,6 @@ fun test() {
}
}
// NO_CHECK_INFOS
// NO_CHECK_WEAK_WARNINGS
@@ -23,4 +23,7 @@ class MyClass() {
}
public var test2: Int = 0
[deprecated("Use A instead")] set
[deprecated("Use A instead")] set
// NO_CHECK_INFOS
// NO_CHECK_WEAK_WARNINGS
@@ -6,4 +6,7 @@ class MyClass(): Base() {
open class Base() {
fun test1() {}
}
}
// NO_CHECK_INFOS
// NO_CHECK_WEAK_WARNINGS
@@ -8,4 +8,7 @@ fun test() {
class Test(): <warning descr="'MyTrait' is deprecated. Use A instead">MyTrait</warning> { }
class Test2(param: <warning descr="'MyTrait' is deprecated. Use A instead">MyTrait</warning>) {}
class Test2(param: <warning descr="'MyTrait' is deprecated. Use A instead">MyTrait</warning>) {}
// NO_CHECK_INFOS
// NO_CHECK_WEAK_WARNINGS
@@ -30,6 +30,6 @@ public abstract class AbstractJetJsCheckerTest extends LightCodeInsightFixtureTe
public void doTest(String filePath) {
myFixture.configureByFile(filePath);
myFixture.checkHighlighting();
myFixture.checkHighlighting(true, false, false);
}
}
@@ -20,6 +20,7 @@ import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
import com.intellij.openapi.projectRoots.Sdk;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.plugin.PluginTestCaseBase;
import org.jetbrains.jet.plugin.highlighter.JetPsiChecker;
public abstract class AbstractJetPsiCheckerTest extends LightDaemonAnalyzerTestCase {
public void doTest(@NotNull String filePath) throws Exception {
@@ -27,9 +28,16 @@ public abstract class AbstractJetPsiCheckerTest extends LightDaemonAnalyzerTestC
}
public void doTestWithInfos(@NotNull String filePath) throws Exception {
doTest(filePath, true, true);
try {
JetPsiChecker.setNamesHighlightingEnabled(false);
doTest(filePath, true, true);
}
finally {
JetPsiChecker.setNamesHighlightingEnabled(true);
}
}
@NotNull
@Override
protected String getTestDataPath() {
return "";
@@ -1,40 +0,0 @@
/*
* 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.highlighter;
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
import com.intellij.openapi.projectRoots.Sdk;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.plugin.PluginTestCaseBase;
public abstract class AbstractDeprecatedHighlightingTest extends LightDaemonAnalyzerTestCase {
@Override
protected Sdk getProjectJDK() {
return PluginTestCaseBase.jdkFromIdeaHome();
}
protected void doTest(String filePath) throws Exception {
doTest(filePath, true, false);
}
@NotNull
@Override
protected String getTestDataPath() {
return "";
}
}
@@ -0,0 +1,50 @@
/*
* 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.highlighter;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.InTextDirectivesUtils;
import org.jetbrains.jet.plugin.JetLightProjectDescriptor;
import java.io.File;
public abstract class AbstractHighlightingTest extends LightCodeInsightFixtureTestCase {
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return JetLightProjectDescriptor.INSTANCE;
}
protected void doTest(String filePath) throws Exception {
String fileText = FileUtil.loadFile(new File(filePath), true);
boolean checkInfos = !InTextDirectivesUtils.isDirectiveDefined(fileText, "// NO_CHECK_INFOS");
boolean checkWeakWarnings = !InTextDirectivesUtils.isDirectiveDefined(fileText, "// NO_CHECK_WEAK_WARNINGS");
boolean checkWarnings = !InTextDirectivesUtils.isDirectiveDefined(fileText, "// NO_CHECK_WARNINGS");
myFixture.configureByFile(filePath);
myFixture.checkHighlighting(checkWarnings, checkInfos, checkWeakWarnings);
}
@NotNull
@Override
protected String getTestDataPath() {
return "";
}
}
@@ -1,104 +0,0 @@
/*
* 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.highlighter;
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.plugin.highlighter.AbstractDeprecatedHighlightingTest;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/testData/highlighter/deprecated")
public class DeprecatedHighlightingTestGenerated extends AbstractDeprecatedHighlightingTest {
public void testAllFilesPresentInDeprecated() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/highlighter/deprecated"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("Class.kt")
public void testClass() throws Exception {
doTest("idea/testData/highlighter/deprecated/Class.kt");
}
@TestMetadata("ClassObject.kt")
public void testClassObject() throws Exception {
doTest("idea/testData/highlighter/deprecated/ClassObject.kt");
}
@TestMetadata("Function.kt")
public void testFunction() throws Exception {
doTest("idea/testData/highlighter/deprecated/Function.kt");
}
@TestMetadata("Get.kt")
public void testGet() throws Exception {
doTest("idea/testData/highlighter/deprecated/Get.kt");
}
@TestMetadata("Getter.kt")
public void testGetter() throws Exception {
doTest("idea/testData/highlighter/deprecated/Getter.kt");
}
@TestMetadata("Inc.kt")
public void testInc() throws Exception {
doTest("idea/testData/highlighter/deprecated/Inc.kt");
}
@TestMetadata("Invoke.kt")
public void testInvoke() throws Exception {
doTest("idea/testData/highlighter/deprecated/Invoke.kt");
}
@TestMetadata("Operation.kt")
public void testOperation() throws Exception {
doTest("idea/testData/highlighter/deprecated/Operation.kt");
}
@TestMetadata("Property.kt")
public void testProperty() throws Exception {
doTest("idea/testData/highlighter/deprecated/Property.kt");
}
@TestMetadata("RangeTo.kt")
public void testRangeTo() throws Exception {
doTest("idea/testData/highlighter/deprecated/RangeTo.kt");
}
@TestMetadata("Setter.kt")
public void testSetter() throws Exception {
doTest("idea/testData/highlighter/deprecated/Setter.kt");
}
@TestMetadata("SuperCall.kt")
public void testSuperCall() throws Exception {
doTest("idea/testData/highlighter/deprecated/SuperCall.kt");
}
@TestMetadata("Trait.kt")
public void testTrait() throws Exception {
doTest("idea/testData/highlighter/deprecated/Trait.kt");
}
}
@@ -0,0 +1,144 @@
/*
* 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.highlighter;
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.plugin.highlighter.AbstractHighlightingTest;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/testData/highlighter")
@InnerTestClasses({HighlightingTestGenerated.Deprecated.class})
public class HighlightingTestGenerated extends AbstractHighlightingTest {
public void testAllFilesPresentInHighlighter() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/highlighter"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("Functions.kt")
public void testFunctions() throws Exception {
doTest("idea/testData/highlighter/Functions.kt");
}
@TestMetadata("JavaTypes.kt")
public void testJavaTypes() throws Exception {
doTest("idea/testData/highlighter/JavaTypes.kt");
}
@TestMetadata("TypesAndAnnotations.kt")
public void testTypesAndAnnotations() throws Exception {
doTest("idea/testData/highlighter/TypesAndAnnotations.kt");
}
@TestMetadata("Variables.kt")
public void testVariables() throws Exception {
doTest("idea/testData/highlighter/Variables.kt");
}
@TestMetadata("VariablesAsFunctions.kt")
public void testVariablesAsFunctions() throws Exception {
doTest("idea/testData/highlighter/VariablesAsFunctions.kt");
}
@TestMetadata("idea/testData/highlighter/deprecated")
public static class Deprecated extends AbstractHighlightingTest {
public void testAllFilesPresentInDeprecated() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/highlighter/deprecated"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("Class.kt")
public void testClass() throws Exception {
doTest("idea/testData/highlighter/deprecated/Class.kt");
}
@TestMetadata("ClassObject.kt")
public void testClassObject() throws Exception {
doTest("idea/testData/highlighter/deprecated/ClassObject.kt");
}
@TestMetadata("Function.kt")
public void testFunction() throws Exception {
doTest("idea/testData/highlighter/deprecated/Function.kt");
}
@TestMetadata("Get.kt")
public void testGet() throws Exception {
doTest("idea/testData/highlighter/deprecated/Get.kt");
}
@TestMetadata("Getter.kt")
public void testGetter() throws Exception {
doTest("idea/testData/highlighter/deprecated/Getter.kt");
}
@TestMetadata("Inc.kt")
public void testInc() throws Exception {
doTest("idea/testData/highlighter/deprecated/Inc.kt");
}
@TestMetadata("Invoke.kt")
public void testInvoke() throws Exception {
doTest("idea/testData/highlighter/deprecated/Invoke.kt");
}
@TestMetadata("Operation.kt")
public void testOperation() throws Exception {
doTest("idea/testData/highlighter/deprecated/Operation.kt");
}
@TestMetadata("Property.kt")
public void testProperty() throws Exception {
doTest("idea/testData/highlighter/deprecated/Property.kt");
}
@TestMetadata("RangeTo.kt")
public void testRangeTo() throws Exception {
doTest("idea/testData/highlighter/deprecated/RangeTo.kt");
}
@TestMetadata("Setter.kt")
public void testSetter() throws Exception {
doTest("idea/testData/highlighter/deprecated/Setter.kt");
}
@TestMetadata("SuperCall.kt")
public void testSuperCall() throws Exception {
doTest("idea/testData/highlighter/deprecated/SuperCall.kt");
}
@TestMetadata("Trait.kt")
public void testTrait() throws Exception {
doTest("idea/testData/highlighter/deprecated/Trait.kt");
}
}
public static Test suite() {
TestSuite suite = new TestSuite("HighlightingTestGenerated");
suite.addTestSuite(HighlightingTestGenerated.class);
suite.addTestSuite(Deprecated.class);
return suite;
}
}
@@ -1,70 +0,0 @@
/*
* 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.highlighter;
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
import com.intellij.openapi.projectRoots.Sdk;
import org.jetbrains.jet.plugin.PluginTestCaseBase;
import org.jetbrains.jet.plugin.highlighter.JetPsiChecker;
public class NamesHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testTypesAndAnnotations() throws Exception {
doTest();
}
public void testVariables() throws Exception {
doTest();
}
public void testFunctions() throws Exception {
doTest();
}
public void testVariablesAsFunctions() throws Exception {
doTest();
}
public void testJavaTypes() throws Exception {
doTest();
}
@Override
protected Sdk getProjectJDK() {
return PluginTestCaseBase.jdkFromIdeaHome();
}
private void doTest() throws Exception {
doTest(getTestName(false) + ".kt", false, true);
}
@Override
public void setUp() throws Exception {
super.setUp();
JetPsiChecker.setNamesHighlightingTest(true);
}
@Override
public void tearDown() throws Exception {
JetPsiChecker.setNamesHighlightingTest(false);
super.tearDown();
}
@Override
protected String getTestDataPath() {
return PluginTestCaseBase.getTestDataPathBase() + "/highlighter/";
}
}