From a0cae94e876619efb0a1d314932409c0bb928dac Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 1 Mar 2017 15:58:22 +0100 Subject: [PATCH] disable "call always fails according to method contract" in tests (IDEA-168613) 1. test might check precisely this failure 2. even if not, the test will fail anyway and the mistake will be obvious quite soon --- .../dataFlow/DataFlowInspectionBase.java | 5 +++++ .../DataFlowInspectionHeavyTest.groovy | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInspectionBase.java b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInspectionBase.java index 46129774dc11..0ca9d67f98b9 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInspectionBase.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/dataFlow/DataFlowInspectionBase.java @@ -39,6 +39,7 @@ import com.intellij.codeInspection.nullable.NullableStuffInspectionBase; import com.intellij.lang.java.JavaLanguage; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.WriteExternalException; import com.intellij.openapi.util.text.StringUtil; @@ -401,6 +402,10 @@ public class DataFlowInspectionBase extends BaseJavaBatchLocalInspectionTool { private static void reportAlwaysFailingCalls(ProblemsHolder holder, DataFlowInstructionVisitor visitor, HashSet reportedAnchors) { + if (ProjectFileIndex.SERVICE.getInstance(holder.getProject()).isInTestSourceContent(holder.getFile().getViewProvider().getVirtualFile())) { + return; + } + for (PsiCall call : visitor.getAlwaysFailingCalls()) { PsiMethod method = call.resolveMethod(); if (method != null && reportedAnchors.add(call)) { diff --git a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionHeavyTest.groovy b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionHeavyTest.groovy index 6f9b10987e37..24e5e5782b18 100644 --- a/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionHeavyTest.groovy +++ b/java/java-tests/testSrc/com/intellij/codeInspection/DataFlowInspectionHeavyTest.groovy @@ -76,4 +76,21 @@ class DataFlowInspectionHeavyTest extends JavaCodeInsightFixtureTestCase { public @interface Nullable {} """ } + + void "test no always failing calls in tests"() { + PsiTestUtil.addSourceRoot(myModule, myFixture.tempDirFixture.findOrCreateDir("test"), true) + + myFixture.configureFromExistingVirtualFile(myFixture.addFileToProject("test/Foo.java", """ +class Foo { + void foo() { + assertTrue(false); + } + private void assertTrue(boolean b) { + if (!b) throw new RuntimeException(); + } +} +""").virtualFile) + myFixture.enableInspections(new DataFlowInspection()) + myFixture.checkHighlighting() + } }