From e54263b32d9c27cdeddda296ef3ab5d720887a1e Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Fri, 11 Aug 2017 01:20:11 +0300 Subject: [PATCH] IndexOutOfRange test added --- .../PythonCodeInsightSanityTest.java | 48 ++++++++++++++----- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/python/testSrc/com/intellij/python/propertyBased/PythonCodeInsightSanityTest.java b/python/testSrc/com/intellij/python/propertyBased/PythonCodeInsightSanityTest.java index 37a3cd80f096..11cbedc50816 100644 --- a/python/testSrc/com/intellij/python/propertyBased/PythonCodeInsightSanityTest.java +++ b/python/testSrc/com/intellij/python/propertyBased/PythonCodeInsightSanityTest.java @@ -26,6 +26,7 @@ import com.jetbrains.env.PyExecutionFixtureTestTask; import jetCheck.Generator; import jetCheck.PropertyChecker; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.junit.Test; import java.io.File; @@ -38,20 +39,27 @@ import java.util.function.Function; @SkipSlowTestLocally public class PythonCodeInsightSanityTest extends PyEnvTestCase { + /** + * When this test fail please record its rechecking seed and create stable test providing it to {@link #runActivity(Pair)} + */ @Test public void testRandomActivity() { - runSanityTest(pathAndFixture -> { - final CodeInsightTestFixture fixture = pathAndFixture.second; - MadTestingUtil.enableAllInspections(fixture.getProject(), fixture.getProject()); - Function> fileActions = file -> - Generator.anyOf(InvokeIntention.randomIntentions(file, new IntentionPolicy()), - InvokeCompletion.completions(file, new CompletionPolicy()), - Generator.constant(new StripTestDataMarkup(file)), - DeleteRange.psiRangeDeletions(file)); + runActivity(null); + } - PropertyChecker.forAll(actionsOnPyFiles(fileActions, fixture, pathAndFixture.first)) - .shouldHold(FileWithActions::runActions); - }); + /** + * To be fixed by {@link com.jetbrains.python.codeInsight.intentions.PyAnnotateTypesIntention} author @traff + * Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 36 + * at java.lang.String.substring(String.java:1963) + * at com.intellij.codeInsight.template.TemplateBuilderImpl.buildTemplate(TemplateBuilderImpl.java:221) + * at com.intellij.codeInsight.template.TemplateBuilderImpl.buildInlineTemplate(TemplateBuilderImpl.java:186) + * at com.jetbrains.python.codeInsight.intentions.PyAnnotateTypesIntention.startTemplate(PyAnnotateTypesIntention.java:159) + * at com.jetbrains.python.codeInsight.intentions.PyAnnotateTypesIntention.generateTypeCommentAnnotations(PyAnnotateTypesIntention.java:153) + * at com.jetbrains.python.codeInsight.intentions.PyAnnotateTypesIntention.annotateTypes(PyAnnotateTypesIntention.java:84) + */ + @Test + public void testStringIndexOutOfRange() { + runActivity(Pair.create(3683007015279203452L, 36)); } @Test @@ -72,6 +80,24 @@ public class PythonCodeInsightSanityTest extends PyEnvTestCase { return MadTestingUtil.actionsOnFileContents(fixture, testDataPath, f -> f.getName().endsWith(".py"), fileActions); } + private void runActivity(@Nullable final Pair seedToRepeat) { + runSanityTest(pathAndFixture -> { + final CodeInsightTestFixture fixture = pathAndFixture.second; + MadTestingUtil.enableAllInspections(fixture.getProject(), fixture.getProject()); + Function> fileActions = file -> + Generator.anyOf(InvokeIntention.randomIntentions(file, new IntentionPolicy()), + InvokeCompletion.completions(file, new CompletionPolicy()), + Generator.constant(new StripTestDataMarkup(file)), + DeleteRange.psiRangeDeletions(file)); + + PropertyChecker checker = PropertyChecker.forAll(actionsOnPyFiles(fileActions, fixture, pathAndFixture.first)); + if (seedToRepeat != null) { + checker = checker.rechecking(seedToRepeat.first, seedToRepeat.second); + } + checker.shouldHold(FileWithActions::runActions); + }); + } + private void runSanityTest(@NotNull final Consumer> test) { final String subfolder = "sanity";