aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorszarnekow2008-12-24 09:05:24 (EST)
committersefftinge2008-12-24 09:05:24 (EST)
commitfde13081f6014fdc3991035029d2dc414ab0e45f (patch)
tree144530cdd5d198a8e005f250106c6860c4141d5e
parentac82afe2bf47dd5ab9612f630ba23b48eda0e501 (diff)
downloadorg.eclipse.xtext-fde13081f6014fdc3991035029d2dc414ab0e45f.zip
org.eclipse.xtext-fde13081f6014fdc3991035029d2dc414ab0e45f.tar.gz
org.eclipse.xtext-fde13081f6014fdc3991035029d2dc414ab0e45f.tar.bz2
Improved robustness of the xtext editor, long running smoke tests for grammar parsing
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/resource/metamodel/Xtext2EcoreTransformerTest.java27
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/ResourceLoadTest.java113
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/StackOverflowTest.java39
3 files changed, 179 insertions, 0 deletions
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/resource/metamodel/Xtext2EcoreTransformerTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/resource/metamodel/Xtext2EcoreTransformerTest.java
index fc47fb2..3aa5851 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/resource/metamodel/Xtext2EcoreTransformerTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/resource/metamodel/Xtext2EcoreTransformerTest.java
@@ -37,6 +37,7 @@ import org.eclipse.xtext.ReferencedMetamodel;
import org.eclipse.xtext.TypeRef;
import org.eclipse.xtext.XtextStandaloneSetup;
import org.eclipse.xtext.crossref.internal.Linker;
+import org.eclipse.xtext.diagnostics.ExceptionDiagnostic;
import org.eclipse.xtext.diagnostics.IDiagnosticConsumer;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.resource.XtextResourceSet;
@@ -766,4 +767,30 @@ public class Xtext2EcoreTransformerTest extends AbstractGeneratorTest {
assertFalse(feature.getEType().equals(classifier));
assertEquals(EcorePackage.Literals.ESTRING, feature.getEType());
}
+
+ public void testNoException_01() throws Exception {
+ String grammar = "language test import 'http://www.eclipse.org/emf/2002/Ecore' as ecore " +
+ "generate test 'http://test'\n" +
+ "CompositeModel: (model+=Model)+;\n" +
+ "Model: id=NestedModelId (':' value=Fraction)? ('#' vector=Vector)? ('+' dots=Dots)? ';'\n" +
+ "ModelId returns ecore::EString: ID '.' ID;\n" +
+ "NestedModelId : ModelId '.' ModelId;\n" +
+ "Fraction returns EBigDecimal: INT ('/' INT)?;\n" +
+ "Vector : '(' INT I";
+ XtextResource resource = getResourceFromString(grammar);
+ for(Diagnostic d: resource.getErrors()) {
+ assertFalse(d instanceof ExceptionDiagnostic);
+ }
+ }
+
+ public void testNoException_02() throws Exception {
+ String grammar = "language test generate test 'http://test'\n" +
+ "Model: (children+=Element)*;\n" +
+ "Element returns Type: Item ( { Item.items+=current } items+=Item );\n" +
+ "Item returns Type: { T";
+ XtextResource resource = getResourceFromString(grammar);
+ for(Diagnostic d: resource.getErrors()) {
+ assertFalse(d instanceof ExceptionDiagnostic);
+ }
+ }
}
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/ResourceLoadTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/ResourceLoadTest.java
new file mode 100644
index 0000000..56f33c0
--- /dev/null
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/ResourceLoadTest.java
@@ -0,0 +1,113 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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 java.io.IOException;
+
+import junit.framework.TestResult;
+
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.Resource.Diagnostic;
+import org.eclipse.xtext.GenerateAllTestGrammars;
+import org.eclipse.xtext.XtextStandaloneSetup;
+import org.eclipse.xtext.diagnostics.ExceptionDiagnostic;
+import org.eclipse.xtext.tests.AbstractGeneratorTest;
+
+/**
+ * Really long running smoke tests for the xtext grammar.
+ * Uses all test grammars.
+ *
+ * @author Sebastian Zarnekow - Initial contribution and API
+ */
+public class ResourceLoadTest extends AbstractGeneratorTest {
+
+ private Class<?> clazz;
+
+ private String model;
+
+ @Override
+ public int countTestCases() {
+ return super.countTestCases() * GenerateAllTestGrammars.testclasses.length;
+ }
+
+ @Override
+ public String getName() {
+ return super.getName() + (clazz != null ? (" [" + clazz.getSimpleName() + "]") : "");
+ }
+
+ @Override
+ public void run(TestResult result) {
+ for(int i = 0; i < GenerateAllTestGrammars.testclasses.length; i++) {
+// for(int i = GenerateAllTestGrammars.testclasses.length - 1; i >= 0; i--) {
+ this.clazz = GenerateAllTestGrammars.testclasses[i];
+// this.clazz = GenerateAllTestGrammars.testclasses[8];
+ initModel();
+ super.run(result);
+ }
+ }
+
+// @Override
+// public void run(TestResult result) {
+// this.clazz = GenerateAllTestGrammars.testclasses[4];
+// initModel();
+// super.run(result);
+// }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ with(XtextStandaloneSetup.class);
+ }
+
+ private void initModel() {
+ try {
+ model = readFileIntoString(clazz.getName().replace('.', '/') + ".xtext");
+ } catch(IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+// public void testNoExceptionDiagnostics_01() throws Exception{
+// for(int i = 0; i < model.length(); i++) {
+// String model = this.model.substring(0, i);
+// Resource r = getResourceFromString(model);
+// assertNoExceptionDiagnostic(r, model);
+// }
+// }
+//
+// public void testNoExceptionDiagnostics_02() throws Exception{
+// for(int i = 0; i < model.length(); i++) {
+// String model = this.model.substring(i);
+// Resource r = getResourceFromString(model);
+// assertNoExceptionDiagnostic(r, model);
+// }
+// }
+//
+// public void testNoExceptionDiagnostics_03() throws Exception{
+// for(int i = 0; i < model.length() - 1; i++) {
+// String model = this.model.substring(0, i) + this.model.substring(i + 1);
+//// System.out.println(model);
+// Resource r = getResourceFromString(model);
+// assertNoExceptionDiagnostic(r, model);
+// }
+// }
+
+ public void testDummy() {
+ assertNotNull(clazz);
+ }
+
+ private void assertNoExceptionDiagnostic(Resource r, String model) throws Exception {
+ for(Diagnostic d: r.getErrors()) {
+ if (d instanceof ExceptionDiagnostic) {
+ throw new Exception(model, ((ExceptionDiagnostic)d).getException());
+ }
+ }
+ }
+
+
+}
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/StackOverflowTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/StackOverflowTest.java
new file mode 100644
index 0000000..bbbee12
--- /dev/null
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/xtext/StackOverflowTest.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.ecore.resource.Resource;
+import org.eclipse.xtext.XtextStandaloneSetup;
+import org.eclipse.xtext.tests.AbstractGeneratorTest;
+
+/**
+ * @author Sebastian Zarnekow - Initial contribution and API
+ */
+public class StackOverflowTest extends AbstractGeneratorTest {
+
+ private String model;
+
+ @Override
+ protected void setUp() throws Exception {
+ model = "language test\n" +
+ "import 'http://www.eclipse.org/2008/Xtext' as xtext\n" +
+ "generate test 'http://eclipse.org/xtext/tests/SimpleTest'\n" +
+ "Foo : name=ID (nameRefs+=NameRef)*;\n" +
+ "NameRef returns xtext::RuleCall : rle=[ParserRule];\n" +
+ "MyRule returns xtext::ParserRule : name=ID;";
+ with(XtextStandaloneSetup.class);
+ }
+
+ public void testNoStackOverflow() throws Exception {
+ Resource r = getResourceFromString(model);
+ assertEquals(r.getErrors().toString(), 1, r.getErrors().size());
+ r = getResourceFromString(model);
+ assertEquals(r.getErrors().toString(), 1, r.getErrors().size());
+ }
+
+}