changed DiagnosticMessageTest

added test arguments to test data
This commit is contained in:
Svetlana Isakova
2013-10-15 16:26:56 +04:00
parent 3663757073
commit 2f02427c57
11 changed files with 89 additions and 14 deletions
@@ -436,7 +436,7 @@ public class JetTestUtils {
return testFiles;
}
private static Map<String, String> parseDirectives(String expectedText) {
public static Map<String, String> parseDirectives(String expectedText) {
Map<String, String> directives = Maps.newHashMap();
Matcher directiveMatcher = DIRECTIVE_PATTERN.matcher(expectedText);
int start = 0;
@@ -1,3 +1,5 @@
// !DIAGNOSTICS_NUMBER: 2
// !DIAGNOSTICS: TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS
// see org.jetbrains.jet.plugin.highlighter.DiagnosticMessageTest
import java.io.Closeable
@@ -1,3 +1,6 @@
// !DIAGNOSTICS_NUMBER: 3
// !DIAGNOSTICS: TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH
class A<T, R>
fun <T, R> foo(a: A<T, R>) = a
@@ -1,3 +1,6 @@
// !DIAGNOSTICS_NUMBER: 1
// !DIAGNOSTICS: INACCESSIBLE_OUTER_CLASS_EXPRESSION
class A {
class B {
val r = object {
@@ -1,3 +1,6 @@
// !DIAGNOSTICS_NUMBER: 3
// !DIAGNOSTICS: INVISIBLE_MEMBER
package foo.bar
class A {
@@ -1,3 +1,6 @@
// !DIAGNOSTICS_NUMBER: 4
// !DIAGNOSTICS: TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS
package a
fun <T> id(t: T): T = t
@@ -1,3 +1,6 @@
// !DIAGNOSTICS_NUMBER: 1
// !DIAGNOSTICS: EXPECTED_PARAMETERS_NUMBER_MISMATCH
package aa
import java.util.ArrayList
@@ -1,3 +1,6 @@
// !DIAGNOSTICS_NUMBER: 3
// !DIAGNOSTICS: TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH
package s
fun <T> id(t: T): T = t
@@ -1,3 +1,6 @@
// !DIAGNOSTICS_NUMBER: 1
// !DIAGNOSTICS: TYPE_MISMATCH
package b
trait A<T>
@@ -1,3 +1,6 @@
// !DIAGNOSTICS_NUMBER: 3
// !DIAGNOSTICS: TYPE_INFERENCE_UPPER_BOUND_VIOLATED
package i
fun foo<R, T: List<R>>(r: R, list: T) {}
@@ -18,9 +18,11 @@ package org.jetbrains.jet.plugin.highlighter;
import com.google.common.collect.Sets;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.jet.ConfigurationKind;
import org.jetbrains.jet.JetLiteFixture;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment;
import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory;
@@ -33,11 +35,17 @@ import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM;
import org.jetbrains.jet.plugin.PluginTestCaseBase;
import java.io.File;
import java.lang.reflect.Field;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class DiagnosticMessageTest extends JetLiteFixture {
private static final String DIAGNOSTICS_NUMBER_DIRECTIVE = "DIAGNOSTICS_NUMBER";
private static final String DIAGNOSTICS_DIRECTIVE = "DIAGNOSTICS";
@Override
protected JetCoreEnvironment createEnvironment() {
return createEnvironmentWithMockJdk(ConfigurationKind.JDK_ONLY);
@@ -48,18 +56,22 @@ public class DiagnosticMessageTest extends JetLiteFixture {
return PluginTestCaseBase.getTestDataPathBase() + "/diagnosticMessage/";
}
public void doTest(String name, int diagnosticNumber, DiagnosticFactory... diagnosticFactories) throws Exception {
public void doTest(String name) throws Exception {
String fileName = name + ".kt";
JetFile psiFile = createPsiFile(null, fileName, loadFile(fileName));
String fileData = JetTestUtils.doLoadFile(new File(getTestDataPath() + fileName));
Map<String,String> directives = JetTestUtils.parseDirectives(fileData);
int diagnosticNumber = computeDiagnosticNumber(directives);
final Set<DiagnosticFactory> diagnosticFactories = computeDiagnosticFactories(directives);
AnalyzeExhaust analyzeExhaust = AnalyzerFacadeForJVM.analyzeOneFileWithJavaIntegration(psiFile, Collections.<AnalyzerScriptParameter>emptyList());
BindingContext bindingContext = analyzeExhaust.getBindingContext();
final Set<DiagnosticFactory> factoriesSet = Sets.newHashSet(diagnosticFactories);
List<Diagnostic> diagnostics = ContainerUtil.filter(bindingContext.getDiagnostics().all(), new Condition<Diagnostic>() {
@Override
public boolean value(Diagnostic diagnostic) {
return factoriesSet.contains(diagnostic.getFactory());
return diagnosticFactories.contains(diagnostic.getFactory());
}
});
@@ -86,40 +98,77 @@ public class DiagnosticMessageTest extends JetLiteFixture {
}
}
private int computeDiagnosticNumber(Map<String, String> directives) {
String diagnosticsNumber = directives.get(DIAGNOSTICS_NUMBER_DIRECTIVE);
assert diagnosticsNumber != null : DIAGNOSTICS_NUMBER_DIRECTIVE + " should be present.";
try {
return Integer.parseInt(diagnosticsNumber);
}
catch (NumberFormatException e) {
throw new AssertionError(DIAGNOSTICS_NUMBER_DIRECTIVE + " should contain number as its value.");
}
}
private Set<DiagnosticFactory> computeDiagnosticFactories(Map<String, String> directives) {
String diagnosticsData = directives.get(DIAGNOSTICS_DIRECTIVE);
assert diagnosticsData != null : DIAGNOSTICS_DIRECTIVE + " should be present.";
Set<DiagnosticFactory> diagnosticFactories = Sets.newHashSet();
String[] diagnostics = diagnosticsData.split(" ");
for (String diagnosticName : diagnostics) {
String errorMessage = "Can't load diagnostic factory for " + diagnosticName;
try {
Field field = Errors.class.getField(diagnosticName);
Object value = field.get(null);
if (value instanceof DiagnosticFactory) {
diagnosticFactories.add((DiagnosticFactory)value);
}
else {
throw new AssertionError(errorMessage);
}
}
catch (NoSuchFieldException e) {
throw new AssertionError(errorMessage);
}
catch (IllegalAccessException e) {
throw new AssertionError(errorMessage);
}
}
return diagnosticFactories;
}
public void testConflictingSubstitutions() throws Exception {
doTest("conflictingSubstitutions", 2, Errors.TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS);
doTest("conflictingSubstitutions");
}
public void testFunctionPlaceholder() throws Exception {
doTest("functionPlaceholder", 3, Errors.TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH);
doTest("functionPlaceholder");
}
public void testRenderCollectionOfTypes() throws Exception {
doTest("renderCollectionOfTypes", 1, Errors.EXPECTED_PARAMETERS_NUMBER_MISMATCH);
doTest("renderCollectionOfTypes");
}
public void testInaccessibleOuterClassExpression() throws Exception {
doTest("inaccessibleOuterClassExpression", 1, Errors.INACCESSIBLE_OUTER_CLASS_EXPRESSION);
doTest("inaccessibleOuterClassExpression");
}
public void testUpperBoundViolated() throws Exception {
doTest("upperBoundViolated", 3, Errors.TYPE_INFERENCE_UPPER_BOUND_VIOLATED);
doTest("upperBoundViolated");
}
public void testTypeMismatchWithNothing() throws Exception {
doTest("typeMismatchWithNothing", 1, Errors.TYPE_MISMATCH);
doTest("typeMismatchWithNothing");
}
public void testInvisibleMember() throws Exception {
doTest("invisibleMember", 3, Errors.INVISIBLE_MEMBER, Errors.INVISIBLE_MEMBER, Errors.INVISIBLE_MEMBER);
doTest("invisibleMember");
}
public void testNumberValueTypes() throws Exception {
doTest("numberValueTypes", 4, Errors.TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH, Errors.TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH,
Errors.TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS);
doTest("numberValueTypes");
}
public void testTypeInferenceExpectedTypeMismatch() throws Exception {
doTest("typeInferenceExpectedTypeMismatch", 3, Errors.TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH);
doTest("typeInferenceExpectedTypeMismatch");
}
}