bug with multifile frontend tests fixed
This commit is contained in:
@@ -11,6 +11,7 @@ import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
|||||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory;
|
import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory;
|
||||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithTextRange;
|
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithTextRange;
|
||||||
import org.jetbrains.jet.lang.diagnostics.Severity;
|
import org.jetbrains.jet.lang.diagnostics.Severity;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
|
|
||||||
@@ -50,6 +51,7 @@ public class CheckerTestUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface DiagnosticDiffCallbacks {
|
public interface DiagnosticDiffCallbacks {
|
||||||
|
@NotNull PsiFile getFile();
|
||||||
void missingDiagnostic(String type, int expectedStart, int expectedEnd);
|
void missingDiagnostic(String type, int expectedStart, int expectedEnd);
|
||||||
void unexpectedDiagnostic(String type, int actualStart, int actualEnd);
|
void unexpectedDiagnostic(String type, int actualStart, int actualEnd);
|
||||||
}
|
}
|
||||||
@@ -129,6 +131,7 @@ public class CheckerTestUtil {
|
|||||||
|
|
||||||
private static void unexpectedDiagnostics(List<Diagnostic> actual, DiagnosticDiffCallbacks callbacks) {
|
private static void unexpectedDiagnostics(List<Diagnostic> actual, DiagnosticDiffCallbacks callbacks) {
|
||||||
for (Diagnostic diagnostic : actual) {
|
for (Diagnostic diagnostic : actual) {
|
||||||
|
if (!diagnostic.getFactory().getPsiFile(diagnostic).equals(callbacks.getFile())) continue;
|
||||||
TextRange textRange = getTextRange(diagnostic);
|
TextRange textRange = getTextRange(diagnostic);
|
||||||
callbacks.unexpectedDiagnostic(diagnostic.getFactory().getName(), textRange.getStartOffset(), textRange.getEndOffset());
|
callbacks.unexpectedDiagnostic(diagnostic.getFactory().getName(), textRange.getStartOffset(), textRange.getEndOffset());
|
||||||
}
|
}
|
||||||
@@ -136,6 +139,7 @@ public class CheckerTestUtil {
|
|||||||
|
|
||||||
private static void missingDiagnostics(DiagnosticDiffCallbacks callbacks, DiagnosedRange currentExpected) {
|
private static void missingDiagnostics(DiagnosticDiffCallbacks callbacks, DiagnosedRange currentExpected) {
|
||||||
for (String type : currentExpected.getDiagnostics()) {
|
for (String type : currentExpected.getDiagnostics()) {
|
||||||
|
if (!currentExpected.getFile().equals(callbacks.getFile())) return;
|
||||||
callbacks.missingDiagnostic(type, currentExpected.getStart(), currentExpected.getEnd());
|
callbacks.missingDiagnostic(type, currentExpected.getStart(), currentExpected.getEnd());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -393,6 +397,7 @@ public class CheckerTestUtil {
|
|||||||
private final int start;
|
private final int start;
|
||||||
private int end;
|
private int end;
|
||||||
private final Multiset<String> diagnostics = HashMultiset.create();
|
private final Multiset<String> diagnostics = HashMultiset.create();
|
||||||
|
private PsiFile file;
|
||||||
|
|
||||||
private DiagnosedRange(int start) {
|
private DiagnosedRange(int start) {
|
||||||
this.start = start;
|
this.start = start;
|
||||||
@@ -417,5 +422,14 @@ public class CheckerTestUtil {
|
|||||||
public void addDiagnostic(String diagnostic) {
|
public void addDiagnostic(String diagnostic) {
|
||||||
diagnostics.add(diagnostic);
|
diagnostics.add(diagnostic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setFile(@NotNull PsiFile file) {
|
||||||
|
this.file = file;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public PsiFile getFile() {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.jetbrains.jet.checkers;
|
|||||||
|
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.JetLiteFixture;
|
import org.jetbrains.jet.JetLiteFixture;
|
||||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||||
@@ -79,7 +80,7 @@ public class CheckerTestUtilTest extends JetLiteFixture {
|
|||||||
this.expected = expectedMessages;
|
this.expected = expectedMessages;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void test(PsiFile psiFile) {
|
public void test(final @NotNull PsiFile psiFile) {
|
||||||
BindingContext bindingContext = AnalyzerFacade.analyzeOneNamespaceWithJavaIntegration(
|
BindingContext bindingContext = AnalyzerFacade.analyzeOneNamespaceWithJavaIntegration(
|
||||||
((JetFile) psiFile).getRootNamespace(),
|
((JetFile) psiFile).getRootNamespace(),
|
||||||
JetControlFlowDataTraceFactory.EMPTY);
|
JetControlFlowDataTraceFactory.EMPTY);
|
||||||
@@ -88,6 +89,9 @@ public class CheckerTestUtilTest extends JetLiteFixture {
|
|||||||
|
|
||||||
List<CheckerTestUtil.DiagnosedRange> diagnosedRanges = Lists.newArrayList();
|
List<CheckerTestUtil.DiagnosedRange> diagnosedRanges = Lists.newArrayList();
|
||||||
CheckerTestUtil.parseDiagnosedRanges(expectedText, diagnosedRanges);
|
CheckerTestUtil.parseDiagnosedRanges(expectedText, diagnosedRanges);
|
||||||
|
for (CheckerTestUtil.DiagnosedRange diagnosedRange : diagnosedRanges) {
|
||||||
|
diagnosedRange.setFile(psiFile);
|
||||||
|
}
|
||||||
|
|
||||||
List<Diagnostic> diagnostics = CheckerTestUtil.getDiagnosticsIncludingSyntaxErrors(bindingContext, psiFile);
|
List<Diagnostic> diagnostics = CheckerTestUtil.getDiagnosticsIncludingSyntaxErrors(bindingContext, psiFile);
|
||||||
Collections.sort(diagnostics, CheckerTestUtil.DIAGNOSTIC_COMPARATOR);
|
Collections.sort(diagnostics, CheckerTestUtil.DIAGNOSTIC_COMPARATOR);
|
||||||
@@ -98,6 +102,12 @@ public class CheckerTestUtilTest extends JetLiteFixture {
|
|||||||
final List<String> actualMessages = Lists.newArrayList();
|
final List<String> actualMessages = Lists.newArrayList();
|
||||||
|
|
||||||
CheckerTestUtil.diagnosticsDiff(diagnosedRanges, diagnostics, new CheckerTestUtil.DiagnosticDiffCallbacks() {
|
CheckerTestUtil.diagnosticsDiff(diagnosedRanges, diagnostics, new CheckerTestUtil.DiagnosticDiffCallbacks() {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public PsiFile getFile() {
|
||||||
|
return psiFile;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void missingDiagnostic(String type, int expectedStart, int expectedEnd) {
|
public void missingDiagnostic(String type, int expectedStart, int expectedEnd) {
|
||||||
String message = "Missing " + type + " at " + expectedStart + " to " + expectedEnd;
|
String message = "Missing " + type + " at " + expectedStart + " to " + expectedEnd;
|
||||||
|
|||||||
@@ -52,10 +52,19 @@ public class JetDiagnosticsTest extends JetLiteFixture {
|
|||||||
expectedText = textWithMarkers;
|
expectedText = textWithMarkers;
|
||||||
clearText = CheckerTestUtil.parseDiagnosedRanges(expectedText, diagnosedRanges);
|
clearText = CheckerTestUtil.parseDiagnosedRanges(expectedText, diagnosedRanges);
|
||||||
jetFile = createCheckAndReturnPsiFile(fileName, clearText);
|
jetFile = createCheckAndReturnPsiFile(fileName, clearText);
|
||||||
|
for (CheckerTestUtil.DiagnosedRange diagnosedRange : diagnosedRanges) {
|
||||||
|
diagnosedRange.setFile(jetFile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getActualText(BindingContext bindingContext, StringBuilder actualText) {
|
public void getActualText(BindingContext bindingContext, StringBuilder actualText) {
|
||||||
CheckerTestUtil.diagnosticsDiff(diagnosedRanges, CheckerTestUtil.getDiagnosticsIncludingSyntaxErrors(bindingContext, jetFile), new CheckerTestUtil.DiagnosticDiffCallbacks() {
|
CheckerTestUtil.diagnosticsDiff(diagnosedRanges, CheckerTestUtil.getDiagnosticsIncludingSyntaxErrors(bindingContext, jetFile), new CheckerTestUtil.DiagnosticDiffCallbacks() {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public PsiFile getFile() {
|
||||||
|
return jetFile;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void missingDiagnostic(String type, int expectedStart, int expectedEnd) {
|
public void missingDiagnostic(String type, int expectedStart, int expectedEnd) {
|
||||||
String message = "Missing " + type + DiagnosticUtils.atLocation(jetFile, new TextRange(expectedStart, expectedEnd));
|
String message = "Missing " + type + DiagnosticUtils.atLocation(jetFile, new TextRange(expectedStart, expectedEnd));
|
||||||
@@ -95,7 +104,7 @@ public class JetDiagnosticsTest extends JetLiteFixture {
|
|||||||
bindingContext = AnalyzerFacade.analyzeNamespacesWithJavaIntegration(getProject(), namespaces, Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY);
|
bindingContext = AnalyzerFacade.analyzeNamespacesWithJavaIntegration(getProject(), namespaces, Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
bindingContext = AnalyzingUtils.analyzeNamespaces(getProject(), Configuration.EMPTY, namespaces, Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY, JetSemanticServices.createSemanticServices(getProject()));
|
bindingContext = AnalyzingUtils.analyzeNamespaces(getProject(), Configuration.EMPTY, namespaces, Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder actualText = new StringBuilder();
|
StringBuilder actualText = new StringBuilder();
|
||||||
|
|||||||
Reference in New Issue
Block a user