[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] Create core.tests/failures/FullParseFailedTests
|
This patch creates a new failing test class : FullParseFailedTests. This
is for writing failed tests on the parser doing COMPLETE_PARSE.
The first failed test is for bug 40842 "Parser: NPE while parsing class
declaration in full parse mode"
Note that these patches are on the failures, parser and suite folders
directly instead of on the core.tests plugin
-Andrew
Index: org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java,v
retrieving revision 1.7
diff -u -r1.7 AutomatedIntegrationSuite.java
--- org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java 25 Jul 2003 14:40:02 -0000 1.7
+++ org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java 28 Jul 2003 15:59:33 -0000
@@ -25,6 +25,7 @@
import org.eclipse.cdt.core.model.tests.ElementDeltaTests;
import org.eclipse.cdt.core.model.tests.WorkingCopyTests;
import org.eclipse.cdt.core.parser.failedTests.ASTFailedTests;
+import org.eclipse.cdt.core.parser.failedTests.FullParseFailedTests;
import org.eclipse.cdt.core.parser.failedTests.LokiFailures;
import org.eclipse.cdt.core.parser.failedTests.STLFailedTests;
import org.eclipse.cdt.core.parser.tests.ParserTestSuite;
@@ -97,6 +98,7 @@
suite.addTestSuite(LokiFailures.class);
suite.addTestSuite(STLFailedTests.class);
suite.addTestSuite(CModelElementsFailedTests.class);
+ suite.addTestSuite(FullParseFailedTests.class);
// Last test to trigger report generation
suite.addTest(suite.new GenerateReport("generateReport"));
Index: org/eclipse/cdt/core/parser/failedTests/FullParseFailedTests.java
===================================================================
RCS file: org/eclipse/cdt/core/parser/failedTests/FullParseFailedTests.java
diff -N org/eclipse/cdt/core/parser/failedTests/FullParseFailedTests.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ org/eclipse/cdt/core/parser/failedTests/FullParseFailedTests.java 28 Jul 2003 15:58:57 -0000
@@ -0,0 +1,45 @@
+/*******************************************************************************
+ * Copyright (c) 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM Corp. - Rational Software - initial implementation
+ ******************************************************************************/
+/*
+ * Created on Jul 28, 2003
+ */
+package org.eclipse.cdt.core.parser.failedTests;
+
+import java.io.StringWriter;
+import java.io.Writer;
+
+import org.eclipse.cdt.core.parser.tests.BaseASTTest;
+
+/**
+ * @author aniefer
+ *
+ * To change the template for this generated type comment go to
+ * Window>Preferences>Java>Code Generation>Code and Comments
+ */
+public class FullParseFailedTests extends BaseASTTest {
+
+ /**
+ * @param a
+ */
+ public FullParseFailedTests(String name) {
+ super(name);
+ }
+
+ public void testBug40842() throws Exception{
+ Writer code = new StringWriter();
+
+ //note that if the parse fails at EOF, parse.failParse never sets
+ //parsePassed = false because it will throw EOF on LA(1), so get
+ //around this by adding more code after the error.
+ code.write("class A {} a;\n int x;");
+ assertCodeFailsFullParse(code.toString());
+ }
+}
Index: org/eclipse/cdt/core/parser/tests/BaseASTTest.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/BaseASTTest.java,v
retrieving revision 1.4
diff -u -r1.4 BaseASTTest.java
--- org/eclipse/cdt/core/parser/tests/BaseASTTest.java 21 Jul 2003 17:30:00 -0000 1.4
+++ org/eclipse/cdt/core/parser/tests/BaseASTTest.java 28 Jul 2003 15:59:16 -0000
@@ -57,6 +57,11 @@
return parse( code, true, true );
}
+ protected IASTCompilationUnit fullParse( String code ) throws ParserException
+ {
+ return parse( code, false, true );
+ }
+
protected IASTDeclaration assertSoleDeclaration( String code ) throws ParserException
{
Iterator declarationIter = null;
@@ -96,6 +101,20 @@
fail("The expected error did not occur.");
}
+ public void assertCodeFailsFullParse(String code) {
+ boolean testPassed = false;
+ try {
+ IASTCompilationUnit tu = fullParse(code);
+ testPassed = true;
+ fail( "We should not reach this point");
+ } catch (Throwable e) {
+ if (!(e instanceof ParserException))
+ fail("Unexpected Error: " + e.getMessage());
+ }
+ if (testPassed)
+ fail("The expected error did not occur.");
+ }
+
protected void assertSimpleReturnType(IASTFunction function, IASTSimpleTypeSpecifier.Type type)
{
assertEquals( ((IASTSimpleTypeSpecifier)function.getReturnType().getTypeSpecifier()).getType(), type );