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
This commit is contained in:
peter
2017-03-01 16:04:44 +01:00
parent fee8d864b6
commit a0cae94e87
2 changed files with 22 additions and 0 deletions
@@ -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<PsiElement> 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)) {
@@ -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()
}
}