/*******************************************************************************
* Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
+ * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
- *
+ *
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
import net.sourceforge.phpdt.core.compiler.IProblem;
import net.sourceforge.phpdt.internal.compiler.CompilationResult;
import net.sourceforge.phpdt.internal.compiler.DefaultErrorHandlingPolicies;
+import net.sourceforge.phpdt.internal.compiler.ast.CompilationUnitDeclaration;
import net.sourceforge.phpdt.internal.compiler.batch.CompilationUnit;
import net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit;
import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
+import net.sourceforge.phpdt.internal.compiler.parser.Scanner;
import net.sourceforge.phpdt.internal.compiler.parser.UnitParser;
import net.sourceforge.phpdt.internal.compiler.problem.DefaultProblem;
import net.sourceforge.phpdt.internal.compiler.problem.DefaultProblemFactory;
import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
-import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
-//import net.sourceforge.phpdt.core.tests.junit.extension.TestCase;
-//import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
+// import net.sourceforge.phpdt.core.tests.junit.extension.TestCase;
+// import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
public class AbstractCompilerTest extends TestCase {
-// public static final String COMPLIANCE_1_3 = "1.3";
-// public static final String COMPLIANCE_1_4 = "1.4";
-// public static final String COMPLIANCE_1_5 = "1.5";
-//
-// public static final int F_1_3 = 0x1;
-// public static final int F_1_4 = 0x2;
-// public static final int F_1_5 = 0x4;
-
private static int possibleComplianceLevels = -1;
protected String complianceLevel;
- public void checkParsePHP(
- char[] source,
- String expectedSyntaxErrorDiagnosis) {
-// String testName) {
- UnitParser parser =
- new UnitParser(
- new ProblemReporter(
- DefaultErrorHandlingPolicies.proceedWithAllProblems(),
- new CompilerOptions(getCompilerOptions()),
- new DefaultProblemFactory(Locale.getDefault())));
+ public void checkParsePHP(char[] source, String expectedSyntaxErrorDiagnosis) {
+ // String testName) {
+
+ UnitParser parser = new UnitParser(new ProblemReporter(
+ DefaultErrorHandlingPolicies.proceedWithAllProblems(),
+ new CompilerOptions(getCompilerOptions()),
+ new DefaultProblemFactory(Locale.getDefault())));
ICompilationUnit sourceUnit = new CompilationUnit(source, "", null);
- CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
-
- CompilationUnitDeclaration computedUnit = parser.dietParse(sourceUnit, compilationResult, true);
-// if (computedUnit.types != null) {
-// for (int i = computedUnit.types.size(); --i >= 0;){
-// ((TypeDeclaration)computedUnit.types.get(i)).parseMethod(parser, computedUnit);
-// }
-// }
+ CompilationResult compilationResult = new CompilationResult(sourceUnit,
+ 0, 0, 0);
+
+ CompilationUnitDeclaration computedUnit = parser.dietParse(sourceUnit,
+ compilationResult, true);
+ // if (computedUnit.types != null) {
+ // for (int i = computedUnit.types.size(); --i >= 0;){
+ // ((TypeDeclaration)computedUnit.types.get(i)).parseMethod(parser,
+ // computedUnit);
+ // }
+ // }
StringBuffer buffer = new StringBuffer(100);
if (compilationResult.hasProblems() || compilationResult.hasTasks()) {
int count = problems.length;
int problemCount = 0;
char[] unitSource = compilationResult.compilationUnit.getContents();
- for (int i = 0; i < count; i++) {
+ for (int i = 0; i < count; i++) {
if (problems[i] != null) {
if (problemCount == 0)
buffer.append("----------\n");
problemCount++;
- buffer.append(problemCount + (problems[i].isError() ? ". ERROR" : ". WARNING"));
- buffer.append(" in " + new String(problems[i].getOriginatingFileName()).replace('/', '\\'));
+ buffer
+ .append(problemCount
+ + (problems[i].isError() ? ". ERROR"
+ : ". WARNING"));
+ buffer.append(" in "
+ + new String(problems[i].getOriginatingFileName())
+ .replace('/', '\\'));
try {
- buffer.append(((DefaultProblem)problems[i]).errorReportSource(unitSource));
+ buffer.append(((DefaultProblem) problems[i])
+ .errorReportSource(unitSource));
buffer.append("\n");
buffer.append(problems[i].getMessage());
buffer.append("\n");
}
}
String computedSyntaxErrorDiagnosis = buffer.toString();
- if(!expectedSyntaxErrorDiagnosis.equals(computedSyntaxErrorDiagnosis)) {
- System.out.println(Util.displayString(computedSyntaxErrorDiagnosis));
+ if (!expectedSyntaxErrorDiagnosis.equals(computedSyntaxErrorDiagnosis)) {
+ System.out
+ .println(Util.displayString(computedSyntaxErrorDiagnosis));
}
- assertEquals(
- "Invalid syntax error diagnosis",
- expectedSyntaxErrorDiagnosis,
- computedSyntaxErrorDiagnosis);
+ assertEquals("Invalid syntax error diagnosis",
+ expectedSyntaxErrorDiagnosis, computedSyntaxErrorDiagnosis);
}
- public void checkParseHTML(
- char[] source,
- String expectedSyntaxErrorDiagnosis) {
-// String testName) {
- UnitParser parser =
- new UnitParser(
- new ProblemReporter(
- DefaultErrorHandlingPolicies.proceedWithAllProblems(),
- new CompilerOptions(getCompilerOptions()),
- new DefaultProblemFactory(Locale.getDefault())));
+ public void checkParseHTML(char[] source,
+ String expectedSyntaxErrorDiagnosis) {
+ // String testName) {
+
+ UnitParser parser = new UnitParser(new ProblemReporter(
+ DefaultErrorHandlingPolicies.proceedWithAllProblems(),
+ new CompilerOptions(getCompilerOptions()),
+ new DefaultProblemFactory(Locale.getDefault())));
ICompilationUnit sourceUnit = new CompilationUnit(source, "", null);
- CompilationResult compilationResult = new CompilationResult(sourceUnit, 0, 0, 0);
-
- CompilationUnitDeclaration computedUnit = parser.dietParse(sourceUnit, compilationResult, false);
-// if (computedUnit.types != null) {
-// for (int i = computedUnit.types.size(); --i >= 0;){
-// ((TypeDeclaration)computedUnit.types.get(i)).parseMethod(parser, computedUnit);
-// }
-// }
+ CompilationResult compilationResult = new CompilationResult(sourceUnit,
+ 0, 0, 0);
+
+ CompilationUnitDeclaration computedUnit = parser.dietParse(sourceUnit,
+ compilationResult, false);
+ // if (computedUnit.types != null) {
+ // for (int i = computedUnit.types.size(); --i >= 0;){
+ // ((TypeDeclaration)computedUnit.types.get(i)).parseMethod(parser,
+ // computedUnit);
+ // }
+ // }
StringBuffer buffer = new StringBuffer(100);
if (compilationResult.hasProblems() || compilationResult.hasTasks()) {
int count = problems.length;
int problemCount = 0;
char[] unitSource = compilationResult.compilationUnit.getContents();
- for (int i = 0; i < count; i++) {
+ for (int i = 0; i < count; i++) {
if (problems[i] != null) {
if (problemCount == 0)
buffer.append("----------\n");
problemCount++;
- buffer.append(problemCount + (problems[i].isError() ? ". ERROR" : ". WARNING"));
- buffer.append(" in " + new String(problems[i].getOriginatingFileName()).replace('/', '\\'));
+ buffer
+ .append(problemCount
+ + (problems[i].isError() ? ". ERROR"
+ : ". WARNING"));
+ buffer.append(" in "
+ + new String(problems[i].getOriginatingFileName())
+ .replace('/', '\\'));
try {
- buffer.append(((DefaultProblem)problems[i]).errorReportSource(unitSource));
+ buffer.append(((DefaultProblem) problems[i])
+ .errorReportSource(unitSource));
buffer.append("\n");
buffer.append(problems[i].getMessage());
buffer.append("\n");
}
}
String computedSyntaxErrorDiagnosis = buffer.toString();
- if(!expectedSyntaxErrorDiagnosis.equals(computedSyntaxErrorDiagnosis)) {
- System.out.println(Util.displayString(computedSyntaxErrorDiagnosis));
+ if (!expectedSyntaxErrorDiagnosis.equals(computedSyntaxErrorDiagnosis)) {
+ System.out
+ .println(Util.displayString(computedSyntaxErrorDiagnosis));
}
- assertEquals(
- "Invalid syntax error diagnosis",
- expectedSyntaxErrorDiagnosis,
- computedSyntaxErrorDiagnosis);
+ assertEquals("Invalid syntax error diagnosis",
+ expectedSyntaxErrorDiagnosis, computedSyntaxErrorDiagnosis);
}
+
/*
* Returns the possible compliance levels this VM instance can run.
*/
-// public static int getPossibleComplianceLevels() {
-// if (possibleComplianceLevels == -1) {
-// String compliance = System.getProperty("compliance");
-// if (compliance != null) {
-// if (COMPLIANCE_1_3.equals(compliance)) {
-// possibleComplianceLevels = F_1_3;
-// } else if (COMPLIANCE_1_4.equals(compliance)) {
-// possibleComplianceLevels = F_1_4;
-// } else if (COMPLIANCE_1_5.equals(compliance)) {
-// possibleComplianceLevels = F_1_5;
-// } else {
-// System.out.println("Invalid compliance specified (" + compliance + ")");
-// System.out.println("Use one of " + COMPLIANCE_1_3 + ", " + COMPLIANCE_1_4 + ", " + COMPLIANCE_1_5);
-// System.out.println("Defaulting to all possible compliances");
-// }
-// }
-// if (possibleComplianceLevels == -1) {
-// possibleComplianceLevels = F_1_3;
-// String specVersion = System.getProperty("java.specification.version");
-// boolean canRun1_4 = !"1.0".equals(specVersion) && !"1.1".equals(specVersion) && !"1.2".equals(specVersion) && !"1.3".equals(specVersion);
-// if (canRun1_4) {
-// possibleComplianceLevels |= F_1_4;
-// }
-// boolean canRun1_5 = canRun1_4 && !"1.4".equals(specVersion);
-// if (canRun1_5) {
-// possibleComplianceLevels |= F_1_5;
-// }
-// }
-// }
-// return possibleComplianceLevels;
-// }
-
+ // public static int getPossibleComplianceLevels() {
+ // if (possibleComplianceLevels == -1) {
+ // String compliance = System.getProperty("compliance");
+ // if (compliance != null) {
+ // if (COMPLIANCE_1_3.equals(compliance)) {
+ // possibleComplianceLevels = F_1_3;
+ // } else if (COMPLIANCE_1_4.equals(compliance)) {
+ // possibleComplianceLevels = F_1_4;
+ // } else if (COMPLIANCE_1_5.equals(compliance)) {
+ // possibleComplianceLevels = F_1_5;
+ // } else {
+ // System.out.println("Invalid compliance specified (" + compliance + ")");
+ // System.out.println("Use one of " + COMPLIANCE_1_3 + ", " + COMPLIANCE_1_4
+ // + ", " + COMPLIANCE_1_5);
+ // System.out.println("Defaulting to all possible compliances");
+ // }
+ // }
+ // if (possibleComplianceLevels == -1) {
+ // possibleComplianceLevels = F_1_3;
+ // String specVersion = System.getProperty("java.specification.version");
+ // boolean canRun1_4 = !"1.0".equals(specVersion) &&
+ // !"1.1".equals(specVersion) && !"1.2".equals(specVersion) &&
+ // !"1.3".equals(specVersion);
+ // if (canRun1_4) {
+ // possibleComplianceLevels |= F_1_4;
+ // }
+ // boolean canRun1_5 = canRun1_4 && !"1.4".equals(specVersion);
+ // if (canRun1_5) {
+ // possibleComplianceLevels |= F_1_5;
+ // }
+ // }
+ // }
+ // return possibleComplianceLevels;
+ // }
/*
- * Returns a test suite including the tests defined by the given classes for all possible complianceLevels
- * and using the given setup class (CompilerTestSetup or a subclass)
+ * Returns a test suite including the tests defined by the given classes for
+ * the given complianceLevel (see AbstractCompilerTest for valid values) and
+ * using the given setup class (CompilerTestSetup or a subclass)
*/
-// public static Test suite(String suiteName, Class setupClass, ArrayList testClasses) {
-// TestSuite all = new TestSuite(suiteName);
-// int complianceLevels = AbstractCompilerTest.getPossibleComplianceLevels();
-// if ((complianceLevels & AbstractCompilerTest.F_1_3) != 0) {
-// all.addTest(suiteForComplianceLevel(COMPLIANCE_1_3, setupClass, testClasses));
-// }
-// if ((complianceLevels & AbstractCompilerTest.F_1_4) != 0) {
-// all.addTest(suiteForComplianceLevel(COMPLIANCE_1_4, setupClass, testClasses));
-// }
-// if ((complianceLevels & AbstractCompilerTest.F_1_5) != 0) {
-// all.addTest(suiteForComplianceLevel(COMPLIANCE_1_5, setupClass, testClasses));
-// }
-// return all;
-// }
-
- /*
- * Returns a test suite including the tests defined by the given classes for the given complianceLevel
- * (see AbstractCompilerTest for valid values) and using the given setup class (CompilerTestSetup or a subclass)
- */
- public static Test suiteForComplianceLevel(String complianceLevel, Class setupClass, ArrayList testClasses) {
+ public static Test suiteForComplianceLevel(String complianceLevel,
+ Class setupClass, ArrayList testClasses) {
TestSuite suite;
if (testClasses.size() == 1) {
- suite = new TestSuite((Class)testClasses.get(0), complianceLevel);
+ suite = new TestSuite((Class) testClasses.get(0), complianceLevel);
} else {
suite = new TestSuite(complianceLevel);
for (int i = 0, length = testClasses.size(); i < length; i++) {
- Class testClass = (Class)testClasses.get(i);
+ Class testClass = (Class) testClasses.get(i);
TestSuite innerSuite = new TestSuite(testClass);
suite.addTest(innerSuite);
}
// call the setup constructor with the suite and compliance level
try {
- Constructor constructor = setupClass.getConstructor(new Class[]{Test.class, String.class});
- Test setUp = (Test)constructor.newInstance(new Object[]{suite, complianceLevel});
+ Constructor constructor = setupClass.getConstructor(new Class[] {
+ Test.class, String.class });
+ Test setUp = (Test) constructor.newInstance(new Object[] { suite,
+ complianceLevel });
return setUp;
} catch (IllegalAccessException e) {
e.printStackTrace();
protected Map getCompilerOptions() {
Map options = new CompilerOptions().getMap();
-// if (COMPLIANCE_1_3.equals(this.complianceLevel)) {
-// options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_3);
-// options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_3);
-// options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_1);
-// } else if (COMPLIANCE_1_4.equals(this.complianceLevel)) {
-// options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_4);
-// options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_4);
-// options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_4);
-// } else if (COMPLIANCE_1_5.equals(this.complianceLevel)) {
-// options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
-// options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
-// options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
-// }
+ // ignore warnings
+ options.put(CompilerOptions.OPTION_PHPVarDeprecatedWarning,
+ CompilerOptions.IGNORE);
+ options.put(CompilerOptions.OPTION_PHPBadStyleKeywordWarning,
+ CompilerOptions.IGNORE);
+ options.put(
+ CompilerOptions.OPTION_PHPBadStyleUppercaseIdentifierWarning,
+ CompilerOptions.IGNORE);
+ options.put(CompilerOptions.OPTION_PHPIncludeNotExistWarning,
+ CompilerOptions.IGNORE);
+ options.put(CompilerOptions.OPTION_UninitializedLocalVariableWarning,
+ CompilerOptions.IGNORE);
+ options.put(CompilerOptions.OPTION_CodeCannotBeReachedWarning,
+ CompilerOptions.IGNORE);
return options;
}
return name;
}
-// public void initialize(CompilerTestSetup setUp) {
-// this.complianceLevel = setUp.complianceLevel;
-// }
+ protected void checkPHP(String strEval) {
+ checkPHP(strEval, "");
+ }
+
+ protected void checkPHP(String strEval, String expectedSyntaxErrorDiagnosis) {
+ if (Scanner.DEBUG) {
+ System.out.println("\n------------------------------------");
+ System.out.println(strEval);
+ }
+ checkParsePHP(strEval.toCharArray(), expectedSyntaxErrorDiagnosis);
+ }
+
+ protected void checkHTML(String strEval) {
+ if (Scanner.DEBUG) {
+ System.out.println("\n------------------------------------");
+ System.out.println(strEval);
+ }
+ checkParseHTML(strEval.toCharArray(), "");
+ }
}