improved diagnostic message test

added ability to denote required message type (text or html)
This commit is contained in:
Svetlana Isakova
2013-10-16 16:48:20 +04:00
parent 66678cdda9
commit 14cff91fed
8 changed files with 47 additions and 105 deletions
@@ -1,5 +1,6 @@
// !DIAGNOSTICS_NUMBER: 3 // !DIAGNOSTICS_NUMBER: 3
// !DIAGNOSTICS: TYPE_INFERENCE_UPPER_BOUND_VIOLATED // !DIAGNOSTICS: TYPE_INFERENCE_UPPER_BOUND_VIOLATED
// !MESSAGE_TYPE: TEXT
package i package i
@@ -1,32 +0,0 @@
<!-- upperBoundViolated1 -->
<html>
Type parameter bound for <b>
T</b>
in <table>
<tr>
<td width="10%">
</td>
<td align="right" colspan="2" style="white-space:nowrap;font-weight:bold;">
<b>
fun</b>
&lt;R, T : jet.List&lt;R&gt;>
foo</td>
<td style="white-space:nowrap;font-weight:bold;">
(</td>
<td align="right" style="white-space:nowrap;font-weight:bold;">
r: R,</td>
<td align="right" style="white-space:nowrap;font-weight:bold;">
list: T</td>
<td style="white-space:nowrap;font-weight:bold;">
)</td>
<td style="white-space:nowrap;font-weight:bold;">
: jet.Unit</td>
</tr>
</table>
is not satisfied: inferred type <font color=red>
<b>
jet.Collection&lt;jet.Int&gt;</b>
</font>
is not a subtype of <b>
jet.List&lt;jet.Int&gt;</b>
</html>
@@ -0,0 +1,3 @@
<!-- upperBoundViolated1 -->
Type parameter bound for T in fun <R, T : jet.List<R>> foo(r: R, list: T): jet.Unit
is not satisfied: inferred type jet.Collection<jet.Int> is not a subtype of jet.List<jet.Int>
@@ -1,32 +0,0 @@
<!-- upperBoundViolated2 -->
<html>
Type parameter bound for <b>
V</b>
in <table>
<tr>
<td width="10%">
</td>
<td align="right" colspan="2" style="white-space:nowrap;font-weight:bold;">
<b>
fun</b>
&lt;V : U, U>
bar</td>
<td style="white-space:nowrap;font-weight:bold;">
(</td>
<td align="right" style="white-space:nowrap;font-weight:bold;">
v: V,</td>
<td align="right" style="white-space:nowrap;font-weight:bold;">
u: jet.MutableSet&lt;U&gt;</td>
<td style="white-space:nowrap;font-weight:bold;">
)</td>
<td style="white-space:nowrap;font-weight:bold;">
: jet.MutableSet&lt;U&gt;</td>
</tr>
</table>
is not satisfied: inferred type <font color=red>
<b>
jet.Any</b>
</font>
is not a subtype of <b>
jet.String</b>
</html>
@@ -0,0 +1,3 @@
<!-- upperBoundViolated2 -->
Type parameter bound for V in fun <V : U, U> bar(v: V, u: jet.MutableSet<U>): jet.MutableSet<U>
is not satisfied: inferred type jet.Any is not a subtype of jet.String
@@ -1,34 +0,0 @@
<!-- upperBoundViolated3 -->
<html>
Type parameter bound for <b>
T</b>
in <table>
<tr>
<td width="10%">
</td>
<td align="right" colspan="2" style="white-space:nowrap;font-weight:bold;">
<b>
fun</b>
&lt;T : R, R : i.B>
baz</td>
<td style="white-space:nowrap;font-weight:bold;">
(</td>
<td align="right" style="white-space:nowrap;font-weight:bold;">
t: T,</td>
<td align="right" style="white-space:nowrap;font-weight:bold;">
r: R</td>
<td style="white-space:nowrap;font-weight:bold;">
)</td>
<td style="white-space:nowrap;font-weight:bold;">
: jet.Unit <b>
where</b>
T : i.A</td>
</tr>
</table>
is not satisfied: inferred type <font color=red>
<b>
i.A</b>
</font>
is not a subtype of <b>
i.B</b>
</html>
@@ -0,0 +1,3 @@
<!-- upperBoundViolated3 -->
Type parameter bound for T in fun <T : R, R : i.B> baz(t: T, r: R): jet.Unit where T : i.A
is not satisfied: inferred type i.A is not a subtype of i.B
@@ -20,6 +20,8 @@ import com.google.common.collect.Sets;
import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.ConfigurationKind; import org.jetbrains.jet.ConfigurationKind;
import org.jetbrains.jet.JetLiteFixture; import org.jetbrains.jet.JetLiteFixture;
import org.jetbrains.jet.JetTestUtils; import org.jetbrains.jet.JetTestUtils;
@@ -45,6 +47,19 @@ import java.util.Set;
public abstract class AbstractDiagnosticMessageTest extends JetLiteFixture { public abstract class AbstractDiagnosticMessageTest extends JetLiteFixture {
private static final String DIAGNOSTICS_NUMBER_DIRECTIVE = "DIAGNOSTICS_NUMBER"; private static final String DIAGNOSTICS_NUMBER_DIRECTIVE = "DIAGNOSTICS_NUMBER";
private static final String DIAGNOSTICS_DIRECTIVE = "DIAGNOSTICS"; private static final String DIAGNOSTICS_DIRECTIVE = "DIAGNOSTICS";
private static final String MESSAGE_TYPE_DIRECTIVE = "MESSAGE_TYPE";
private enum MessageType {
TEXT("TEXT", "txt"), HTML("HTML", "html");
public final String directive;
public final String extension;
MessageType(String directive, String extension) {
this.directive = directive;
this.extension = extension;
}
}
@Override @Override
protected JetCoreEnvironment createEnvironment() { protected JetCoreEnvironment createEnvironment() {
@@ -62,8 +77,9 @@ public abstract class AbstractDiagnosticMessageTest extends JetLiteFixture {
String fileData = JetTestUtils.doLoadFile(file); String fileData = JetTestUtils.doLoadFile(file);
Map<String,String> directives = JetTestUtils.parseDirectives(fileData); Map<String,String> directives = JetTestUtils.parseDirectives(fileData);
int diagnosticNumber = computeDiagnosticNumber(directives); int diagnosticNumber = getDiagnosticNumber(directives);
final Set<DiagnosticFactory> diagnosticFactories = computeDiagnosticFactories(directives); final Set<DiagnosticFactory> diagnosticFactories = getDiagnosticFactories(directives);
MessageType messageType = getMessageTypeDirective(directives);
JetFile psiFile = createPsiFile(null, fileName, loadFile(fileName)); JetFile psiFile = createPsiFile(null, fileName, loadFile(fileName));
AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegration(psiFile, Collections.<AnalyzerScriptParameter>emptyList()); AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegration(psiFile, Collections.<AnalyzerScriptParameter>emptyList());
@@ -83,13 +99,13 @@ public abstract class AbstractDiagnosticMessageTest extends JetLiteFixture {
for (Diagnostic diagnostic : diagnostics) { for (Diagnostic diagnostic : diagnostics) {
String readableDiagnosticText; String readableDiagnosticText;
String extension; String extension;
if (IdeErrorMessages.MAP.get(diagnostic.getFactory()) != null) { if (messageType != MessageType.TEXT && IdeErrorMessages.MAP.get(diagnostic.getFactory()) != null) {
readableDiagnosticText = IdeErrorMessages.RENDERER.render(diagnostic).replaceAll(">", ">\n"); readableDiagnosticText = IdeErrorMessages.RENDERER.render(diagnostic).replaceAll(">", ">\n");
extension = "html"; extension = MessageType.HTML.extension;
} }
else { else {
readableDiagnosticText = DefaultErrorMessages.RENDERER.render(diagnostic); readableDiagnosticText = DefaultErrorMessages.RENDERER.render(diagnostic);
extension = "txt"; extension = MessageType.TEXT.extension;
} }
String errorMessageFileName = name + index; String errorMessageFileName = name + index;
String path = getTestDataPath() + "/" + errorMessageFileName + "." + extension; String path = getTestDataPath() + "/" + errorMessageFileName + "." + extension;
@@ -100,7 +116,7 @@ public abstract class AbstractDiagnosticMessageTest extends JetLiteFixture {
} }
} }
private int computeDiagnosticNumber(Map<String, String> directives) { private static int getDiagnosticNumber(Map<String, String> directives) {
String diagnosticsNumber = directives.get(DIAGNOSTICS_NUMBER_DIRECTIVE); String diagnosticsNumber = directives.get(DIAGNOSTICS_NUMBER_DIRECTIVE);
assert diagnosticsNumber != null : DIAGNOSTICS_NUMBER_DIRECTIVE + " should be present."; assert diagnosticsNumber != null : DIAGNOSTICS_NUMBER_DIRECTIVE + " should be present.";
try { try {
@@ -111,7 +127,8 @@ public abstract class AbstractDiagnosticMessageTest extends JetLiteFixture {
} }
} }
private Set<DiagnosticFactory> computeDiagnosticFactories(Map<String, String> directives) { @NotNull
private static Set<DiagnosticFactory> getDiagnosticFactories(Map<String, String> directives) {
String diagnosticsData = directives.get(DIAGNOSTICS_DIRECTIVE); String diagnosticsData = directives.get(DIAGNOSTICS_DIRECTIVE);
assert diagnosticsData != null : DIAGNOSTICS_DIRECTIVE + " should be present."; assert diagnosticsData != null : DIAGNOSTICS_DIRECTIVE + " should be present.";
Set<DiagnosticFactory> diagnosticFactories = Sets.newHashSet(); Set<DiagnosticFactory> diagnosticFactories = Sets.newHashSet();
@@ -137,4 +154,17 @@ public abstract class AbstractDiagnosticMessageTest extends JetLiteFixture {
} }
return diagnosticFactories; return diagnosticFactories;
} }
@Nullable
private static MessageType getMessageTypeDirective(Map<String, String> directives) {
String messageType = directives.get(MESSAGE_TYPE_DIRECTIVE);
if (messageType == null) return null;
try {
return MessageType.valueOf(messageType);
}
catch (IllegalArgumentException e) {
throw new AssertionError(MESSAGE_TYPE_DIRECTIVE + " should be " + MessageType.TEXT.directive + " or " +
MessageType.HTML.directive + ". But was: \"" + messageType + "\".");
}
}
} }