diff --git a/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaCodeInsightSanityTest.java b/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaCodeInsightSanityTest.java index 360190a5eed6..02d505109891 100644 --- a/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaCodeInsightSanityTest.java +++ b/java/java-tests/testSrc/com/intellij/java/propertyBased/JavaCodeInsightSanityTest.java @@ -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> 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 actionsOnJavaFiles(Function> 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() { diff --git a/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/CheckHighlighterConsistency.java b/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/CheckHighlighterConsistency.java index 666840142863..2835376aa53b 100644 --- a/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/CheckHighlighterConsistency.java +++ b/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/CheckHighlighterConsistency.java @@ -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 randomEditsWithHighlighterChecks(PsiFile file) { + public static final Function> randomEditsWithHighlighterChecks = file -> { + FileEditorManager.getInstance(file.getProject()).openFile(file.getVirtualFile(), true); return Generator.anyOf(Generator.constant(new CheckHighlighterConsistency(file)), InsertString.asciiInsertions(file), DeleteRange.psiRangeDeletions(file)); - } + }; } diff --git a/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/FileWithActions.java b/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/FileWithActions.java deleted file mode 100644 index 21101638c08f..000000000000 --- a/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/FileWithActions.java +++ /dev/null @@ -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 myActions; - - public FileWithActions(PsiFile file, List 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.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; - } - -} diff --git a/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/MadTestingUtil.java b/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/MadTestingUtil.java index 5ff29a54bfb0..c8f65e891079 100644 --- a/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/MadTestingUtil.java +++ b/platform/testFramework/testSrc/com/intellij/testFramework/propertyBased/MadTestingUtil.java @@ -209,28 +209,9 @@ public class MadTestingUtil { * @return */ @NotNull - public static Generator actionsOnFileContents(CodeInsightTestFixture fixture, String rootPath, - FileFilter fileFilter, - Function> actions) { - Generator 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 commandsOnFileContents(CodeInsightTestFixture fixture, String rootPath, - FileFilter fileFilter, - Function> actions) { + public static Supplier actionsOnFileContents(CodeInsightTestFixture fixture, String rootPath, + FileFilter fileFilter, + Function> actions) { Generator 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()) { diff --git a/python/testSrc/com/intellij/python/propertyBased/PythonCodeInsightSanityTest.java b/python/testSrc/com/intellij/python/propertyBased/PythonCodeInsightSanityTest.java index be6a83142def..3066871265f7 100644 --- a/python/testSrc/com/intellij/python/propertyBased/PythonCodeInsightSanityTest.java +++ b/python/testSrc/com/intellij/python/propertyBased/PythonCodeInsightSanityTest.java @@ -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 actionsOnPyFiles(@NotNull final Function> fileActions, - @NotNull final CodeInsightTestFixture fixture, - @NotNull final String testDataPath) { + private static Supplier actionsOnPyFiles(@NotNull final Function> 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 checker = PropertyChecker.forAll(actionsOnPyFiles(fileActions, fixture, pathAndFixture.first)); + //todo use ImperativeCommand.checkScenarios like in other tests + PropertyChecker 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); }); }