mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
migrate all sanity tests to ImperativeCommand API
This commit is contained in:
+5
-3
@@ -60,7 +60,8 @@ public class JavaCodeInsightSanityTest extends LightCodeInsightFixtureTestCase {
|
||||
InvokeCompletion.completions(file, new JavaCompletionPolicy()),
|
||||
Generator.constant(new StripTestDataMarkup(file)),
|
||||
DeleteRange.psiRangeDeletions(file));
|
||||
ImperativeCommand.checkScenarios(actionsOnJavaFiles(fileActions));
|
||||
ImperativeCommand.checkScenarios(
|
||||
actionsOnJavaFiles(fileActions));
|
||||
}
|
||||
|
||||
public void testPreserveComments() {
|
||||
@@ -71,7 +72,8 @@ public class JavaCodeInsightSanityTest extends LightCodeInsightFixtureTestCase {
|
||||
Function<PsiFile, Generator<? extends MadTestingAction>> fileActions = file ->
|
||||
Generator.anyOf(InvokeIntention.randomIntentions(file, new JavaCommentingStrategy()),
|
||||
InsertLineComment.insertComment(file, "//simple end comment\n"));
|
||||
ImperativeCommand.checkScenarios(actionsOnJavaFiles(fileActions));
|
||||
ImperativeCommand.checkScenarios(
|
||||
actionsOnJavaFiles(fileActions));
|
||||
}
|
||||
finally {
|
||||
AbstractJavaFormatterTest.getJavaSettings().ENABLE_JAVADOC_FORMATTING = oldSettings;
|
||||
@@ -80,7 +82,7 @@ public class JavaCodeInsightSanityTest extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
@NotNull
|
||||
private Supplier<ImperativeCommand> actionsOnJavaFiles(Function<PsiFile, Generator<? extends MadTestingAction>> fileActions) {
|
||||
return MadTestingUtil.commandsOnFileContents(myFixture, PathManager.getHomePath(), f -> f.getName().endsWith(".java"), fileActions);
|
||||
return MadTestingUtil.actionsOnFileContents(myFixture, PathManager.getHomePath(), f -> f.getName().endsWith(".java"), fileActions);
|
||||
}
|
||||
|
||||
public void testReparse() {
|
||||
|
||||
+6
-8
@@ -23,8 +23,10 @@ import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.testFramework.LexerTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.junit.Assert;
|
||||
import org.jetbrains.jetCheck.Generator;
|
||||
import org.junit.Assert;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Checks that incrementally updated editor highlighter produces the same result as it would
|
||||
@@ -78,16 +80,12 @@ public class CheckHighlighterConsistency implements MadTestingAction {
|
||||
return tokens.toString();
|
||||
}
|
||||
|
||||
public static boolean runActionsInEditor(FileWithActions actions) {
|
||||
FileEditorManager.getInstance(actions.getPsiFile().getProject()).openFile(actions.getPsiFile().getVirtualFile(), true);
|
||||
return actions.runActions();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Generator<MadTestingAction> randomEditsWithHighlighterChecks(PsiFile file) {
|
||||
public static final Function<PsiFile, Generator<? extends MadTestingAction>> randomEditsWithHighlighterChecks = file -> {
|
||||
FileEditorManager.getInstance(file.getProject()).openFile(file.getVirtualFile(), true);
|
||||
return Generator.anyOf(Generator.constant(new CheckHighlighterConsistency(file)),
|
||||
InsertString.asciiInsertions(file),
|
||||
DeleteRange.psiRangeDeletions(file));
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
-61
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-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 com.intellij.testFramework.propertyBased;
|
||||
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.testFramework.RunAll;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class FileWithActions {
|
||||
private final PsiFile myFile;
|
||||
private final List<? extends MadTestingAction> myActions;
|
||||
|
||||
public FileWithActions(PsiFile file, List<? extends MadTestingAction> actions) {
|
||||
myFile = file;
|
||||
myActions = actions;
|
||||
}
|
||||
|
||||
public PsiFile getPsiFile() {
|
||||
return myFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return myFile.getVirtualFile().getPath() + "[" + StringUtil.join(myActions, a -> "\n " + a, "") + "\n]";
|
||||
}
|
||||
|
||||
public String getConstructionCode() {
|
||||
String path = myFile.getVirtualFile().getPath();
|
||||
String actions = StringUtil.join(myActions, a -> "new " + a.getClass().getSimpleName() + "(" + a.getConstructorArguments() + ")", ",\n ");
|
||||
return "PsiFile file = myFixture.addFileToProject(\"" + StringUtil.trimStart(path, "/src/") + "\", fileText);\n" +
|
||||
"new FileWithActions(file, Arrays.<MadTestingAction>asList(\n " + actions + "\n)).runActions();";
|
||||
}
|
||||
|
||||
public boolean runActions() {
|
||||
Project project = myFile.getProject();
|
||||
new RunAll(() -> MadTestingUtil.changeAndRevert(project, () -> MadTestingAction.runActions(myActions)),
|
||||
() -> WriteAction.run(() -> myFile.getVirtualFile().delete(this))).run();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+4
-23
@@ -209,28 +209,9 @@ public class MadTestingUtil {
|
||||
* @return
|
||||
*/
|
||||
@NotNull
|
||||
public static Generator<FileWithActions> actionsOnFileContents(CodeInsightTestFixture fixture, String rootPath,
|
||||
FileFilter fileFilter,
|
||||
Function<PsiFile, Generator<? extends MadTestingAction>> actions) {
|
||||
Generator<File> randomFiles = randomFiles(rootPath, fileFilter);
|
||||
return randomFiles.flatMap(ioFile -> {
|
||||
VirtualFile vFile = copyFileToProject(ioFile, fixture, rootPath);
|
||||
PsiDocumentManager.getInstance(fixture.getProject()).commitAllDocuments();
|
||||
PsiFile file = PsiManager.getInstance(fixture.getProject()).findFile(vFile);
|
||||
if (file instanceof PsiBinaryFile || file instanceof PsiPlainTextFile) {
|
||||
System.err.println("Can't check " + vFile + " due to incorrect file type: " + file + " of " + file.getClass());
|
||||
// no operations, but the just created file needs to be deleted (in FileWithActions#runActions)
|
||||
// todo a side-effect-free generator
|
||||
return Generator.constant(new FileWithActions(file, Collections.emptyList()));
|
||||
}
|
||||
return Generator.nonEmptyLists(actions.apply(file)).map(a -> new FileWithActions(file, a));
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Supplier<ImperativeCommand> commandsOnFileContents(CodeInsightTestFixture fixture, String rootPath,
|
||||
FileFilter fileFilter,
|
||||
Function<PsiFile, Generator<? extends MadTestingAction>> actions) {
|
||||
public static Supplier<ImperativeCommand> actionsOnFileContents(CodeInsightTestFixture fixture, String rootPath,
|
||||
FileFilter fileFilter,
|
||||
Function<PsiFile, Generator<? extends MadTestingAction>> actions) {
|
||||
Generator<File> randomFiles = randomFiles(rootPath, fileFilter);
|
||||
return () -> env -> new RunAll()
|
||||
.append(() -> {
|
||||
@@ -241,7 +222,7 @@ public class MadTestingUtil {
|
||||
System.err.println("Can't check " + vFile + " due to incorrect file type: " + psiFile + " of " + psiFile.getClass());
|
||||
return;
|
||||
}
|
||||
env.executeCommands(actions.apply(psiFile));
|
||||
env.executeCommands(Generator.from(data -> data.generate(actions.apply(fixture.getPsiManager().findFile(vFile)))));
|
||||
})
|
||||
.append(() -> WriteAction.run(() -> {
|
||||
for (VirtualFile file : fixture.getTempDirFixture().getFile("").getChildren()) {
|
||||
|
||||
@@ -25,14 +25,17 @@ import com.intellij.testFramework.propertyBased.*;
|
||||
import com.jetbrains.env.PyEnvTestCase;
|
||||
import com.jetbrains.env.PyExecutionFixtureTestTask;
|
||||
import org.jetbrains.jetCheck.Generator;
|
||||
import org.jetbrains.jetCheck.ImperativeCommand;
|
||||
import org.jetbrains.jetCheck.PropertyChecker;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jetCheck.Scenario;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* @author Ilya.Kazakevich
|
||||
@@ -67,16 +70,15 @@ public class PythonCodeInsightSanityTest extends PyEnvTestCase {
|
||||
public void testReparse() {
|
||||
runSanityTest(pathAndFixture -> {
|
||||
final CodeInsightTestFixture fixture = pathAndFixture.second;
|
||||
PropertyChecker.forAll(actionsOnPyFiles(MadTestingUtil::randomEditsWithReparseChecks, fixture,
|
||||
new File(fixture.getTestDataPath(), "sanity").getPath()))
|
||||
.shouldHold(FileWithActions::runActions);
|
||||
ImperativeCommand.checkScenarios(actionsOnPyFiles(MadTestingUtil::randomEditsWithReparseChecks, fixture,
|
||||
new File(fixture.getTestDataPath(), "sanity").getPath()));
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Generator<FileWithActions> actionsOnPyFiles(@NotNull final Function<PsiFile, Generator<? extends MadTestingAction>> fileActions,
|
||||
@NotNull final CodeInsightTestFixture fixture,
|
||||
@NotNull final String testDataPath) {
|
||||
private static Supplier<ImperativeCommand> actionsOnPyFiles(@NotNull final Function<PsiFile, Generator<? extends MadTestingAction>> fileActions,
|
||||
@NotNull final CodeInsightTestFixture fixture,
|
||||
@NotNull final String testDataPath) {
|
||||
|
||||
return MadTestingUtil.actionsOnFileContents(fixture, testDataPath, f -> f.getName().endsWith(".py"), fileActions);
|
||||
}
|
||||
@@ -91,11 +93,12 @@ public class PythonCodeInsightSanityTest extends PyEnvTestCase {
|
||||
Generator.constant(new StripTestDataMarkup(file)),
|
||||
DeleteRange.psiRangeDeletions(file));
|
||||
|
||||
PropertyChecker<FileWithActions> checker = PropertyChecker.forAll(actionsOnPyFiles(fileActions, fixture, pathAndFixture.first));
|
||||
//todo use ImperativeCommand.checkScenarios like in other tests
|
||||
PropertyChecker<Scenario> checker = PropertyChecker.forAll(ImperativeCommand.scenarios(actionsOnPyFiles(fileActions, fixture, pathAndFixture.first)));
|
||||
if (seedToRepeat != null) {
|
||||
checker = checker.recheckingIteration(seedToRepeat.first, seedToRepeat.second);
|
||||
}
|
||||
checker.shouldHold(FileWithActions::runActions);
|
||||
checker.shouldHold(Scenario::ensureSuccessful);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user