Refactored multi-file quickfix test to generated tests framework.
This commit is contained in:
@@ -32,6 +32,7 @@ import org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveDescriptorRenderer
|
||||
import org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveNamespaceComparingTest;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.AbstractLazyResolveTest;
|
||||
import org.jetbrains.jet.plugin.highlighter.AbstractDeprecatedHighlightingTest;
|
||||
import org.jetbrains.jet.plugin.quickfix.AbstractQuickFixMultiFileTest;
|
||||
import org.jetbrains.jet.plugin.quickfix.AbstractQuickFixTest;
|
||||
import org.jetbrains.jet.test.generator.SimpleTestClassModel;
|
||||
import org.jetbrains.jet.test.generator.TestClassModel;
|
||||
@@ -209,6 +210,13 @@ public class GenerateTests {
|
||||
new SimpleTestClassModel(new File("idea/testData/quickfix"), true, Pattern.compile("^before(\\w+)\\.kt$"), "doTest")
|
||||
);
|
||||
|
||||
generateTest(
|
||||
"idea/tests/",
|
||||
"QuickFixMultiFileTestGenerated",
|
||||
AbstractQuickFixMultiFileTest.class,
|
||||
new SimpleTestClassModel(new File("idea/testData/quickfix"), true, Pattern.compile("^(\\w+)\\.before\\.Main\\.kt$"), "doTestWithExtraFile")
|
||||
);
|
||||
|
||||
generateTest(
|
||||
"idea/tests/",
|
||||
"DeprecatedHighlightingTestGenerated",
|
||||
|
||||
@@ -24,11 +24,14 @@ import com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import junit.framework.ComparisonFailure;
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -47,21 +50,35 @@ public abstract class AbstractQuickFixMultiFileTest extends DaemonAnalyzerTestCa
|
||||
return texts;
|
||||
}
|
||||
|
||||
public void doTest() throws Exception {
|
||||
configureByFiles(null, getTestFileNames().toArray(new String[1]));
|
||||
protected void doTestWithoutExtraFile(String beforeFileName) throws Exception {
|
||||
doTest(beforeFileName, false);
|
||||
}
|
||||
|
||||
protected void doTestWithExtraFile(String beforeFileName) throws Exception {
|
||||
doTest(beforeFileName, true);
|
||||
}
|
||||
|
||||
private void doTest(final String beforeFileName, boolean withExtraFile) throws Exception {
|
||||
if (withExtraFile) {
|
||||
configureByFiles(null, beforeFileName, beforeFileName.replace(".Main.", ".Data.Sample."));
|
||||
}
|
||||
else {
|
||||
configureByFiles(null, beforeFileName);
|
||||
}
|
||||
|
||||
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
final Pair<String, Boolean> pair = LightQuickFixTestCase.parseActionHint(getFile(), loadFile(getFile().getName()));
|
||||
final Pair<String, Boolean> pair = LightQuickFixTestCase.parseActionHint(
|
||||
getFile(),FileUtil.loadFile(new File(getTestDataPath() + beforeFileName)));
|
||||
final String text = pair.getFirst();
|
||||
|
||||
final boolean actionShouldBeAvailable = pair.getSecond();
|
||||
|
||||
QuickFixActionsUtils.checkForUnexpectedErrors((JetFile) getFile());
|
||||
|
||||
doAction(text, actionShouldBeAvailable, getTestDataPath());
|
||||
doAction(text, actionShouldBeAvailable, beforeFileName);
|
||||
}
|
||||
catch (ComparisonFailure e) {
|
||||
throw e;
|
||||
@@ -110,15 +127,11 @@ public abstract class AbstractQuickFixMultiFileTest extends DaemonAnalyzerTestCa
|
||||
}
|
||||
}
|
||||
|
||||
checkResultByFile(getCheckFileName());
|
||||
checkResultByFile(testFullPath.replace(".before.Main.", ".after."));
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract String getCheckFileName();
|
||||
|
||||
protected abstract List<String> getTestFileNames();
|
||||
|
||||
protected List<IntentionAction> getAvailableActions() {
|
||||
private List<IntentionAction> getAvailableActions() {
|
||||
doHighlighting();
|
||||
return LightQuickFixTestCase.getAvailableActions(getEditor(), getFile());
|
||||
}
|
||||
@@ -127,4 +140,9 @@ public abstract class AbstractQuickFixMultiFileTest extends DaemonAnalyzerTestCa
|
||||
protected Sdk getTestProjectJdk() {
|
||||
return PluginTestCaseBase.jdkFromIdeaHome();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JetTestCaseBuilder.getHomeDirectory() + "/";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,89 +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.quickfix;
|
||||
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class AutoImportFixTest extends AbstractQuickFixMultiFileTest {
|
||||
|
||||
public void testClassImport() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testExtensionFunctionImport() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testFunctionImport() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testImportInFirstPartInQualifiedExpression() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testImportInFirstPartInUserType() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNoImportForFunInQualifiedNotFirst() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNoImportForPrivateClass() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNoImportInImports() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNoImportInQualifiedExpressionNotFirst() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNoImportInQualifiedUserTypeNotFirst() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNoImportInSafeQualifiedExpressionNotFirst() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testPackageClass() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCheckFileName() {
|
||||
return getTestName(true) + ".after.kt";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getTestFileNames() {
|
||||
return Arrays.asList(getTestName(true) + ".before.Main.kt",
|
||||
getTestName(true) + ".before.data.Sample.kt");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JetTestCaseBuilder.getHomeDirectory() + "/idea/testData/quickfix/autoImports/";
|
||||
}
|
||||
}
|
||||
@@ -22,9 +22,6 @@ import com.intellij.testFramework.PsiTestUtil;
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
import org.jetbrains.jet.testing.LocalFileSystemUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class FinalJavaSupertypeTest extends AbstractQuickFixMultiFileTest {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@@ -38,17 +35,7 @@ public class FinalJavaSupertypeTest extends AbstractQuickFixMultiFileTest {
|
||||
final VirtualFile rootDir = PsiTestUtil.createTestProjectStructure(myProject, myModule, path, myFilesToDelete, false);
|
||||
addSourceContentToRoots(myModule, rootDir);
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
doTest();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCheckFileName() {
|
||||
throw new IllegalStateException("This test is to check that quickfix is not available, so no check file is needed.");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getTestFileNames() {
|
||||
return Arrays.asList(getTestName(false) + ".before.kt");
|
||||
doTestWithoutExtraFile(getTestName(false) + ".before.kt");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
* 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.quickfix;
|
||||
|
||||
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.quickfix.AbstractQuickFixMultiFileTest;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@TestMetadata("idea/testData/quickfix")
|
||||
@InnerTestClasses({QuickFixMultiFileTestGenerated.AddStarProjections.class, QuickFixMultiFileTestGenerated.AutoImports.class, QuickFixMultiFileTestGenerated.Modifiers.class, QuickFixMultiFileTestGenerated.TypeImports.class, QuickFixMultiFileTestGenerated.Variables.class, })
|
||||
public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTest {
|
||||
public void testAllFilesPresentInQuickfix() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix"), Pattern.compile("^(\\w+)\\.before\\.Main\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/addStarProjections")
|
||||
@InnerTestClasses({})
|
||||
public static class AddStarProjections extends AbstractQuickFixMultiFileTest {
|
||||
public void testAllFilesPresentInAddStarProjections() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/addStarProjections"), Pattern.compile("^(\\w+)\\.before\\.Main\\.kt$"), true);
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
TestSuite suite = new TestSuite("AddStarProjections");
|
||||
suite.addTestSuite(AddStarProjections.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/autoImports")
|
||||
public static class AutoImports extends AbstractQuickFixMultiFileTest {
|
||||
public void testAllFilesPresentInAutoImports() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/autoImports"), Pattern.compile("^(\\w+)\\.before\\.Main\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("classImport.before.Main.kt")
|
||||
public void testClassImport() throws Exception {
|
||||
doTestWithExtraFile("idea/testData/quickfix/autoImports/classImport.before.Main.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("extensionFunctionImport.before.Main.kt")
|
||||
public void testExtensionFunctionImport() throws Exception {
|
||||
doTestWithExtraFile("idea/testData/quickfix/autoImports/extensionFunctionImport.before.Main.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("functionImport.before.Main.kt")
|
||||
public void testFunctionImport() throws Exception {
|
||||
doTestWithExtraFile("idea/testData/quickfix/autoImports/functionImport.before.Main.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("importInFirstPartInQualifiedExpression.before.Main.kt")
|
||||
public void testImportInFirstPartInQualifiedExpression() throws Exception {
|
||||
doTestWithExtraFile("idea/testData/quickfix/autoImports/importInFirstPartInQualifiedExpression.before.Main.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("importInFirstPartInUserType.before.Main.kt")
|
||||
public void testImportInFirstPartInUserType() throws Exception {
|
||||
doTestWithExtraFile("idea/testData/quickfix/autoImports/importInFirstPartInUserType.before.Main.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("noImportForFunInQualifiedNotFirst.before.Main.kt")
|
||||
public void testNoImportForFunInQualifiedNotFirst() throws Exception {
|
||||
doTestWithExtraFile("idea/testData/quickfix/autoImports/noImportForFunInQualifiedNotFirst.before.Main.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("noImportForPrivateClass.before.Main.kt")
|
||||
public void testNoImportForPrivateClass() throws Exception {
|
||||
doTestWithExtraFile("idea/testData/quickfix/autoImports/noImportForPrivateClass.before.Main.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("noImportInImports.before.Main.kt")
|
||||
public void testNoImportInImports() throws Exception {
|
||||
doTestWithExtraFile("idea/testData/quickfix/autoImports/noImportInImports.before.Main.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("noImportInQualifiedExpressionNotFirst.before.Main.kt")
|
||||
public void testNoImportInQualifiedExpressionNotFirst() throws Exception {
|
||||
doTestWithExtraFile("idea/testData/quickfix/autoImports/noImportInQualifiedExpressionNotFirst.before.Main.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("noImportInQualifiedUserTypeNotFirst.before.Main.kt")
|
||||
public void testNoImportInQualifiedUserTypeNotFirst() throws Exception {
|
||||
doTestWithExtraFile("idea/testData/quickfix/autoImports/noImportInQualifiedUserTypeNotFirst.before.Main.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("noImportInSafeQualifiedExpressionNotFirst.before.Main.kt")
|
||||
public void testNoImportInSafeQualifiedExpressionNotFirst() throws Exception {
|
||||
doTestWithExtraFile("idea/testData/quickfix/autoImports/noImportInSafeQualifiedExpressionNotFirst.before.Main.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("packageClass.before.Main.kt")
|
||||
public void testPackageClass() throws Exception {
|
||||
doTestWithExtraFile("idea/testData/quickfix/autoImports/packageClass.before.Main.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/modifiers")
|
||||
@InnerTestClasses({Modifiers.FinalSupertype.class})
|
||||
public static class Modifiers extends AbstractQuickFixMultiFileTest {
|
||||
public void testAllFilesPresentInModifiers() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/modifiers"), Pattern.compile("^(\\w+)\\.before\\.Main\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/modifiers/finalSupertype")
|
||||
@InnerTestClasses({FinalSupertype.FinalJavaSupertype.class})
|
||||
public static class FinalSupertype extends AbstractQuickFixMultiFileTest {
|
||||
public void testAllFilesPresentInFinalSupertype() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/modifiers/finalSupertype"), Pattern.compile("^(\\w+)\\.before\\.Main\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/modifiers/finalSupertype/finalJavaSupertype")
|
||||
@InnerTestClasses({FinalJavaSupertype.JavaCode.class, })
|
||||
public static class FinalJavaSupertype extends AbstractQuickFixMultiFileTest {
|
||||
public void testAllFilesPresentInFinalJavaSupertype() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/modifiers/finalSupertype/finalJavaSupertype"), Pattern.compile("^(\\w+)\\.before\\.Main\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/modifiers/finalSupertype/finalJavaSupertype/javaCode")
|
||||
@InnerTestClasses({})
|
||||
public static class JavaCode extends AbstractQuickFixMultiFileTest {
|
||||
public void testAllFilesPresentInJavaCode() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/modifiers/finalSupertype/finalJavaSupertype/javaCode"), Pattern.compile("^(\\w+)\\.before\\.Main\\.kt$"), true);
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
TestSuite suite = new TestSuite("JavaCode");
|
||||
suite.addTestSuite(JavaCode.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
TestSuite suite = new TestSuite("FinalJavaSupertype");
|
||||
suite.addTestSuite(FinalJavaSupertype.class);
|
||||
suite.addTest(JavaCode.innerSuite());
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
TestSuite suite = new TestSuite("FinalSupertype");
|
||||
suite.addTestSuite(FinalSupertype.class);
|
||||
suite.addTest(FinalJavaSupertype.innerSuite());
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
TestSuite suite = new TestSuite("Modifiers");
|
||||
suite.addTestSuite(Modifiers.class);
|
||||
suite.addTest(FinalSupertype.innerSuite());
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/typeImports")
|
||||
public static class TypeImports extends AbstractQuickFixMultiFileTest {
|
||||
public void testAllFilesPresentInTypeImports() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/typeImports"), Pattern.compile("^(\\w+)\\.before\\.Main\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("importFromAnotherFile.before.Main.kt")
|
||||
public void testImportFromAnotherFile() throws Exception {
|
||||
doTestWithExtraFile("idea/testData/quickfix/typeImports/importFromAnotherFile.before.Main.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/variables")
|
||||
@InnerTestClasses({})
|
||||
public static class Variables extends AbstractQuickFixMultiFileTest {
|
||||
public void testAllFilesPresentInVariables() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/quickfix/variables"), Pattern.compile("^(\\w+)\\.before\\.Main\\.kt$"), true);
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
TestSuite suite = new TestSuite("Variables");
|
||||
suite.addTestSuite(Variables.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite("QuickFixMultiFileTestGenerated");
|
||||
suite.addTestSuite(QuickFixMultiFileTestGenerated.class);
|
||||
suite.addTest(AddStarProjections.innerSuite());
|
||||
suite.addTestSuite(AutoImports.class);
|
||||
suite.addTest(Modifiers.innerSuite());
|
||||
suite.addTestSuite(TypeImports.class);
|
||||
suite.addTest(Variables.innerSuite());
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
@@ -1,167 +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.quickfix;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixTestCase;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FilenameFilter;
|
||||
import java.util.*;
|
||||
|
||||
public class QuickFixMultifileTest extends AbstractQuickFixMultiFileTest {
|
||||
|
||||
public final static String MAIN_SUBSTRING = ".Main";
|
||||
public final static String DATA_SUBSTRING = ".Data";
|
||||
|
||||
private final String dataPath;
|
||||
private final String name;
|
||||
|
||||
public QuickFixMultifileTest(String dataPath, String name) {
|
||||
this.dataPath = dataPath;
|
||||
this.name = name;
|
||||
|
||||
setName("doTest");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCheckFileName() {
|
||||
return name.replace("before", "after").replace(MAIN_SUBSTRING, "") + ".kt";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getTestFileNames() {
|
||||
return getFileNames(getTestFiles());
|
||||
}
|
||||
|
||||
protected List<File> getTestFiles() {
|
||||
File dir = new File(getTestDataPath());
|
||||
|
||||
assertTrue("Main file should contain .Main. substring", name.contains(MAIN_SUBSTRING));
|
||||
final String testPrefix = name.replace(MAIN_SUBSTRING, "");
|
||||
|
||||
// Files of single test
|
||||
FilenameFilter resultFilter = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File file, String s) {
|
||||
return s.contains(testPrefix) && !s.contains("after");
|
||||
}
|
||||
};
|
||||
|
||||
List<File> allTestFiles = Arrays.asList(dir.listFiles(resultFilter));
|
||||
|
||||
final Collection<File> mainFiles = Collections2.filter(allTestFiles, new Predicate<File>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable File file) {
|
||||
return file != null && file.getName().contains(MAIN_SUBSTRING);
|
||||
}
|
||||
});
|
||||
|
||||
assertTrue("No main file for test in " + dir, mainFiles.size() > 0);
|
||||
assertTrue("Too many main files for the test in " + dir, mainFiles.size() <= 1);
|
||||
|
||||
final Collection<File> dataFiles = Collections2.filter(allTestFiles, new Predicate<File>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable File file) {
|
||||
return file != null && file.getName().contains(DATA_SUBSTRING);
|
||||
}
|
||||
});
|
||||
|
||||
final ArrayList<File> fileResult = new ArrayList<File>(mainFiles);
|
||||
fileResult.addAll(dataFiles);
|
||||
|
||||
return fileResult;
|
||||
}
|
||||
|
||||
protected static List<String> getFileNames(List<File> files) {
|
||||
return Lists.newArrayList(Collections2.transform(files, new Function<File, String>() {
|
||||
@Override
|
||||
public String apply(File file) {
|
||||
return file.getName();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
protected List<IntentionAction> getAvailableActions() {
|
||||
doHighlighting();
|
||||
return LightQuickFixTestCase.getAvailableActions(getEditor(), getFile());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "test" + name.replaceFirst(name.substring(0, 1), name.substring(0, 1).toUpperCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return PluginTestCaseBase.getTestDataPathBase() + "/quickfix/" + dataPath + "/";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getTestProjectJdk() {
|
||||
return PluginTestCaseBase.jdkFromIdeaHome();
|
||||
}
|
||||
|
||||
public static boolean isMainFile(String fileName) {
|
||||
return fileName.contains(MAIN_SUBSTRING);
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite();
|
||||
|
||||
FilenameFilter multifileFileNameFilter = new FilenameFilter() {
|
||||
@Override
|
||||
public boolean accept(File file, String s) {
|
||||
return s.startsWith("before") && isMainFile(s);
|
||||
}
|
||||
};
|
||||
|
||||
JetTestCaseBuilder.NamedTestFactory multiFileNamedTestFactory = new JetTestCaseBuilder.NamedTestFactory() {
|
||||
@NotNull
|
||||
@Override
|
||||
public Test createTest(@NotNull String dataPath, @NotNull String name, @NotNull File file) {
|
||||
return new QuickFixMultifileTest(dataPath, name);
|
||||
}
|
||||
};
|
||||
|
||||
File dir = new File(getTestDataPathBase());
|
||||
List<String> subDirs = Arrays.asList(dir.list());
|
||||
Collections.sort(subDirs);
|
||||
for (String subDirName : subDirs) {
|
||||
final TestSuite multiFileTestSuite = JetTestCaseBuilder.suiteForDirectory(getTestDataPathBase(), subDirName, true, multifileFileNameFilter, multiFileNamedTestFactory);
|
||||
if (multiFileTestSuite.countTestCases() != 0) {
|
||||
suite.addTest(multiFileTestSuite);
|
||||
}
|
||||
}
|
||||
return suite;
|
||||
}
|
||||
|
||||
public static String getTestDataPathBase() {
|
||||
return JetTestCaseBuilder.getHomeDirectory() + "/idea/testData/quickfix/";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user