aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorszarnekow2009-03-05 08:56:34 (EST)
committersefftinge2009-03-05 08:56:34 (EST)
commit5832bc711b6060414aff2f13d004d1ea87c20296 (patch)
tree1d516a6718fbb751cea9d08604fe1cb39511ced9
parent0724b0d238671701272fc4244e74346cacfa7179 (diff)
downloadorg.eclipse.xtext-5832bc711b6060414aff2f13d004d1ea87c20296.zip
org.eclipse.xtext-5832bc711b6060414aff2f13d004d1ea87c20296.tar.gz
org.eclipse.xtext-5832bc711b6060414aff2f13d004d1ea87c20296.tar.bz2
Fix: Don't execute checks multiple times per validation
Warning if someone will stumble accross https://bugs.eclipse.org/bugs/show_bug.cgi?id=266978
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/PluginTestSuite.java1
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/packrat/PerformanceTest.java2
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/validator/AbstractDeclarativeValidatorTest.java19
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/XtextValidationTest.java62
4 files changed, 76 insertions, 8 deletions
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/PluginTestSuite.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/PluginTestSuite.java
index e127016..f1be47c 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/PluginTestSuite.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/generator/PluginTestSuite.java
@@ -89,6 +89,7 @@ public class PluginTestSuite {
suite.addTestSuite(org.eclipse.xtext.xtext.ExceptionTest.class);
suite.addTestSuite(org.eclipse.xtext.xtext.ResourceLoadTest.class);
suite.addTestSuite(org.eclipse.xtext.xtext.parser.packrat.XtextPackratParserTest.class);
+ suite.addTestSuite(org.eclipse.xtext.xtext.XtextValidationTest.class);
return suite;
}
}
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/packrat/PerformanceTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/packrat/PerformanceTest.java
index 716da5b..2d0c311 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/packrat/PerformanceTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/parser/packrat/PerformanceTest.java
@@ -32,7 +32,7 @@ public class PerformanceTest extends AbstractGeneratorTest {
protected void setUp() throws Exception {
with(XtextTerminalsTestLanguageStandaloneSetup.class);
this.generatedWithTerminals = get(XtextTerminalsTestLanguagePackratParser.class);
- StringBuilder modelBuilder = new StringBuilder("grammar a.bc.def.ghi extends e.fh.ijk\n");
+ StringBuilder modelBuilder = new StringBuilder("grammar a.bc.def.ghi with e.fh.ijk\n");
for(int i = 0; i < metamodelCount; i++) {
if (i % 2 == 0)
modelBuilder.append("import 'http://test' as mm" + i + "\n");
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/validator/AbstractDeclarativeValidatorTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/validator/AbstractDeclarativeValidatorTest.java
index 6a3b5c5..459dcae 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/validator/AbstractDeclarativeValidatorTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/validator/AbstractDeclarativeValidatorTest.java
@@ -9,7 +9,7 @@ package org.eclipse.xtext.validator;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import junit.framework.TestCase;
@@ -56,11 +56,15 @@ public class AbstractDeclarativeValidatorTest extends TestCase {
}
};
TestChain chain = chain();
- test.validate(EcorePackage.eINSTANCE.getEClass(), chain, Collections.singletonMap((Object)CheckMode.KEY, (Object)CheckMode.FAST));
+ test.validate(EcorePackage.eINSTANCE.getEClass(), chain, new HashMap<Object,Object>() {
+ { put(CheckMode.KEY, Integer.valueOf(CheckMode.FAST)); }
+ });
assertMatch(chain, 1, 3);
chain = chain();
- test.validate(EcorePackage.eINSTANCE.getEClass(), chain, Collections.singletonMap((Object)CheckMode.KEY, (Object)CheckMode.ALL));
+ test.validate(EcorePackage.eINSTANCE.getEClass(), chain, new HashMap<Object,Object>() {
+ { put(CheckMode.KEY, Integer.valueOf(CheckMode.ALL)); }
+ });
assertMatch(chain, 1, 3, 27);
chain = chain();
@@ -78,21 +82,22 @@ public class AbstractDeclarativeValidatorTest extends TestCase {
private TestChain chain() {
return new TestChain();
}
-
-
+
+
public void testGuard() throws Exception {
AbstractDeclarativeValidator validator = new AbstractDeclarativeValidator(){
+ @SuppressWarnings("unused")
@Check
public void guarded(EClass x) {
guard("".equals(x.getName()));
}
};
-
+
TestChain diagnostics = new TestChain();
validator.validate(EcorePackage.eINSTANCE.getEClass(), diagnostics, null);
assertEquals(0,diagnostics.integers.size());
}
-
+
@SuppressWarnings("unused")
private class TestValidator extends AbstractDeclarativeValidator {
@Check
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/XtextValidationTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/XtextValidationTest.java
new file mode 100644
index 0000000..97b9ac9
--- /dev/null
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/XtextValidationTest.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * Copyright (c) 2009 itemis AG (http://www.itemis.eu) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.xtext.xtext;
+
+import org.eclipse.emf.common.util.Diagnostic;
+import org.eclipse.emf.ecore.util.Diagnostician;
+import org.eclipse.xtext.Assignment;
+import org.eclipse.xtext.CrossReference;
+import org.eclipse.xtext.Grammar;
+import org.eclipse.xtext.Group;
+import org.eclipse.xtext.ParserRule;
+import org.eclipse.xtext.XtextPackage;
+import org.eclipse.xtext.XtextStandaloneSetup;
+import org.eclipse.xtext.resource.XtextResource;
+import org.eclipse.xtext.tests.AbstractGeneratorTest;
+
+/**
+ * @author Sebastian Zarnekow - Initial contribution and API
+ */
+public class XtextValidationTest extends AbstractGeneratorTest {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ with(XtextStandaloneSetup.class);
+ }
+
+ public void testMarkerForCrossReferences() throws Exception {
+ XtextResource resource = getResourceFromString(
+ "grammar org.foo.Bar with org.eclipse.xtext.common.Terminals\n" +
+ "generate metamodel 'myURI'\n" +
+ "Model: name=ID ref=[Model|(ID|STRING)];");
+ assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
+ assertTrue(resource.getWarnings().toString(), resource.getWarnings().isEmpty());
+
+ Grammar grammar = (Grammar) resource.getContents().get(0);
+ ParserRule modelRule = (ParserRule) grammar.getRules().get(0);
+ Assignment assignment = (Assignment) ((Group) modelRule.getAlternatives()).getTokens().get(1);
+ CrossReference reference = (CrossReference) assignment.getTerminal();
+
+ Diagnostic diag = Diagnostician.INSTANCE.validate(resource.getContents().get(0));
+ assertNotNull("diag", diag);
+ assertEquals(diag.getChildren().toString(), 1, diag.getChildren().size());
+ assertEquals("diag.isWarning", diag.getSeverity(), Diagnostic.WARNING);
+ assertEquals(diag.getData().toString(), grammar, diag.getData().get(0));
+ assertEquals(diag.getData().toString(), 1, diag.getData().size());
+
+ Diagnostic child = diag.getChildren().get(0);
+ assertNotNull("child", child);
+ assertEquals("child.isWarning", child.getSeverity(), Diagnostic.WARNING);
+ assertNull("child.children", child.getChildren());
+ assertEquals("child.data[0]", reference, child.getData().get(0));
+ assertEquals("child.data[1]", XtextPackage.CROSS_REFERENCE__TERMINAL, child.getData().get(1));
+ assertEquals(child.getData().toString(), 2, child.getData().size());
+ }
+
+}