Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
Stephan Herrmann | 075533e | 2015-04-28 17:54:14 +0200 | [diff] [blame] | 2 | * Copyright (c) 2000, 2015 IBM Corporation and others. |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 3 | * All rights reserved. This program and the accompanying materials |
| 4 | * are made available under the terms of the Eclipse Public License v1.0 |
| 5 | * which accompanies this distribution, and is available at |
| 6 | * http://www.eclipse.org/legal/epl-v10.html |
Stephan Herrmann | 8f59a94 | 2015-02-01 15:13:21 +0100 | [diff] [blame] | 7 | * |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 8 | * Contributors: |
| 9 | * IBM Corporation - initial API and implementation |
| 10 | * Technical University Berlin - adapted for Object Teams |
Stephan Herrmann | bf0ecd3 | 2013-04-04 15:17:36 +0200 | [diff] [blame] | 11 | * Stephan Herrmann - Contribution for |
| 12 | * bug 335093 - [compiler][null] minimal hook for future null annotation support |
| 13 | * bug 388800 - [1.8] adjust tests to 1.8 JRE |
Stephan Herrmann | 307ebe3 | 2013-05-02 02:46:05 +0200 | [diff] [blame] | 14 | * bug 402237 - [1.8][compiler] investigate differences between compilers re MethodVerifyTest |
| 15 | * bug 391376 - [1.8] check interaction of default methods with bridge methods and generics |
Stephan Herrmann | 7c411a0 | 2013-12-29 14:47:52 +0100 | [diff] [blame] | 16 | * Bug 412203 - [compiler] Internal compiler error: java.lang.IllegalArgumentException: info cannot be null |
Stephan Herrmann | f087af3 | 2014-01-04 01:36:05 +0100 | [diff] [blame] | 17 | * Bug 422051 - [1.8][compiler][tests] cleanup excuses (JavacHasABug) in InterfaceMethodTests |
Stephan Herrmann | c1c4862 | 2014-01-04 23:19:31 +0100 | [diff] [blame] | 18 | * Bug 400874 - [1.8][compiler] Inference infrastructure should evolve to meet JLS8 18.x (Part G of JSR335 spec) |
Stephan Herrmann | 4d07945 | 2014-03-27 18:01:49 +0100 | [diff] [blame] | 19 | * Bug 425721 - [1.8][compiler] Nondeterministic results in GenericsRegressionTest_1_8.testBug424195a |
Stephan Herrmann | 396f334 | 2013-03-14 14:31:57 +0100 | [diff] [blame] | 20 | * Jesper S Moller - Contributions for bug 378674 - "The method can be declared as static" is wrong |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 21 | *******************************************************************************/ |
| 22 | package org.eclipse.jdt.core.tests.compiler.regression; |
| 23 | |
| 24 | import java.io.BufferedReader; |
| 25 | import java.io.BufferedWriter; |
| 26 | import java.io.File; |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 27 | import java.io.FileInputStream; |
Stephan Herrmann | 618f692 | 2012-08-10 22:00:05 +0200 | [diff] [blame] | 28 | import java.io.FileOutputStream; |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 29 | import java.io.FileWriter; |
| 30 | import java.io.IOException; |
| 31 | import java.io.InputStream; |
| 32 | import java.io.InputStreamReader; |
| 33 | import java.io.PrintWriter; |
Stephan Herrmann | 71432c0 | 2011-10-25 16:30:36 +0000 | [diff] [blame] | 34 | import java.net.URL; |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 35 | import java.text.SimpleDateFormat; |
| 36 | import java.util.ArrayList; |
| 37 | import java.util.Date; |
| 38 | import java.util.HashMap; |
| 39 | import java.util.Iterator; |
| 40 | import java.util.List; |
| 41 | import java.util.Locale; |
| 42 | import java.util.Map; |
Stephan Herrmann | 8f59a94 | 2015-02-01 15:13:21 +0100 | [diff] [blame] | 43 | import java.util.Set; |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 44 | import java.util.StringTokenizer; |
| 45 | |
Stephan Herrmann | 8f59a94 | 2015-02-01 15:13:21 +0100 | [diff] [blame] | 46 | import javax.annotation.processing.AbstractProcessor; |
| 47 | import javax.annotation.processing.Processor; |
| 48 | import javax.annotation.processing.RoundEnvironment; |
| 49 | import javax.annotation.processing.SupportedAnnotationTypes; |
| 50 | import javax.lang.model.element.TypeElement; |
| 51 | |
Stephan Herrmann | 71432c0 | 2011-10-25 16:30:36 +0000 | [diff] [blame] | 52 | import org.eclipse.core.runtime.FileLocator; |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 53 | import org.eclipse.core.runtime.IPath; |
| 54 | import org.eclipse.core.runtime.Path; |
Stephan Herrmann | 71432c0 | 2011-10-25 16:30:36 +0000 | [diff] [blame] | 55 | import org.eclipse.core.runtime.Platform; |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 56 | import org.eclipse.jdt.core.JavaCore; |
| 57 | import org.eclipse.jdt.core.ToolFactory; |
| 58 | import org.eclipse.jdt.core.compiler.batch.BatchCompiler; |
| 59 | import org.eclipse.jdt.core.search.SearchDocument; |
| 60 | import org.eclipse.jdt.core.search.SearchParticipant; |
| 61 | import org.eclipse.jdt.core.tests.junit.extension.StopableTestCase; |
| 62 | import org.eclipse.jdt.core.tests.util.AbstractCompilerTest; |
| 63 | import org.eclipse.jdt.core.tests.util.CompilerTestSetup; |
| 64 | import org.eclipse.jdt.core.tests.util.TestVerifier; |
| 65 | import org.eclipse.jdt.core.tests.util.Util; |
| 66 | import org.eclipse.jdt.core.util.ClassFileBytesDisassembler; |
| 67 | import org.eclipse.jdt.core.util.ClassFormatException; |
| 68 | import org.eclipse.jdt.internal.compiler.ASTVisitor; |
Stephan Herrmann | 8f59a94 | 2015-02-01 15:13:21 +0100 | [diff] [blame] | 69 | import org.eclipse.jdt.internal.compiler.AbstractAnnotationProcessorManager; |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 70 | import org.eclipse.jdt.internal.compiler.Compiler; |
| 71 | import org.eclipse.jdt.internal.compiler.ICompilerRequestor; |
| 72 | import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy; |
| 73 | import org.eclipse.jdt.internal.compiler.IProblemFactory; |
Stephan Herrmann | 8f59a94 | 2015-02-01 15:13:21 +0100 | [diff] [blame] | 74 | import org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager; |
| 75 | import org.eclipse.jdt.internal.compiler.apt.dispatch.BaseProcessingEnvImpl; |
| 76 | import org.eclipse.jdt.internal.compiler.apt.dispatch.ProcessorInfo; |
| 77 | import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 78 | import org.eclipse.jdt.internal.compiler.batch.FileSystem; |
| 79 | import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; |
| 80 | import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; |
| 81 | import org.eclipse.jdt.internal.compiler.env.INameEnvironment; |
| 82 | import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; |
Stephan Herrmann | 8f59a94 | 2015-02-01 15:13:21 +0100 | [diff] [blame] | 83 | import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 84 | import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; |
Stephan Herrmann | 8f59a94 | 2015-02-01 15:13:21 +0100 | [diff] [blame] | 85 | import org.eclipse.jdt.internal.compiler.problem.AbortCompilation; |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 86 | import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; |
| 87 | import org.eclipse.jdt.internal.core.search.JavaSearchParticipant; |
| 88 | import org.eclipse.jdt.internal.core.search.indexing.BinaryIndexer; |
Stephan Herrmann | aaa73af | 2013-12-29 16:34:59 +0100 | [diff] [blame] | 89 | import org.osgi.framework.Bundle; |
Stephan Herrmann | 8f59a94 | 2015-02-01 15:13:21 +0100 | [diff] [blame] | 90 | |
Stephan Herrmann | 4194d17 | 2014-11-11 21:35:54 +0100 | [diff] [blame] | 91 | import java.util.regex.Pattern; |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 92 | |
Stephan Herrmann | 8f59a94 | 2015-02-01 15:13:21 +0100 | [diff] [blame] | 93 | @SuppressWarnings({ "unchecked", "rawtypes" }) |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 94 | public abstract class AbstractRegressionTest extends AbstractCompilerTest implements StopableTestCase { |
Stephan Herrmann | bf0ecd3 | 2013-04-04 15:17:36 +0200 | [diff] [blame] | 95 | |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 96 | // javac comparison related types, fields and methods - see runJavac for |
| 97 | // details |
| 98 | static class JavacCompiler { |
| 99 | String rootDirectoryPath; |
| 100 | String javacPathName; |
| 101 | String version; // not intended to be modified - one of JavaCore.VERSION_1_* |
| 102 | int minor; |
| 103 | String rawVersion; // not intended to be modified - more complete version name |
| 104 | long compliance; |
| 105 | public static final long EXIT_VALUE_MASK = 0x00000000FFFFFFFFL; |
| 106 | public static final long ERROR_LOG_MASK = 0xFFFFFFFF00000000L; |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 107 | private String classpath; |
| 108 | JavacCompiler(String rootDirectoryPath) throws IOException, InterruptedException { |
| 109 | this(rootDirectoryPath, null); |
| 110 | } |
| 111 | JavacCompiler(String rootDirectoryPath, String rawVersion) throws IOException, InterruptedException { |
| 112 | this.rootDirectoryPath = rootDirectoryPath; |
| 113 | this.javacPathName = new File(rootDirectoryPath + File.separator |
| 114 | + "bin" + File.separator + JAVAC_NAME).getCanonicalPath(); |
| 115 | // WORK don't need JAVAC_NAME any more; suppress this as we work towards code cleanup |
| 116 | if (rawVersion == null) { |
| 117 | Process fetchVersionProcess = null; |
| 118 | try { |
| 119 | fetchVersionProcess = Runtime.getRuntime().exec(this.javacPathName |
| 120 | + " -version", null, null); |
| 121 | Logger versionLogger = new Logger(fetchVersionProcess.getErrorStream(), ""); |
| 122 | versionLogger.start(); |
| 123 | fetchVersionProcess.waitFor(); |
| 124 | versionLogger.join(); // make sure we get the whole output |
| 125 | rawVersion = versionLogger.buffer.toString(); |
| 126 | int eol = rawVersion.indexOf('\n'); |
| 127 | if (eol != -1) { |
| 128 | rawVersion = rawVersion.substring(0, eol); |
| 129 | } |
| 130 | if (rawVersion.startsWith("javac ")) { |
| 131 | rawVersion = rawVersion.substring(6, rawVersion.length()); |
| 132 | } |
| 133 | } finally { |
| 134 | if (fetchVersionProcess != null) { |
| 135 | fetchVersionProcess.destroy(); // closes process streams |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | if (rawVersion.indexOf("1.4") != -1 || |
| 140 | this.javacPathName.indexOf("1.4") != -1 |
| 141 | /* in fact, SUN javac 1.4 does not support the -version option; |
| 142 | * this is a imperfect heuristic to catch the case */) { |
| 143 | this.version = JavaCore.VERSION_1_4; |
| 144 | } else if (rawVersion.indexOf("1.5") != -1) { |
| 145 | this.version = JavaCore.VERSION_1_5; |
| 146 | } else if (rawVersion.indexOf("1.6") != -1) { |
| 147 | this.version = JavaCore.VERSION_1_6; |
| 148 | } else if (rawVersion.indexOf("1.7") != -1) { |
| 149 | this.version = JavaCore.VERSION_1_7; |
Stephan Herrmann | 307ebe3 | 2013-05-02 02:46:05 +0200 | [diff] [blame] | 150 | } else if (rawVersion.indexOf("1.8") != -1) { |
| 151 | this.version = JavaCore.VERSION_1_8; |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 152 | } else { |
| 153 | throw new RuntimeException("unknown javac version: " + rawVersion); |
| 154 | } |
| 155 | this.compliance = CompilerOptions.versionToJdkLevel(this.version); |
| 156 | this.minor = minorFromRawVersion(this.version, rawVersion); |
| 157 | this.rawVersion = rawVersion; |
| 158 | StringBuffer classpathBuffer = new StringBuffer(" -classpath "); |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 159 | this.classpath = classpathBuffer.toString(); |
| 160 | } |
| 161 | // projects known raw versions to minors; minors should grow with time, so |
| 162 | // that before and after relationships be easy to implement upon compilers |
| 163 | // of the same version; two latest digits are used for variants into levels |
| 164 | // denoted by the two first digits |
| 165 | static int minorFromRawVersion (String version, String rawVersion) { |
| 166 | if (version == JavaCore.VERSION_1_5) { |
| 167 | if ("1.5.0_15-ea".equals(rawVersion)) { |
| 168 | return 1500; |
| 169 | } |
| 170 | if ("1.5.0_16-ea".equals(rawVersion)) { // b01 |
| 171 | return 1600; |
| 172 | } |
| 173 | } |
| 174 | if (version == JavaCore.VERSION_1_6) { |
| 175 | if ("1.6.0_10-ea".equals(rawVersion)) { |
| 176 | return 1000; |
| 177 | } |
| 178 | if ("1.6.0_10-beta".equals(rawVersion)) { // b24 |
| 179 | return 1010; |
| 180 | } |
| 181 | } |
| 182 | if (version == JavaCore.VERSION_1_7) { |
| 183 | if ("1.7.0-ea".equals(rawVersion)) { |
| 184 | return 0000; |
| 185 | } |
Stephan Herrmann | 307ebe3 | 2013-05-02 02:46:05 +0200 | [diff] [blame] | 186 | if ("1.7.0_10".equals(rawVersion)) { |
| 187 | return 1000; |
| 188 | } |
Stephan Herrmann | c1c4862 | 2014-01-04 23:19:31 +0100 | [diff] [blame] | 189 | if ("1.7.0_25".equals(rawVersion)) { |
| 190 | return 2500; |
| 191 | } |
Stephan Herrmann | 307ebe3 | 2013-05-02 02:46:05 +0200 | [diff] [blame] | 192 | } |
| 193 | if (version == JavaCore.VERSION_1_8) { |
Stephan Herrmann | 4d07945 | 2014-03-27 18:01:49 +0100 | [diff] [blame] | 194 | if ("1.8.0-ea".equals(rawVersion) || ("1.8.0".equals(rawVersion))) { |
Stephan Herrmann | 307ebe3 | 2013-05-02 02:46:05 +0200 | [diff] [blame] | 195 | return 0000; |
| 196 | } |
Stephan Herrmann | ae70795 | 2015-10-30 22:28:02 +0100 | [diff] [blame^] | 197 | if ("1.8.0_40".equals(rawVersion)) { |
| 198 | return 1000; // corresponds to JLS maintenance release 2015-02-13 |
| 199 | } |
| 200 | if ("1.8.0_60".equals(rawVersion)) { |
| 201 | return 1500; |
| 202 | } |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 203 | } |
| 204 | throw new RuntimeException("unknown raw javac version: " + rawVersion); |
| 205 | } |
| 206 | // returns 0L if everything went fine; else the lower word contains the |
| 207 | // exit value and the upper word is non-zero iff the error log has contents |
| 208 | long compile(File directory, String options, String[] sourceFileNames, StringBuffer log) throws IOException, InterruptedException { |
| 209 | Process compileProcess = null; |
| 210 | long result = 0L; |
| 211 | // WORK classpath should depend on the compiler, not on the default runtime |
| 212 | try { |
| 213 | StringBuffer cmdLine = new StringBuffer(this.javacPathName); |
| 214 | cmdLine.append(this.classpath); |
| 215 | cmdLine.append(". "); |
| 216 | cmdLine.append(options); |
| 217 | for (int i = 0; i < sourceFileNames.length; i ++) { |
| 218 | cmdLine.append(' '); |
| 219 | cmdLine.append(sourceFileNames[i]); |
| 220 | } |
| 221 | String cmdLineAsString; |
| 222 | // WORK improve double-quotes management on Linux |
| 223 | if ("Linux".equals(System.getProperty("os.name"))) { |
| 224 | cmdLineAsString = cmdLine.toString().replaceAll("\"", ""); |
| 225 | } else { |
| 226 | cmdLineAsString = cmdLine.toString(); |
| 227 | } |
| 228 | compileProcess = Runtime.getRuntime().exec(cmdLineAsString, null, directory); |
| 229 | Logger errorLogger = new Logger(compileProcess.getErrorStream(), |
| 230 | "ERROR", log == null ? new StringBuffer() : log); |
| 231 | errorLogger.start(); |
| 232 | int compilerResult = compileProcess.waitFor(); |
| 233 | result |= compilerResult; // caveat: may never terminate under specific conditions |
| 234 | errorLogger.join(); // make sure we get the whole output |
| 235 | if (errorLogger.buffer.length() > 0) { |
| 236 | System.err.println("--- javac err: ---"); |
| 237 | System.err.println(errorLogger.buffer.toString()); |
| 238 | result |= ERROR_LOG_MASK; |
| 239 | } |
| 240 | } finally { |
| 241 | if (compileProcess != null) { |
| 242 | compileProcess.destroy(); |
| 243 | } |
| 244 | } |
| 245 | return result; |
| 246 | } |
| 247 | } |
| 248 | static class JavaRuntime { |
| 249 | private String rootDirectoryPath; |
| 250 | private String javaPathName; |
| 251 | String version; // not intended to be modified - one of JavaCore.VERSION_1_* |
| 252 | String rawVersion; // not intended to be modified - more complete version name |
| 253 | int minor; |
| 254 | private static HashMap runtimes = new HashMap(); |
| 255 | static JavaRuntime runtimeFor(JavacCompiler compiler) throws IOException, InterruptedException { |
| 256 | JavaRuntime cached = (JavaRuntime) runtimes.get(compiler.rawVersion); |
| 257 | if (cached == null) { |
| 258 | cached = new JavaRuntime(compiler.rootDirectoryPath, compiler.version, compiler.rawVersion, compiler.minor); |
| 259 | runtimes.put(compiler.rawVersion, cached); |
| 260 | } |
| 261 | return cached; |
| 262 | } |
| 263 | private JavaRuntime(String rootDirectoryPath, String version, String rawVersion, int minor) throws IOException, InterruptedException { |
| 264 | this.rootDirectoryPath = rootDirectoryPath; |
| 265 | this.javaPathName = new File(this.rootDirectoryPath + File.separator |
| 266 | + "bin" + File.separator + JAVA_NAME).getCanonicalPath(); |
| 267 | this.version = version; |
| 268 | this.rawVersion = rawVersion; |
| 269 | this.minor = minor; |
| 270 | } |
| 271 | // returns 0 if everything went fine |
| 272 | int execute(File directory, String options, String className, StringBuffer stdout, StringBuffer stderr) throws IOException, InterruptedException { |
| 273 | Process executionProcess = null; |
| 274 | try { |
| 275 | StringBuffer cmdLine = new StringBuffer(this.javaPathName); |
| 276 | cmdLine.append(" -classpath . "); // default classpath |
| 277 | cmdLine.append(options); |
| 278 | cmdLine.append(' '); |
| 279 | cmdLine.append(className); |
| 280 | executionProcess = Runtime.getRuntime().exec(cmdLine.toString(), null, directory); |
| 281 | Logger outputLogger = new Logger(executionProcess.getInputStream(), |
| 282 | "RUNTIME OUTPUT", stdout == null ? new StringBuffer() : stdout); |
| 283 | outputLogger.start(); |
| 284 | Logger errorLogger = new Logger(executionProcess.getErrorStream(), |
| 285 | "RUNTIME ERROR", stderr == null ? new StringBuffer() : stderr); |
| 286 | errorLogger.start(); |
| 287 | int result = executionProcess.waitFor(); // caveat: may never terminate under specific conditions |
| 288 | outputLogger.join(); // make sure we get the whole output |
| 289 | errorLogger.join(); // make sure we get the whole output |
| 290 | return result; |
| 291 | } finally { |
| 292 | if (executionProcess != null) { |
| 293 | executionProcess.destroy(); |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | protected static class JavacTestOptions { |
| 299 | static final JavacTestOptions DEFAULT = new JavacTestOptions(); |
| 300 | static final JavacTestOptions SKIP = new JavacTestOptions() { |
| 301 | boolean skip(JavacCompiler compiler) { |
| 302 | return true; |
| 303 | } |
| 304 | }; |
| 305 | // TODO (maxime) enable selective javac output dir manipulations between |
| 306 | // tests steps |
| 307 | // some tests manipulate the OUTPUT_DIR explicitly between run*Test calls; |
| 308 | // however, these manipulations are not reflected in the javac output |
| 309 | // directory (yet); skipping until we fix this |
| 310 | static final JavacTestOptions SKIP_UNTIL_FRAMEWORK_FIX = new JavacTestOptions() { |
| 311 | boolean skip(JavacCompiler compiler) { |
| 312 | return true; |
| 313 | } |
| 314 | }; |
| 315 | private String compilerOptions = ""; |
| 316 | public JavacTestOptions() { |
| 317 | } |
| 318 | public JavacTestOptions(String compilerOptions) { |
| 319 | this.compilerOptions = compilerOptions; |
| 320 | } |
| 321 | String getCompilerOptions() { |
| 322 | return this.compilerOptions; |
| 323 | } |
Stephan Herrmann | 4d07945 | 2014-03-27 18:01:49 +0100 | [diff] [blame] | 324 | public void setCompilerOptions(String options) { |
| 325 | this.compilerOptions = options; |
| 326 | } |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 327 | boolean skip(JavacCompiler compiler) { |
| 328 | return false; |
| 329 | } |
| 330 | static class MismatchType { |
| 331 | static final int EclipseErrorsJavacNone = 0x0001; |
| 332 | static final int EclipseErrorsJavacWarnings = 0x0002; |
| 333 | static final int JavacErrorsEclipseNone = 0x0004; |
| 334 | static final int JavacErrorsEclipseWarnings = 0x0008; |
| 335 | static final int EclipseWarningsJavacNone = 0x0010; |
| 336 | static final int JavacWarningsEclipseNone = 0x0020; |
| 337 | static final int StandardOutputMismatch = 0x0040; |
| 338 | static final int ErrorOutputMismatch = 0x0080; |
| 339 | static final int JavacAborted = 0x0100; |
| 340 | static final int JavacNotLaunched = 0x0200; |
| 341 | static final int JavaAborted = 0x0400; |
| 342 | static final int JavaNotLaunched = 0x0800; |
| 343 | } |
| 344 | public static class Excuse extends JavacTestOptions { |
| 345 | protected int mismatchType; |
| 346 | Excuse(int mismatchType) { |
| 347 | this.mismatchType = mismatchType; |
| 348 | } |
| 349 | Excuse excuseFor(JavacCompiler compiler) { |
| 350 | return this; |
| 351 | } |
| 352 | public boolean clears(int mismatch) { |
| 353 | return this.mismatchType == 0 || (this.mismatchType & mismatch) == mismatch; // one excuse can clear multiple mismatches |
| 354 | } |
| 355 | public static Excuse |
| 356 | EclipseHasSomeMoreWarnings = RUN_JAVAC ? |
| 357 | new Excuse(MismatchType.EclipseWarningsJavacNone) : null, |
| 358 | EclipseWarningConfiguredAsError = RUN_JAVAC ? |
| 359 | new Excuse(MismatchType.EclipseErrorsJavacWarnings | MismatchType.EclipseErrorsJavacNone) : null, |
| 360 | JavacCompilesBogusReferencedFileAgain = RUN_JAVAC ? |
Stephan Herrmann | ae70795 | 2015-10-30 22:28:02 +0100 | [diff] [blame^] | 361 | new Excuse(MismatchType.JavacErrorsEclipseNone) : null, |
| 362 | // bugs not found on javac bug site, but points to a javac bug. |
| 363 | JavacDoesNotCompileCorrectSource = RUN_JAVAC ? |
| 364 | new JavacHasABug(MismatchType.JavacErrorsEclipseNone) : null, |
| 365 | /* A General Excuse - Revisit periodically */ |
| 366 | JavacCompilesIncorrectSource = RUN_JAVAC ? |
| 367 | new JavacHasABug(MismatchType.EclipseErrorsJavacNone | |
| 368 | MismatchType.EclipseErrorsJavacWarnings | |
| 369 | MismatchType.EclipseWarningsJavacNone) : null, |
| 370 | JavacGeneratesIncorrectCode = RUN_JAVAC ? |
| 371 | new JavacHasABug(MismatchType.StandardOutputMismatch) : null, |
| 372 | JavacHasWarningsEclipseNotConfigured = RUN_JAVAC ? |
| 373 | new JavacHasABug(MismatchType.JavacWarningsEclipseNone) : null; |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 374 | } |
| 375 | Excuse excuseFor(JavacCompiler compiler) { |
| 376 | return null; |
| 377 | } |
| 378 | public static class EclipseHasABug extends Excuse { |
| 379 | EclipseHasABug(int mismatchType) { |
| 380 | super(mismatchType); |
| 381 | } |
| 382 | public static EclipseHasABug |
| 383 | EclipseBug159851 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=159851 |
Stephan Herrmann | c1c4862 | 2014-01-04 23:19:31 +0100 | [diff] [blame] | 384 | new EclipseHasABug(MismatchType.JavacErrorsEclipseNone) { |
| 385 | Excuse excuseFor(JavacCompiler compiler) { |
| 386 | return compiler.compliance < ClassFileConstants.JDK1_7 ? this : null; |
| 387 | } |
| 388 | } : null, |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 389 | EclipseBug177715 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=177715 |
| 390 | new EclipseHasABug(MismatchType.JavacErrorsEclipseNone) : null, |
| 391 | EclipseBug207935 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=207935 |
| 392 | new EclipseHasABug(MismatchType.EclipseErrorsJavacNone | MismatchType.EclipseWarningsJavacNone) : null, |
| 393 | EclipseBug216558 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=216558 |
| 394 | new EclipseHasABug(MismatchType.JavacErrorsEclipseNone) : null, |
| 395 | EclipseBug235550 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=235550 |
| 396 | new EclipseHasABug(MismatchType.JavacErrorsEclipseNone) : null, |
| 397 | EclipseBug235809 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=235809 |
| 398 | new EclipseHasABug(MismatchType.StandardOutputMismatch) : null, |
| 399 | EclipseBug236217 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=236217 |
Stephan Herrmann | c1c4862 | 2014-01-04 23:19:31 +0100 | [diff] [blame] | 400 | new EclipseHasABug(MismatchType.JavacErrorsEclipseNone) { |
| 401 | Excuse excuseFor(JavacCompiler compiler) { |
| 402 | return compiler.compliance < ClassFileConstants.JDK1_8 ? this : null; // in 1.8 accepted by both compilers |
| 403 | } |
| 404 | } : null, |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 405 | EclipseBug236236 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=236236 |
| 406 | new EclipseHasABug(MismatchType.EclipseErrorsJavacNone) { |
| 407 | Excuse excuseFor(JavacCompiler compiler) { |
| 408 | return compiler.compliance > ClassFileConstants.JDK1_5 ? this : null; |
| 409 | } |
| 410 | }: null, |
| 411 | EclipseBug236242 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=236242 |
| 412 | new EclipseHasABug(MismatchType.EclipseErrorsJavacWarnings) { |
| 413 | Excuse excuseFor(JavacCompiler compiler) { |
Stephan Herrmann | c1c4862 | 2014-01-04 23:19:31 +0100 | [diff] [blame] | 414 | return compiler.compliance == ClassFileConstants.JDK1_7 ? this : null; |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 415 | } |
| 416 | }: null, |
| 417 | EclipseBug236243 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=236243 |
| 418 | new EclipseHasABug(MismatchType.EclipseErrorsJavacNone) { |
| 419 | Excuse excuseFor(JavacCompiler compiler) { |
| 420 | return compiler.compliance > ClassFileConstants.JDK1_6 ? this : null; |
| 421 | } |
| 422 | }: null, |
| 423 | EclipseBug236370 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=236370 |
| 424 | new EclipseHasABug(MismatchType.EclipseErrorsJavacNone) { |
| 425 | Excuse excuseFor(JavacCompiler compiler) { |
| 426 | return compiler.compliance > ClassFileConstants.JDK1_6 ? this : null; |
| 427 | } |
| 428 | }: null, |
| 429 | EclipseBug236379 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=236379 |
| 430 | new EclipseHasABug(MismatchType.EclipseWarningsJavacNone) { |
| 431 | Excuse excuseFor(JavacCompiler compiler) { |
| 432 | return compiler.compliance > ClassFileConstants.JDK1_5 ? this : null; |
| 433 | } |
Stephan Herrmann | ae70795 | 2015-10-30 22:28:02 +0100 | [diff] [blame^] | 434 | }: null, |
| 435 | EclipseBug424410 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=424410 |
| 436 | new EclipseHasABug(MismatchType.JavacErrorsEclipseNone) : null, |
| 437 | EclipseBug427719 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=427719 |
| 438 | new EclipseHasABug(MismatchType.JavacErrorsEclipseWarnings) : null, |
| 439 | EclipseBug427745 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=427745 |
| 440 | new EclipseHasABug(MismatchType.StandardOutputMismatch) : null, |
| 441 | EclipseBug421922 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=421922 |
| 442 | new EclipseHasABug(MismatchType.EclipseErrorsJavacNone) : null, |
| 443 | EclipseBug428061 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=428061 |
| 444 | new EclipseHasABug(MismatchType.JavacErrorsEclipseNone | |
| 445 | MismatchType.JavacErrorsEclipseWarnings) : null; |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 446 | } |
| 447 | // Justification based upon: |
| 448 | // - Eclipse bugs opened to investigate differences and closed as INVALID |
| 449 | // on grounds other than an identified javac bug; |
| 450 | // - Eclipse bugs that discuss the topic in depth and explain why we made a |
| 451 | // given choice; |
| 452 | // - explanations inlined here (no bug available, apparently not worth |
| 453 | // opening one). |
| 454 | public static class EclipseJustification extends Excuse { |
| 455 | EclipseJustification(int mismatchType) { |
| 456 | super(mismatchType); |
| 457 | } |
| 458 | public static final EclipseJustification |
| 459 | EclipseBug40839 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=40839 |
| 460 | new EclipseJustification(MismatchType.JavacWarningsEclipseNone) : null, |
| 461 | EclipseBug72704 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=72704 |
| 462 | new EclipseJustification(MismatchType.EclipseErrorsJavacNone) : null, |
| 463 | EclipseBug83902 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83902 |
| 464 | new EclipseJustification(MismatchType.EclipseWarningsJavacNone) { |
| 465 | Excuse excuseFor(JavacCompiler compiler) { |
| 466 | return compiler.compliance > ClassFileConstants.JDK1_5 ? this : null; |
| 467 | } |
| 468 | } : null, |
| 469 | EclipseBug83902b = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83902 |
| 470 | new EclipseJustification(MismatchType.JavacErrorsEclipseWarnings) : null, |
| 471 | EclipseBug95021 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=95021 |
| 472 | new EclipseJustification(MismatchType.JavacErrorsEclipseNone) { |
| 473 | Excuse excuseFor(JavacCompiler compiler) { |
Stephan Herrmann | c1c4862 | 2014-01-04 23:19:31 +0100 | [diff] [blame] | 474 | return compiler.compliance == ClassFileConstants.JDK1_7 ? this : null; |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 475 | } |
| 476 | // WORK consider adding reversed pivots |
| 477 | } : null, |
| 478 | EclipseBug112433 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=112433 |
| 479 | new EclipseJustification(MismatchType.JavacErrorsEclipseNone) : null, |
| 480 | EclipseBug126712 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=126712 & http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6342411 |
| 481 | new EclipseJustification(MismatchType.StandardOutputMismatch) { |
| 482 | Excuse excuseFor(JavacCompiler compiler) { |
| 483 | return compiler.compliance > ClassFileConstants.JDK1_5 ? this : null; |
| 484 | } |
| 485 | // WORK consider adding reversed pivots |
| 486 | } : null, |
| 487 | EclipseBug126744 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=126744 |
| 488 | new EclipseJustification(MismatchType.JavacErrorsEclipseNone) : null, |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 489 | EclipseBug151275 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=151275 |
Stephan Herrmann | c1c4862 | 2014-01-04 23:19:31 +0100 | [diff] [blame] | 490 | new EclipseJustification(MismatchType.JavacErrorsEclipseNone) { |
| 491 | Excuse excuseFor(JavacCompiler compiler) { |
| 492 | return compiler.compliance < ClassFileConstants.JDK1_7 ? this : null; |
| 493 | } |
| 494 | } : null, |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 495 | EclipseBug159214 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=159214 |
| 496 | new EclipseJustification(MismatchType.EclipseErrorsJavacNone) { |
| 497 | Excuse excuseFor(JavacCompiler compiler) { |
Stephan Herrmann | c1c4862 | 2014-01-04 23:19:31 +0100 | [diff] [blame] | 498 | return compiler.compliance == ClassFileConstants.JDK1_6 ? this : null; |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 499 | } |
| 500 | // WORK consider adding reversed pivots |
| 501 | } : null, |
| 502 | EclipseBug169017 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=169017 |
| 503 | new EclipseJustification(MismatchType.JavacErrorsEclipseNone) { |
| 504 | Excuse excuseFor(JavacCompiler compiler) { |
| 505 | return compiler.compliance > ClassFileConstants.JDK1_5 ? this : null; |
| 506 | } |
| 507 | // WORK consider adding reversed pivots |
| 508 | } : null, |
| 509 | EclipseBug180789 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789 |
| 510 | new EclipseJustification(MismatchType.EclipseErrorsJavacWarnings) : null, |
| 511 | EclipseBug183211 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=183211 |
| 512 | new EclipseJustification(MismatchType.JavacErrorsEclipseNone | MismatchType.EclipseErrorsJavacNone) : null, |
| 513 | EclipseBug183211b = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=183211 |
| 514 | new EclipseJustification(MismatchType.EclipseErrorsJavacNone) { |
| 515 | Excuse excuseFor(JavacCompiler compiler) { |
| 516 | return compiler.compliance > ClassFileConstants.JDK1_5 ? this : null; |
| 517 | } |
| 518 | } : null, |
| 519 | EclipseBug185422 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=185422 |
| 520 | new EclipseJustification(MismatchType.JavacErrorsEclipseNone) : null, |
| 521 | EclipseBug218677 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=218677 |
| 522 | new EclipseJustification(MismatchType.EclipseErrorsJavacNone) { |
| 523 | Excuse excuseFor(JavacCompiler compiler) { |
| 524 | return compiler.compliance > ClassFileConstants.JDK1_6 ? this : null; |
| 525 | } |
| 526 | // WORK consider adding reversed pivots |
| 527 | } : null, |
| 528 | EclipseBug234815 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=234815 |
Stephan Herrmann | c1c4862 | 2014-01-04 23:19:31 +0100 | [diff] [blame] | 529 | new EclipseJustification(MismatchType.JavacErrorsEclipseNone) { |
| 530 | Excuse excuseFor(JavacCompiler compiler) { |
| 531 | return compiler.compliance < ClassFileConstants.JDK1_7 ? this : null; |
| 532 | } |
| 533 | }: null, |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 534 | EclipseBug235543 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=235543 |
| 535 | new EclipseJustification(MismatchType.EclipseErrorsJavacNone) : null, |
| 536 | EclipseBug235546 = RUN_JAVAC ? // https://bugs.eclipse.org/bugs/show_bug.cgi?id=235546 |
| 537 | new EclipseJustification(MismatchType.JavacErrorsEclipseNone) : null; |
| 538 | public static final EclipseJustification |
| 539 | EclipseJustification0001 = RUN_JAVAC ? |
| 540 | new EclipseJustification(MismatchType.EclipseErrorsJavacNone) : null; |
| 541 | /* javac properly detects duplicate attributes in annotations in the |
| 542 | * simplest case (AnnotationTest#18b) but fails on a slightly more |
| 543 | * complex one where the duplicate is within an embedded annotation; |
| 544 | * there seems to be no reason for not reporting the error |
| 545 | * (AnnotationTest#18) */ |
| 546 | } |
| 547 | public static class JavacHasABug extends Excuse { |
| 548 | long pivotCompliance; |
| 549 | int pivotMinor; |
| 550 | int[] minorsFixed; |
| 551 | static final int NO_FIX = -1; |
| 552 | static final int IRRELEVANT = -2; |
| 553 | JavacHasABug(int mismatchType) { |
| 554 | super(mismatchType); |
| 555 | } |
| 556 | // private JavacHasABug(int mismatchType, int[] minorsFixed) { |
| 557 | // super(mismatchType); |
| 558 | // this.minorsFixed = minorsFixed; |
| 559 | // } |
| 560 | private JavacHasABug(int mismatchType, long pivotCompliance, int pivotMinor) { |
| 561 | super(mismatchType); |
| 562 | this.pivotCompliance = pivotCompliance; |
| 563 | this.pivotMinor = pivotMinor; |
| 564 | } |
| 565 | Excuse excuseFor(JavacCompiler compiler) { |
| 566 | if (this.minorsFixed != null) { |
Stephan Herrmann | 5fa7f31 | 2012-07-13 01:52:51 +0200 | [diff] [blame] | 567 | if (compiler.compliance == ClassFileConstants.JDK1_8) { |
| 568 | return this.minorsFixed[5] > compiler.minor || this.minorsFixed[5] < 0 ? |
| 569 | this : null; |
| 570 | } else if (compiler.compliance == ClassFileConstants.JDK1_7) { |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 571 | return this.minorsFixed[4] > compiler.minor || this.minorsFixed[4] < 0 ? |
| 572 | this : null; |
| 573 | } else if (compiler.compliance == ClassFileConstants.JDK1_6) { |
| 574 | return this.minorsFixed[3] > compiler.minor || this.minorsFixed[3] < 0 ? |
| 575 | this : null; |
| 576 | } else if (compiler.compliance == ClassFileConstants.JDK1_5) { |
| 577 | return this.minorsFixed[2] > compiler.minor || this.minorsFixed[2] < 0 ? |
| 578 | this : null; |
| 579 | } else if (compiler.compliance == ClassFileConstants.JDK1_4) { |
| 580 | return this.minorsFixed[1] > compiler.minor || this.minorsFixed[1] < 0 ? |
| 581 | this : null; |
| 582 | } else if (compiler.compliance == ClassFileConstants.JDK1_3) { |
| 583 | return this.minorsFixed[0] > compiler.minor || this.minorsFixed[0] < 0 ? |
| 584 | this : null; |
| 585 | } |
| 586 | throw new RuntimeException(); // should not get there |
| 587 | } else if (this.pivotCompliance > 0) { |
| 588 | if (this.pivotCompliance < compiler.compliance) { |
| 589 | return null; |
| 590 | } else if (this.pivotCompliance > compiler.compliance) { |
| 591 | return this; |
| 592 | } else { |
| 593 | return this.pivotMinor > compiler.minor ? this : null; |
| 594 | } |
| 595 | } else if (this.pivotCompliance < 0) { |
| 596 | if (this.pivotCompliance < -compiler.compliance) { |
| 597 | return null; |
| 598 | } else if (this.pivotCompliance > -compiler.compliance) { |
| 599 | return this; |
| 600 | } else { |
| 601 | return this.pivotMinor <= compiler.minor ? this : null; |
| 602 | } |
| 603 | } |
| 604 | return this; |
| 605 | } |
| 606 | // bugs that we know precisely of |
| 607 | public static JavacHasABug |
| 608 | JavacBug4094180 = RUN_JAVAC ? // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4094180 |
| 609 | new JavacHasABug(MismatchType.EclipseErrorsJavacNone) : null, |
| 610 | JavacBug4660984 = RUN_JAVAC ? // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4660984 & https://bugs.eclipse.org/bugs/show_bug.cgi?id=235555 |
| 611 | new JavacHasABug(MismatchType.JavacErrorsEclipseNone) : null, |
| 612 | JavacBug5042462 = RUN_JAVAC ? // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5042462 & https://bugs.eclipse.org/bugs/show_bug.cgi?id=208873 |
| 613 | new JavacHasABug( |
| 614 | MismatchType.JavacErrorsEclipseNone, |
| 615 | ClassFileConstants.JDK1_7, 0 /* 1.7.0 b17 */) : null, |
| 616 | JavacBug5061359 = RUN_JAVAC ? // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5061359 |
| 617 | new JavacHasABug( |
| 618 | MismatchType.EclipseErrorsJavacNone, |
| 619 | ClassFileConstants.JDK1_7, 0 /* 1.7.0 b03 */) : null, |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 620 | JavacBug6302954 = RUN_JAVAC ? // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6302954 & https://bugs.eclipse.org/bugs/show_bug.cgi?id=98379 |
| 621 | new JavacHasABug( |
| 622 | MismatchType.JavacErrorsEclipseNone, |
| 623 | ClassFileConstants.JDK1_7, 0 /* 1.7.0 b03 */) : null, |
| 624 | JavacBug6400189 = RUN_JAVAC ? // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6400189 & https://bugs.eclipse.org/bugs/show_bug.cgi?id=106744 & https://bugs.eclipse.org/bugs/show_bug.cgi?id=167952 |
| 625 | new JavacHasABug( |
Stephan Herrmann | c1c4862 | 2014-01-04 23:19:31 +0100 | [diff] [blame] | 626 | MismatchType.EclipseErrorsJavacNone) { |
| 627 | Excuse excuseFor(JavacCompiler compiler) { |
| 628 | return compiler.compliance == ClassFileConstants.JDK1_6 ? this : null; |
| 629 | } |
| 630 | } : null, |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 631 | JavacBug6500701 = RUN_JAVAC ? // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6500701 & https://bugs.eclipse.org/bugs/show_bug.cgi?id=209779 |
| 632 | new JavacHasABug( |
Stephan Herrmann | c1c4862 | 2014-01-04 23:19:31 +0100 | [diff] [blame] | 633 | MismatchType.StandardOutputMismatch, |
| 634 | ClassFileConstants.JDK1_7, 0) : null, |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 635 | JavacBug6531075 = RUN_JAVAC ? // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6531075 |
| 636 | new JavacHasABug( |
| 637 | MismatchType.StandardOutputMismatch, |
| 638 | ClassFileConstants.JDK1_7, 0) : null, // fixed in jdk7 b27; unfortunately, we do not have a distinct minor for this, hence former jdk7s will report an unused excuse |
| 639 | JavacBug6569404 = RUN_JAVAC ? // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6569404 |
| 640 | new JavacHasABug( |
Stephan Herrmann | c1c4862 | 2014-01-04 23:19:31 +0100 | [diff] [blame] | 641 | MismatchType.JavacErrorsEclipseNone) { |
| 642 | Excuse excuseFor(JavacCompiler compiler) { |
| 643 | // present only in javac6 between 1.6.0_10_b08 and EOL |
| 644 | return (compiler.compliance == ClassFileConstants.JDK1_6 && compiler.minor >= 10) ? this : null; |
| 645 | } |
| 646 | } : null, |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 647 | JavacBug6557661 = RUN_JAVAC ? // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6557661 & https://bugs.eclipse.org/bugs/show_bug.cgi?id=129261 |
| 648 | new JavacHasABug( |
| 649 | MismatchType.EclipseErrorsJavacNone) : null, |
| 650 | JavacBug6573446 = RUN_JAVAC ? // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6573446 & https://bugs.eclipse.org/bugs/show_bug.cgi?id=190945 |
| 651 | new JavacHasABug( |
| 652 | MismatchType.EclipseErrorsJavacNone) : null, |
| 653 | JavacBug6575821 = RUN_JAVAC ? // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6575821 |
| 654 | new JavacHasABug( |
| 655 | MismatchType.JavacErrorsEclipseNone, |
Stephan Herrmann | ae70795 | 2015-10-30 22:28:02 +0100 | [diff] [blame^] | 656 | ClassFileConstants.JDK1_6, 10 /* 1.6.0_10_b08 or better - maybe before */) : null, |
| 657 | JavacBug8033810 = RUN_JAVAC ? // https://bugs.openjdk.java.net/browse/JDK-8033810 |
| 658 | new JavacHasABug(MismatchType.EclipseErrorsJavacNone) : null; |
| 659 | |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 660 | // bugs that have been fixed but that we've not identified |
| 661 | public static JavacHasABug |
| 662 | JavacBugFixed_6_10 = RUN_JAVAC ? |
| 663 | new JavacHasABug( |
| 664 | 0 /* all */, |
| 665 | ClassFileConstants.JDK1_6, 1000 /* 1.6.0_10_b08 or better - maybe before */) : null, |
| 666 | JavacBugFixed_6_10_b24 = RUN_JAVAC ? |
| 667 | new JavacHasABug( |
| 668 | 0 /* all */, |
| 669 | ClassFileConstants.JDK1_6, 1010 /* 1.6.0_10_b24 or better - maybe before */) : null, |
| 670 | JavacBugFixed_7 = RUN_JAVAC ? |
| 671 | new JavacHasABug( |
| 672 | 0 /* all */, |
| 673 | ClassFileConstants.JDK1_7, 0 /* 1.7.0_b24 or better - maybe before */) : null; |
| 674 | // bugs that have neither been fixed nor formally identified but which outcomes are obvious enough to clear any doubts |
| 675 | public static JavacHasABug |
| 676 | JavacGeneratesByteCodeUponWhichJavaThrowsAnException = RUN_JAVAC ? |
| 677 | new JavacHasABug( |
| 678 | MismatchType.StandardOutputMismatch) : null, |
| 679 | JavacThrowsAnException = RUN_JAVAC ? // some of these are transient - that is, depend on the system on which the test is run, aka stack overflow |
| 680 | new JavacHasABug( |
| 681 | MismatchType.JavacErrorsEclipseNone) : null, |
| 682 | JavacThrowsAnExceptionForJava_1_5_0_16 = RUN_JAVAC ? |
| 683 | new JavacHasABug( |
| 684 | MismatchType.JavacErrorsEclipseNone) { |
| 685 | Excuse excuseFor(JavacCompiler compiler) { |
| 686 | return compiler.compliance != ClassFileConstants.JDK1_5 || |
| 687 | compiler.minor != 1600 ? null : this; |
| 688 | } |
Stephan Herrmann | f087af3 | 2014-01-04 01:36:05 +0100 | [diff] [blame] | 689 | }: null; |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | |
| 693 | // PREMATURE: Logger helps us monitor processes outputs (standard and error); |
| 694 | // some asynchronous mechanism is needed here since not consuming |
| 695 | // the streams fast enough can result into bad behaviors (as |
| 696 | // documented in Process); however, we could have a single worker |
| 697 | // take care of this |
| 698 | static class Logger extends Thread { |
| 699 | StringBuffer buffer; |
| 700 | InputStream inputStream; |
| 701 | String type; |
| 702 | Logger(InputStream inputStream, String type) { |
| 703 | this.inputStream = inputStream; |
| 704 | this.type = type; |
| 705 | this.buffer = new StringBuffer(); |
| 706 | } |
| 707 | Logger(InputStream inputStream, String type, StringBuffer buffer) { |
| 708 | this.inputStream = inputStream; |
| 709 | this.type = type; |
| 710 | this.buffer = buffer; |
| 711 | } |
| 712 | |
| 713 | public void run() { |
| 714 | try { |
| 715 | BufferedReader reader = new BufferedReader(new InputStreamReader(this.inputStream)); |
| 716 | String line = null; |
| 717 | while ((line = reader.readLine()) != null) { |
| 718 | this.buffer./*append(this.type).append("->").*/append(line).append("\n"); |
| 719 | } |
| 720 | reader.close(); |
| 721 | } catch (IOException e) { |
| 722 | e.printStackTrace(); |
| 723 | } |
| 724 | } |
| 725 | } |
| 726 | protected static int[] DIFF_COUNTERS = new int[3]; |
| 727 | protected static final String EVAL_DIRECTORY = Util.getOutputDirectory() + File.separator + "eval"; |
| 728 | public static int INDENT = 2; |
| 729 | protected static final String JAVA_NAME = |
| 730 | File.pathSeparatorChar == ':' ? "java" : "java.exe"; |
| 731 | protected static final String JAVAC_NAME = |
| 732 | File.pathSeparatorChar == ':' ? "javac" : "javac.exe"; |
| 733 | |
| 734 | protected static String JAVAC_OUTPUT_DIR_NAME = |
| 735 | Util.getOutputDirectory() + File.separator + "javac"; |
| 736 | static File JAVAC_OUTPUT_DIR; |
| 737 | protected static String javacCommandLineHeader; |
| 738 | protected static PrintWriter javacFullLog; |
| 739 | // flags errors so that any error in a test case prevents |
| 740 | // java execution |
| 741 | private static String javacFullLogFileName; |
| 742 | protected static String javaCommandLineHeader; |
| 743 | |
| 744 | // needed for multiple test calls within a single test method |
| 745 | protected static boolean javacTestErrorFlag; |
| 746 | |
| 747 | protected static String javacTestName; |
| 748 | |
| 749 | protected static IPath jdkRootDirPath; |
| 750 | |
| 751 | // list of available javac compilers, as defined by the jdk.roots |
| 752 | // variable, which should hold a File.pathSeparatorChar separated |
| 753 | // list of paths for to-be-tested JDK root directories |
| 754 | protected static List javacCompilers = null; |
| 755 | |
| 756 | public static final String OUTPUT_DIR = Util.getOutputDirectory() + File.separator + "regression"; |
| 757 | public static final String LIB_DIR = Util.getOutputDirectory() + File.separator + "lib"; |
| 758 | |
| 759 | public final static String PACKAGE_INFO_NAME = new String(TypeConstants.PACKAGE_INFO_NAME); |
| 760 | |
| 761 | public static boolean SHIFT = false; |
| 762 | |
| 763 | protected static final String SOURCE_DIRECTORY = Util.getOutputDirectory() + File.separator + "source"; |
| 764 | |
| 765 | protected String[] classpaths; |
| 766 | protected boolean createdVerifier; |
| 767 | protected INameEnvironment javaClassLib; |
| 768 | protected TestVerifier verifier; |
Stephan Herrmann | 4194d17 | 2014-11-11 21:35:54 +0100 | [diff] [blame] | 769 | protected boolean shouldSwallowCaptureId; |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 770 | public AbstractRegressionTest(String name) { |
| 771 | super(name); |
| 772 | } |
| 773 | protected void checkClassFile(String className, String source, String expectedOutput) throws ClassFormatException, IOException { |
| 774 | this.checkClassFile("", className, source, expectedOutput, ClassFileBytesDisassembler.SYSTEM); |
| 775 | } |
| 776 | protected void checkClassFile(String className, String source, String expectedOutput, int mode) throws ClassFormatException, IOException { |
| 777 | this.checkClassFile("", className, source, expectedOutput, mode); |
| 778 | } |
| 779 | protected void checkClassFile(String directoryName, String className, String disassembledClassName, String source, String expectedOutput, int mode) throws ClassFormatException, IOException { |
| 780 | compileAndDeploy(source, directoryName, className); |
| 781 | try { |
| 782 | File directory = new File(EVAL_DIRECTORY, directoryName); |
| 783 | if (!directory.exists()) { |
| 784 | assertTrue(".class file not generated properly in " + directory, false); |
| 785 | } |
| 786 | File f = new File(directory, disassembledClassName + ".class"); |
| 787 | byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f); |
| 788 | ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); |
| 789 | String result = disassembler.disassemble(classFileBytes, "\n", mode); |
| 790 | int index = result.indexOf(expectedOutput); |
| 791 | if (index == -1 || expectedOutput.length() == 0) { |
| 792 | System.out.println(Util.displayString(result, 3)); |
| 793 | } |
| 794 | if (index == -1) { |
| 795 | assertEquals("Wrong contents", expectedOutput, result); |
| 796 | } |
| 797 | FileInputStream stream = null; |
| 798 | try { |
| 799 | stream = new FileInputStream(f); |
| 800 | ClassFileReader.read(stream, className + ".class", true); |
| 801 | } catch (org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException e) { |
| 802 | e.printStackTrace(); |
| 803 | assertTrue("ClassFormatException", false); |
| 804 | } catch (IOException e) { |
| 805 | e.printStackTrace(); |
| 806 | assertTrue("IOException", false); |
| 807 | } finally { |
| 808 | if (stream != null) { |
| 809 | try { |
| 810 | stream.close(); |
| 811 | } catch (IOException e) { |
| 812 | /* ignore */ |
| 813 | } |
| 814 | } |
| 815 | } |
| 816 | } finally { |
| 817 | removeTempClass(className); |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | protected void checkClassFile(String directoryName, String className, String source, String expectedOutput, int mode) throws ClassFormatException, IOException { |
| 822 | this.checkClassFile(directoryName, className, className, source, expectedOutput, mode); |
| 823 | } |
| 824 | |
| 825 | protected ClassFileReader getInternalClassFile(String directoryName, String className, String disassembledClassName, String source) throws ClassFormatException, IOException { |
| 826 | compileAndDeploy(source, directoryName, className); |
| 827 | try { |
| 828 | File directory = new File(EVAL_DIRECTORY, directoryName); |
| 829 | if (!directory.exists()) { |
| 830 | assertTrue(".class file not generated properly in " + directory, false); |
| 831 | } |
| 832 | File f = new File(directory, disassembledClassName + ".class"); |
| 833 | ClassFileReader classFileReader = null; |
| 834 | FileInputStream stream = null; |
| 835 | try { |
| 836 | stream = new FileInputStream(f); |
| 837 | classFileReader = ClassFileReader.read(stream, className + ".class", true); |
| 838 | } catch (org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException e) { |
| 839 | e.printStackTrace(); |
| 840 | assertTrue("ClassFormatException", false); |
| 841 | } catch (IOException e) { |
| 842 | e.printStackTrace(); |
| 843 | assertTrue("IOException", false); |
| 844 | } finally { |
| 845 | if (stream != null) { |
| 846 | try { |
| 847 | stream.close(); |
| 848 | } catch (IOException e) { |
| 849 | /* ignore */ |
| 850 | } |
| 851 | } |
| 852 | } |
| 853 | return classFileReader; |
| 854 | } finally { |
| 855 | removeTempClass(className); |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | protected void checkDisassembledClassFile(String fileName, String className, String expectedOutput) throws Exception { |
| 860 | this.checkDisassembledClassFile(fileName, className, expectedOutput, ClassFileBytesDisassembler.DETAILED); |
| 861 | } |
| 862 | protected void checkDisassembledClassFile(String fileName, String className, String expectedOutput, int mode) throws Exception { |
| 863 | File classFile = new File(fileName); |
| 864 | if (!classFile.exists()) { |
| 865 | assertTrue(".class file doesn't exist", false); |
| 866 | } |
| 867 | byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(classFile); |
| 868 | ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler(); |
| 869 | String result = disassembler.disassemble(classFileBytes, "\n", mode); |
| 870 | int index = result.indexOf(expectedOutput); |
| 871 | if (index == -1 || expectedOutput.length() == 0) { |
| 872 | System.out.println(Util.displayString(result, 2)); |
| 873 | } |
| 874 | if (index == -1) { |
| 875 | assertEquals("Wrong contents", expectedOutput, result); |
| 876 | } |
| 877 | FileInputStream stream = null; |
| 878 | try { |
| 879 | stream = new FileInputStream(classFile); |
| 880 | ClassFileReader.read(stream, className + ".class", true); |
| 881 | } finally { |
| 882 | if (stream != null) { |
| 883 | try { |
| 884 | stream.close(); |
| 885 | } catch (IOException e) { |
| 886 | /* ignore */ |
| 887 | } |
| 888 | } |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | protected void compileAndDeploy(String source, String directoryName, String className) { |
| 893 | File directory = new File(SOURCE_DIRECTORY); |
| 894 | if (!directory.exists()) { |
| 895 | if (!directory.mkdirs()) { |
| 896 | System.out.println("Could not create " + SOURCE_DIRECTORY); |
| 897 | return; |
| 898 | } |
| 899 | } |
| 900 | if (directoryName != null && directoryName.length() != 0) { |
| 901 | directory = new File(SOURCE_DIRECTORY, directoryName); |
| 902 | if (!directory.exists()) { |
| 903 | if (!directory.mkdirs()) { |
| 904 | System.out.println("Could not create " + directory); |
| 905 | return; |
| 906 | } |
| 907 | } |
| 908 | } |
| 909 | String fileName = directory.getAbsolutePath() + File.separator + className + ".java"; |
| 910 | try { |
| 911 | BufferedWriter writer = new BufferedWriter(new FileWriter(fileName)); |
| 912 | writer.write(source); |
| 913 | writer.flush(); |
| 914 | writer.close(); |
| 915 | } catch (IOException e) { |
| 916 | e.printStackTrace(); |
| 917 | return; |
| 918 | } |
| 919 | StringBuffer buffer = new StringBuffer() |
| 920 | .append("\"") |
| 921 | .append(fileName) |
| 922 | .append("\" -d \"") |
| 923 | .append(EVAL_DIRECTORY); |
Stephan Herrmann | 075533e | 2015-04-28 17:54:14 +0200 | [diff] [blame] | 924 | String processAnnot = this.enableAPT ? "" : "-proc:none"; |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 925 | if (this.complianceLevel < ClassFileConstants.JDK1_5) { |
| 926 | buffer.append("\" -1.4 -source 1.3 -target 1.2"); |
| 927 | } else if (this.complianceLevel == ClassFileConstants.JDK1_5) { |
| 928 | buffer.append("\" -1.5"); |
| 929 | } else if (this.complianceLevel == ClassFileConstants.JDK1_6) { |
Stephan Herrmann | 075533e | 2015-04-28 17:54:14 +0200 | [diff] [blame] | 930 | buffer.append("\" -1.6 " + processAnnot); |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 931 | } else if (this.complianceLevel == ClassFileConstants.JDK1_7) { |
Stephan Herrmann | 075533e | 2015-04-28 17:54:14 +0200 | [diff] [blame] | 932 | buffer.append("\" -1.7 " + processAnnot); |
Stephan Herrmann | 5fa7f31 | 2012-07-13 01:52:51 +0200 | [diff] [blame] | 933 | } else if (this.complianceLevel == ClassFileConstants.JDK1_8) { |
Stephan Herrmann | 075533e | 2015-04-28 17:54:14 +0200 | [diff] [blame] | 934 | buffer.append("\" -1.8 " + processAnnot); |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 935 | } |
| 936 | buffer |
| 937 | .append(" -preserveAllLocals -nowarn -g -classpath \"") |
| 938 | .append(Util.getJavaClassLibsAsString()) |
| 939 | .append(SOURCE_DIRECTORY) |
| 940 | .append("\""); |
| 941 | BatchCompiler.compile(buffer.toString(), new PrintWriter(System.out), new PrintWriter(System.err), null/*progress*/); |
| 942 | } |
| 943 | |
| 944 | /* |
| 945 | * Compute the problem log from given requestor and compare the result to |
| 946 | * the expected one. |
| 947 | * When there's a difference, display the expected output in the console as |
| 948 | * code string to allow easy copy/paste in the test to fix the failure. |
| 949 | * Also write test files to the console output. |
| 950 | * Fail if exception is non null. |
| 951 | */ |
| 952 | protected void checkCompilerLog(String[] testFiles, Requestor requestor, |
Stephan Herrmann | 4d07945 | 2014-03-27 18:01:49 +0100 | [diff] [blame] | 953 | String[] alternatePlatformIndependantExpectedLogs, Throwable exception) { |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 954 | String computedProblemLog = Util.convertToIndependantLineDelimiter(requestor.problemLog.toString()); |
Stephan Herrmann | 4194d17 | 2014-11-11 21:35:54 +0100 | [diff] [blame] | 955 | if (this.shouldSwallowCaptureId) |
| 956 | computedProblemLog = Pattern.compile("capture#(\\d+)").matcher(computedProblemLog).replaceAll("capture"); |
| 957 | |
Stephan Herrmann | 4d07945 | 2014-03-27 18:01:49 +0100 | [diff] [blame] | 958 | int i; |
| 959 | for (i = 0; i < alternatePlatformIndependantExpectedLogs.length; i++) { |
| 960 | if (alternatePlatformIndependantExpectedLogs[i].equals(computedProblemLog)) |
| 961 | return; // OK |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 962 | } |
Stephan Herrmann | 4d07945 | 2014-03-27 18:01:49 +0100 | [diff] [blame] | 963 | logTestTitle(); |
| 964 | System.out.println(Util.displayString(computedProblemLog, INDENT, SHIFT)); |
| 965 | logTestFiles(false, testFiles); |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 966 | if (exception == null) { |
Stephan Herrmann | 4d07945 | 2014-03-27 18:01:49 +0100 | [diff] [blame] | 967 | assertEquals("Invalid problem log ", alternatePlatformIndependantExpectedLogs[i-1], computedProblemLog); |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 968 | } |
| 969 | } |
| 970 | |
| 971 | protected void dualPrintln(String message) { |
| 972 | System.out.println(message); |
| 973 | javacFullLog.println(message); |
| 974 | } |
| 975 | protected void executeClass( |
| 976 | String sourceFile, |
| 977 | String expectedSuccessOutputString, |
| 978 | String[] classLib, |
| 979 | boolean shouldFlushOutputDirectory, |
| 980 | String[] vmArguments, |
| 981 | Map customOptions, |
| 982 | ICompilerRequestor clientRequestor) { |
| 983 | |
| 984 | // Compute class name by removing ".java" and replacing slashes with dots |
| 985 | String className = sourceFile.substring(0, sourceFile.length() - 5).replace('/', '.').replace('\\', '.'); |
| 986 | if (className.endsWith(PACKAGE_INFO_NAME)) return; |
| 987 | |
| 988 | if (vmArguments != null) { |
| 989 | if (this.verifier != null) { |
| 990 | this.verifier.shutDown(); |
| 991 | } |
| 992 | this.verifier = new TestVerifier(false); |
| 993 | this.createdVerifier = true; |
| 994 | } |
| 995 | boolean passed = |
| 996 | this.verifier.verifyClassFiles( |
| 997 | sourceFile, |
| 998 | className, |
| 999 | expectedSuccessOutputString, |
| 1000 | this.classpaths, |
| 1001 | null, |
| 1002 | vmArguments); |
| 1003 | assertTrue(this.verifier.failureReason, // computed by verifyClassFiles(...) action |
| 1004 | passed); |
| 1005 | if (vmArguments != null) { |
| 1006 | if (this.verifier != null) { |
| 1007 | this.verifier.shutDown(); |
| 1008 | } |
| 1009 | this.verifier = new TestVerifier(false); |
| 1010 | this.createdVerifier = true; |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | /* |
| 1015 | * Returns the references in the given .class file. |
| 1016 | */ |
| 1017 | protected String findReferences(String classFilePath) { |
| 1018 | // check that "new Z().init()" is bound to "AbstractB.init()" |
| 1019 | final StringBuffer references = new StringBuffer(10); |
| 1020 | final SearchParticipant participant = new JavaSearchParticipant() { |
| 1021 | final SearchParticipant searchParticipant = this; |
| 1022 | public SearchDocument getDocument(final String documentPath) { |
| 1023 | return new SearchDocument(documentPath, this.searchParticipant) { |
| 1024 | public byte[] getByteContents() { |
| 1025 | try { |
| 1026 | return org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(new File(getPath())); |
| 1027 | } catch (IOException e) { |
| 1028 | e.printStackTrace(); |
| 1029 | return null; |
| 1030 | } |
| 1031 | } |
| 1032 | public char[] getCharContents() { |
| 1033 | // not used |
| 1034 | return null; |
| 1035 | } |
| 1036 | public String getEncoding() { |
| 1037 | // not used |
| 1038 | return null; |
| 1039 | } |
| 1040 | }; |
| 1041 | } |
| 1042 | }; |
| 1043 | SearchDocument document = participant.getDocument(new File(classFilePath).getPath()); |
| 1044 | BinaryIndexer indexer = new BinaryIndexer(document) { |
| 1045 | protected void addIndexEntry(char[] category, char[] key) { |
| 1046 | references.append(category); |
| 1047 | references.append('/'); |
| 1048 | references.append(key); |
| 1049 | references.append('\n'); |
| 1050 | } |
| 1051 | }; |
| 1052 | indexer.indexDocument(); |
| 1053 | String computedReferences = references.toString(); |
| 1054 | return computedReferences; |
| 1055 | } |
| 1056 | |
| 1057 | protected ClassFileReader getClassFileReader(String fileName, String className) { |
| 1058 | File classFile = new File(fileName); |
| 1059 | if (!classFile.exists()) { |
| 1060 | assertTrue(".class file doesn't exist", false); |
| 1061 | } |
| 1062 | FileInputStream stream = null; |
| 1063 | try { |
| 1064 | stream = new FileInputStream(classFile); |
| 1065 | ClassFileReader reader = ClassFileReader.read(stream, className + ".class", true); |
| 1066 | return reader; |
| 1067 | } catch (org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException e) { |
| 1068 | e.printStackTrace(); |
| 1069 | assertTrue("ClassFormatException", false); |
| 1070 | } catch (IOException e) { |
| 1071 | e.printStackTrace(); |
| 1072 | assertTrue("IOException", false); |
| 1073 | } finally { |
| 1074 | if (stream != null) { |
| 1075 | try { |
| 1076 | stream.close(); |
| 1077 | } catch (IOException e) { |
| 1078 | /* ignore */ |
| 1079 | } |
| 1080 | } |
| 1081 | } |
| 1082 | return null; |
| 1083 | } |
| 1084 | |
Stephan Herrmann | 618f692 | 2012-08-10 22:00:05 +0200 | [diff] [blame] | 1085 | protected INameEnvironment[] getClassLibs(boolean useDefaultClasspaths) { |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 1086 | String encoding = (String)getCompilerOptions().get(CompilerOptions.OPTION_Encoding); |
| 1087 | if ("".equals(encoding)) |
| 1088 | encoding = null; |
Stephan Herrmann | 618f692 | 2012-08-10 22:00:05 +0200 | [diff] [blame] | 1089 | if (useDefaultClasspaths && encoding == null) |
| 1090 | return DefaultJavaRuntimeEnvironment.create(this.classpaths); |
| 1091 | // fall back to FileSystem |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 1092 | INameEnvironment[] classLibs = new INameEnvironment[1]; |
| 1093 | classLibs[0] = new FileSystem(this.classpaths, new String[]{}, // ignore initial file names |
| 1094 | encoding // default encoding |
| 1095 | ); |
| 1096 | return classLibs; |
| 1097 | } |
| 1098 | protected Map getCompilerOptions() { |
| 1099 | Map defaultOptions = super.getCompilerOptions(); |
| 1100 | defaultOptions.put(CompilerOptions.OPTION_LocalVariableAttribute, CompilerOptions.GENERATE); |
| 1101 | defaultOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.WARNING); |
| 1102 | defaultOptions.put(CompilerOptions.OPTION_ReportUnusedImport, CompilerOptions.WARNING); |
| 1103 | defaultOptions.put(CompilerOptions.OPTION_ReportLocalVariableHiding, CompilerOptions.WARNING); |
| 1104 | defaultOptions.put(CompilerOptions.OPTION_ReportFieldHiding, CompilerOptions.WARNING); |
| 1105 | defaultOptions.put(CompilerOptions.OPTION_ReportPossibleAccidentalBooleanAssignment, CompilerOptions.WARNING); |
| 1106 | defaultOptions.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.WARNING); |
| 1107 | defaultOptions.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.PRESERVE); |
| 1108 | defaultOptions.put(CompilerOptions.OPTION_ReportUnnecessaryElse, CompilerOptions.WARNING ); |
| 1109 | defaultOptions.put(CompilerOptions.OPTION_ReportDeadCode, CompilerOptions.WARNING); |
| 1110 | //{ObjectTeams: try to let our keywords not interfere with pure Java tests: |
| 1111 | defaultOptions.put(CompilerOptions.OPTION_AllowScopedKeywords, CompilerOptions.ENABLED); |
| 1112 | // SH} |
| 1113 | return defaultOptions; |
| 1114 | } |
| 1115 | |
| 1116 | protected String[] getDefaultClassPaths() { |
Stephan Herrmann | 618f692 | 2012-08-10 22:00:05 +0200 | [diff] [blame] | 1117 | return DefaultJavaRuntimeEnvironment.getDefaultClassPaths(); |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 1118 | } |
Stephan Herrmann | 7c411a0 | 2013-12-29 14:47:52 +0100 | [diff] [blame] | 1119 | /** Get class library paths built from default class paths plus the JDT null annotations. */ |
Stephan Herrmann | aaa73af | 2013-12-29 16:34:59 +0100 | [diff] [blame] | 1120 | protected String[] getLibsWithNullAnnotations(long sourceLevel) throws IOException { |
Stephan Herrmann | 7c411a0 | 2013-12-29 14:47:52 +0100 | [diff] [blame] | 1121 | String[] defaultLibs = getDefaultClassPaths(); |
| 1122 | int len = defaultLibs.length; |
| 1123 | String[] libs = new String[len+1]; |
| 1124 | System.arraycopy(defaultLibs, 0, libs, 0, len); |
Stephan Herrmann | aaa73af | 2013-12-29 16:34:59 +0100 | [diff] [blame] | 1125 | String version = sourceLevel < ClassFileConstants.JDK1_8 ? "[1.1.0,2.0.0)" : "[2.0.0,3.0.0)"; |
| 1126 | Bundle[] bundles = Platform.getBundles("org.eclipse.jdt.annotation", version); |
| 1127 | File bundleFile = FileLocator.getBundleFile(bundles[0]); |
Stephan Herrmann | 7c411a0 | 2013-12-29 14:47:52 +0100 | [diff] [blame] | 1128 | if (bundleFile.isDirectory()) |
| 1129 | libs[len] = bundleFile.getPath()+"/bin"; |
| 1130 | else |
| 1131 | libs[len] = bundleFile.getPath(); |
| 1132 | return libs; |
| 1133 | } |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 1134 | protected IErrorHandlingPolicy getErrorHandlingPolicy() { |
| 1135 | return new IErrorHandlingPolicy() { |
| 1136 | public boolean stopOnFirstError() { |
| 1137 | return false; |
| 1138 | } |
| 1139 | public boolean proceedOnErrors() { |
| 1140 | return true; |
| 1141 | } |
Stephan Herrmann | 307ebe3 | 2013-05-02 02:46:05 +0200 | [diff] [blame] | 1142 | public boolean ignoreAllErrors() { |
| 1143 | return false; |
| 1144 | } |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 1145 | }; |
| 1146 | } |
| 1147 | /* |
| 1148 | * Will consider first the source units passed as arguments, then investigate the classpath: jdklib + output dir |
| 1149 | */ |
| 1150 | protected INameEnvironment getNameEnvironment(final String[] testFiles, String[] classPaths) { |
| 1151 | this.classpaths = classPaths == null ? getDefaultClassPaths() : classPaths; |
Stephan Herrmann | 618f692 | 2012-08-10 22:00:05 +0200 | [diff] [blame] | 1152 | return new InMemoryNameEnvironment(testFiles, getClassLibs(classPaths == null)); |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 1153 | } |
| 1154 | protected IProblemFactory getProblemFactory() { |
| 1155 | return new DefaultProblemFactory(Locale.getDefault()); |
| 1156 | } |
| 1157 | |
| 1158 | public void initialize(CompilerTestSetup setUp) { |
| 1159 | super.initialize(setUp); |
| 1160 | if (setUp instanceof RegressionTestSetup) { |
| 1161 | RegressionTestSetup regressionTestSetUp = (RegressionTestSetup)setUp; |
| 1162 | this.javaClassLib = regressionTestSetUp.javaClassLib; |
| 1163 | this.verifier = regressionTestSetUp.verifier; |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | void logTestFiles(boolean logTitle, String[] testFiles) { |
| 1168 | if (logTitle) { |
| 1169 | logTestTitle(); |
| 1170 | } |
| 1171 | for (int i = 0; i < testFiles.length; i += 2) { |
| 1172 | System.out.print(testFiles[i]); |
| 1173 | System.out.println(" ["); //$NON-NLS-1$ |
| 1174 | System.out.println(testFiles[i + 1]); |
| 1175 | System.out.println("]"); //$NON-NLS-1$ |
| 1176 | } |
| 1177 | } |
| 1178 | void logTestTitle() { |
| 1179 | System.out.println(getClass().getName() + '#' + getName()); |
| 1180 | } |
| 1181 | |
| 1182 | /* |
| 1183 | * Write given source test files in current output sub-directory. |
| 1184 | * Use test name for this sub-directory name (ie. test001, test002, etc...) |
| 1185 | */ |
| 1186 | protected void printFiles(String[] testFiles) { |
| 1187 | for (int i=0, length=testFiles.length; i<length; i++) { |
| 1188 | System.out.println(testFiles[i++]); |
| 1189 | System.out.println(testFiles[i]); |
| 1190 | } |
| 1191 | System.out.println(""); |
| 1192 | } |
| 1193 | protected void printJavacResultsSummary() { |
| 1194 | if (RUN_JAVAC) { |
| 1195 | Integer count = (Integer)TESTS_COUNTERS.get(CURRENT_CLASS_NAME); |
| 1196 | if (count != null) { |
| 1197 | int newCount = count.intValue()-1; |
| 1198 | TESTS_COUNTERS.put(CURRENT_CLASS_NAME, new Integer(newCount)); |
| 1199 | if (newCount == 0) { |
| 1200 | if (DIFF_COUNTERS[0]!=0 || DIFF_COUNTERS[1]!=0 || DIFF_COUNTERS[2]!=0) { |
| 1201 | dualPrintln("==========================================================================="); |
| 1202 | dualPrintln("Results summary:"); |
| 1203 | } |
| 1204 | if (DIFF_COUNTERS[0]!=0) |
| 1205 | dualPrintln(" - "+DIFF_COUNTERS[0]+" test(s) where Javac found errors/warnings but Eclipse did not"); |
| 1206 | if (DIFF_COUNTERS[1]!=0) |
| 1207 | dualPrintln(" - "+DIFF_COUNTERS[1]+" test(s) where Eclipse found errors/warnings but Javac did not"); |
| 1208 | if (DIFF_COUNTERS[2]!=0) |
| 1209 | dualPrintln(" - "+DIFF_COUNTERS[2]+" test(s) where Eclipse and Javac did not have same output"); |
| 1210 | System.out.println("\n"); |
| 1211 | } |
| 1212 | } |
| 1213 | dualPrintln("\n\nFull results sent to " + javacFullLogFileName); |
| 1214 | javacFullLog.flush(); |
| 1215 | } |
| 1216 | } |
| 1217 | protected void removeTempClass(String className) { |
| 1218 | File dir = new File(SOURCE_DIRECTORY); |
| 1219 | String[] fileNames = dir.list(); |
| 1220 | if (fileNames != null) { |
| 1221 | for (int i = 0, max = fileNames.length; i < max; i++) { |
| 1222 | if (fileNames[i].indexOf(className) != -1) { |
| 1223 | Util.delete(SOURCE_DIRECTORY + File.separator + fileNames[i]); |
| 1224 | } |
| 1225 | } |
| 1226 | } |
| 1227 | |
| 1228 | dir = new File(EVAL_DIRECTORY); |
| 1229 | fileNames = dir.list(); |
| 1230 | if (fileNames != null) { |
| 1231 | for (int i = 0, max = fileNames.length; i < max; i++) { |
| 1232 | if (fileNames[i].indexOf(className) != -1) { |
| 1233 | Util.delete(EVAL_DIRECTORY + File.separator + fileNames[i]); |
| 1234 | } |
| 1235 | } |
| 1236 | } |
| 1237 | |
| 1238 | } |
| 1239 | |
| 1240 | // WORK replace null logs (no test) by empty string in most situations (more |
| 1241 | // complete coverage) and see what happens |
| 1242 | protected void runConformTest(String[] testFiles) { |
| 1243 | runTest( |
| 1244 | // test directory preparation |
| 1245 | true /* flush output directory */, |
| 1246 | testFiles /* test files */, |
| 1247 | // compiler options |
| 1248 | null /* no class libraries */, |
| 1249 | null /* no custom options */, |
| 1250 | false /* do not perform statements recovery */, |
| 1251 | null /* no custom requestor */, |
| 1252 | // compiler results |
| 1253 | false /* expecting no compiler errors */, |
| 1254 | null /* do not check compiler log */, |
| 1255 | // runtime options |
| 1256 | false /* do not force execution */, |
| 1257 | null /* no vm arguments */, |
| 1258 | // runtime results |
| 1259 | null /* do not check output string */, |
| 1260 | null /* do not check error string */, |
| 1261 | // javac options |
| 1262 | JavacTestOptions.DEFAULT /* default javac test options */); |
| 1263 | } |
| 1264 | |
| 1265 | // WORK replace null logs (no test) by empty string in most situations (more |
| 1266 | // complete coverage) and see what happens |
| 1267 | protected void runConformTest(String[] testFiles, ASTVisitor visitor) { |
| 1268 | runTest( |
| 1269 | // test directory preparation |
| 1270 | true /* flush output directory */, |
| 1271 | testFiles /* test files */, |
Stephan Herrmann | de4efa9 | 2010-09-26 16:11:28 +0000 | [diff] [blame] | 1272 | new String[] {}, |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 1273 | // compiler options |
| 1274 | null /* no class libraries */, |
| 1275 | null /* no custom options */, |
| 1276 | false /* do not perform statements recovery */, |
| 1277 | null /* no custom requestor */, |
| 1278 | // compiler results |
| 1279 | false /* expecting no compiler errors */, |
| 1280 | null /* do not check compiler log */, |
Stephan Herrmann | 4d07945 | 2014-03-27 18:01:49 +0100 | [diff] [blame] | 1281 | null /* no alternate compiler logs */, |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 1282 | // runtime options |
| 1283 | false /* do not force execution */, |
| 1284 | null /* no vm arguments */, |
| 1285 | // runtime results |
| 1286 | null /* do not check output string */, |
| 1287 | null /* do not check error string */, |
| 1288 | visitor, |
| 1289 | // javac options |
| 1290 | JavacTestOptions.DEFAULT /* default javac test options */); |
| 1291 | } |
| 1292 | |
| 1293 | protected void runConformTest(String[] testFiles, String expectedOutputString) { |
Stephan Herrmann | ae70795 | 2015-10-30 22:28:02 +0100 | [diff] [blame^] | 1294 | runConformTest(false, JavacTestOptions.DEFAULT, testFiles, expectedOutputString); |
| 1295 | } |
| 1296 | protected void runConformTest(boolean skipJavac, JavacTestOptions javacTestOptions, String[] testFiles, String expectedOutputString) { |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 1297 | runTest( |
Stephan Herrmann | 13a070b | 2010-04-02 03:54:26 +0000 | [diff] [blame] | 1298 | // test directory preparation |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 1299 | true /* flush output directory */, |
| 1300 | testFiles /* test files */, |
| 1301 | // compiler options |
| 1302 | null /* no class libraries */, |
| 1303 | null /* no custom options */, |
| 1304 | false /* do not perform statements recovery */, |
| 1305 | null /* no custom requestor */, |
| 1306 | // compiler results |
| 1307 | false /* expecting no compiler errors */, |
| 1308 | null /* do not check compiler log */, |
| 1309 | // runtime options |
| 1310 | false /* do not force execution */, |
| 1311 | null /* no vm arguments */, |
| 1312 | // runtime results |
| 1313 | expectedOutputString /* expected output string */, |
| 1314 | null /* do not check error string */, |
| 1315 | // javac options |
Stephan Herrmann | ae70795 | 2015-10-30 22:28:02 +0100 | [diff] [blame^] | 1316 | skipJavac ? JavacTestOptions.SKIP : |
| 1317 | javacTestOptions != null ? javacTestOptions : JavacTestOptions.DEFAULT /* default javac test options */); |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 1318 | } |
Stephan Herrmann | 396f334 | 2013-03-14 14:31:57 +0100 | [diff] [blame] | 1319 | protected void runConformTest(String[] testFiles, Map customOptions) { |
| 1320 | runTest( |
| 1321 | // test directory preparation |
| 1322 | true /* flush output directory */, |
| 1323 | testFiles /* test files */, |
| 1324 | // compiler options |
| 1325 | null /* no class libraries */, |
| 1326 | customOptions /* no custom options */, |
| 1327 | false /* do not perform statements recovery */, |
| 1328 | null /* no custom requestor */, |
| 1329 | // compiler results |
| 1330 | false /* expecting no compiler errors */, |
| 1331 | null /* do not check compiler log */, |
| 1332 | // runtime options |
| 1333 | false /* do not force execution */, |
| 1334 | null /* no vm arguments */, |
| 1335 | // runtime results |
| 1336 | null /* expected output string */, |
| 1337 | null /* do not check error string */, |
| 1338 | // javac options |
| 1339 | JavacTestOptions.DEFAULT /* default javac test options */); |
| 1340 | } |
Stephan Herrmann | 31907e2 | 2014-01-03 15:27:45 +0100 | [diff] [blame] | 1341 | protected void runConformTest(String[] testFiles, String expectedOutput, Map customOptions) { |
| 1342 | runTest( |
| 1343 | // test directory preparation |
| 1344 | true /* flush output directory */, |
| 1345 | testFiles /* test files */, |
| 1346 | // compiler options |
| 1347 | null /* no class libraries */, |
| 1348 | customOptions /* no custom options */, |
| 1349 | false /* do not perform statements recovery */, |
| 1350 | null /* no custom requestor */, |
| 1351 | // compiler results |
| 1352 | false /* expecting no compiler errors */, |
| 1353 | null /* do not check compiler log */, |
| 1354 | // runtime options |
| 1355 | false /* do not force execution */, |
| 1356 | null /* no vm arguments */, |
| 1357 | // runtime results |
| 1358 | expectedOutput /* expected output string */, |
| 1359 | null /* do not check error string */, |
| 1360 | // javac options |
| 1361 | JavacTestOptions.DEFAULT /* default javac test options */); |
| 1362 | } |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 1363 | protected void runConformTest( |
Stephan Herrmann | de4efa9 | 2010-09-26 16:11:28 +0000 | [diff] [blame] | 1364 | String[] testFiles, |
| 1365 | String[] dependantFiles, |
| 1366 | String expectedSuccessOutputString) { |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 1367 | runTest( |
Stephan Herrmann | de4efa9 | 2010-09-26 16:11:28 +0000 | [diff] [blame] | 1368 | true, |
| 1369 | testFiles, |
| 1370 | dependantFiles, |
| 1371 | null, |
| 1372 | null, |
| 1373 | false, |
| 1374 | null, |
| 1375 | false, |
| 1376 | null, |
Stephan Herrmann | 4d07945 | 2014-03-27 18:01:49 +0100 | [diff] [blame] | 1377 | null, |
Stephan Herrmann | de4efa9 | 2010-09-26 16:11:28 +0000 | [diff] [blame] | 1378 | false, |
| 1379 | null, |
| 1380 | expectedSuccessOutputString, |
| 1381 | null, |
| 1382 | null, |
| 1383 | JavacTestOptions.DEFAULT); |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | protected void runConformTest( |
| 1387 | String[] testFiles, |
| 1388 | String expectedOutputString, |
| 1389 | String[] classLibraries, |
| 1390 | boolean shouldFlushOutputDirectory, |
| 1391 | String[] vmArguments) { |
| 1392 | runTest( |
| 1393 | // test directory preparation |
| 1394 | shouldFlushOutputDirectory /* should flush output directory */, |
| 1395 | testFiles /* test files */, |
| 1396 | // compiler options |
| 1397 | classLibraries /* class libraries */, |
| 1398 | null /* no custom options */, |
| 1399 | false /* do not perform statements recovery */, |
| 1400 | null /* no custom requestor */, |
| 1401 | // compiler results |
| 1402 | false /* expecting no compiler errors */, |
| 1403 | null /* do not check compiler log */, |
| 1404 | // runtime options |
| 1405 | false /* do not force execution */, |
| 1406 | vmArguments /* vm arguments */, |
| 1407 | // runtime results |
| 1408 | expectedOutputString /* expected output string */, |
| 1409 | null /* do not check error string */, |
| 1410 | // javac options |
| 1411 | JavacTestOptions.DEFAULT /* default javac test options */); |
| 1412 | } |
| 1413 | |
| 1414 | protected void runConformTest( |
| 1415 | String[] testFiles, |
| 1416 | String expectedOutputString, |
| 1417 | String[] classLibraries, |
| 1418 | boolean shouldFlushOutputDirectory, |
| 1419 | String[] vmArguments, |
| 1420 | Map customOptions, |
| 1421 | ICompilerRequestor customRequestor) { |
| 1422 | runTest( |
| 1423 | // test directory preparation |
| 1424 | shouldFlushOutputDirectory /* should flush output directory */, |
| 1425 | testFiles /* test files */, |
| 1426 | // compiler options |
| 1427 | classLibraries /* class libraries */, |
| 1428 | customOptions /* custom options */, |
| 1429 | false /* do not perform statements recovery */, |
| 1430 | customRequestor /* custom requestor */, |
| 1431 | // compiler results |
| 1432 | false /* expecting no compiler errors */, |
| 1433 | null /* do not check compiler log */, |
| 1434 | // runtime options |
| 1435 | false /* do not force execution */, |
| 1436 | vmArguments /* vm arguments */, |
| 1437 | // runtime results |
| 1438 | expectedOutputString /* expected output string */, |
| 1439 | null /* do not check error string */, |
| 1440 | // javac options |
| 1441 | JavacTestOptions.DEFAULT /* default javac test options */); |
| 1442 | } |
| 1443 | |
| 1444 | // WORK good candidate for elimination (8 instances) |
| 1445 | protected void runConformTest( |
| 1446 | String[] testFiles, |
| 1447 | String expectedSuccessOutputString, |
| 1448 | String[] classLib, |
| 1449 | boolean shouldFlushOutputDirectory, |
| 1450 | String[] vmArguments, |
| 1451 | Map customOptions, |
| 1452 | ICompilerRequestor clientRequestor, |
| 1453 | boolean skipJavac) { |
| 1454 | runTest( |
| 1455 | shouldFlushOutputDirectory, |
| 1456 | testFiles, |
| 1457 | classLib, |
| 1458 | customOptions, |
| 1459 | false /* do not perform statements recovery */, |
| 1460 | clientRequestor, |
| 1461 | false, |
| 1462 | null, |
| 1463 | false, |
| 1464 | vmArguments, |
| 1465 | expectedSuccessOutputString, |
| 1466 | null, |
| 1467 | (skipJavac ? |
| 1468 | JavacTestOptions.SKIP : |
| 1469 | JavacTestOptions.DEFAULT)); |
| 1470 | } |
| 1471 | |
| 1472 | /* |
| 1473 | * Run Sun compilation using javac. |
| 1474 | * Launch compilation in a thread and verify that it does not take more than 5s |
| 1475 | * to perform it. Otherwise abort the process and log in console. |
| 1476 | * TODO (maxime) not sure we really do that 5s cap any more. |
| 1477 | * A semi verbose output is sent to the console that analyzes differences |
| 1478 | * of behaviors between javac and Eclipse on a per test basis. A more |
| 1479 | * verbose output is produced into a file which name is printed on the |
| 1480 | * console. Such files can be compared between various javac releases |
| 1481 | * to check potential changes. |
| 1482 | * To enable such tests, specify the following VM properies in the launch |
| 1483 | * configuration: |
| 1484 | * -Drun.javac=enabled |
| 1485 | * mandatory - tells the test suite to run javac tests |
| 1486 | * -Djdk.root=<the root directory of the tested javac> |
| 1487 | * optional - enables to find the javac that will be run by the tests |
| 1488 | * suite; the root directory must be specified as an absolute path and |
| 1489 | * should point to the JDK root, aka /opt/jdk1.5.0_05 for Linux or |
| 1490 | * c:/JDK_50 for Windows; in case this property is not specified, the |
| 1491 | * tests suite will use the runtime JRE of the launching configuration. |
| 1492 | * Note that enabling javac tests implies running into 1.5 compliance level |
| 1493 | * (or higher). |
| 1494 | */ |
| 1495 | protected void runJavac( |
| 1496 | String[] testFiles, |
| 1497 | final String expectedProblemLog, |
| 1498 | final String expectedSuccessOutputString, |
| 1499 | boolean shouldFlushOutputDirectory) { |
| 1500 | String testName = null; |
| 1501 | Process compileProcess = null; |
| 1502 | Process execProcess = null; |
| 1503 | try { |
| 1504 | // Init test name |
| 1505 | testName = testName(); |
| 1506 | |
| 1507 | // Cleanup javac output dir if needed |
| 1508 | File javacOutputDirectory = new File(JAVAC_OUTPUT_DIR_NAME); |
| 1509 | if (shouldFlushOutputDirectory) { |
| 1510 | Util.delete(javacOutputDirectory); |
| 1511 | } |
| 1512 | |
| 1513 | // Write files in dir |
| 1514 | writeFiles(testFiles); |
| 1515 | |
| 1516 | // Prepare command line |
| 1517 | StringBuffer cmdLine = new StringBuffer(javacCommandLineHeader); |
| 1518 | // compute extra classpath |
| 1519 | String[] classpath = Util.concatWithClassLibs(JAVAC_OUTPUT_DIR_NAME, false); |
| 1520 | StringBuffer cp = new StringBuffer(" -classpath "); |
| 1521 | int length = classpath.length; |
| 1522 | for (int i = 0; i < length; i++) { |
| 1523 | if (i > 0) |
| 1524 | cp.append(File.pathSeparatorChar); |
| 1525 | if (classpath[i].indexOf(" ") != -1) { |
| 1526 | cp.append("\"" + classpath[i] + "\""); |
| 1527 | } else { |
| 1528 | cp.append(classpath[i]); |
| 1529 | } |
| 1530 | } |
| 1531 | cmdLine.append(cp); |
| 1532 | // add source files |
| 1533 | for (int i = 0; i < testFiles.length; i += 2) { |
| 1534 | // *.java is not enough (p1/X.java, p2/Y.java) |
| 1535 | cmdLine.append(' '); |
| 1536 | cmdLine.append(testFiles[i]); |
| 1537 | } |
| 1538 | |
| 1539 | // Launch process |
| 1540 | compileProcess = Runtime.getRuntime().exec( |
| 1541 | cmdLine.toString(), null, this.outputTestDirectory); |
| 1542 | |
| 1543 | // Log errors |
| 1544 | Logger errorLogger = new Logger(compileProcess.getErrorStream(), "ERROR"); |
| 1545 | |
| 1546 | // Log output |
| 1547 | Logger outputLogger = new Logger(compileProcess.getInputStream(), "OUTPUT"); |
| 1548 | |
| 1549 | // start the threads to run outputs (standard/error) |
| 1550 | errorLogger.start(); |
| 1551 | outputLogger.start(); |
| 1552 | |
| 1553 | // Wait for end of process |
| 1554 | int exitValue = compileProcess.waitFor(); |
| 1555 | errorLogger.join(); // make sure we get the whole output |
| 1556 | outputLogger.join(); |
| 1557 | |
| 1558 | // Report raw javac results |
| 1559 | if (! testName.equals(javacTestName)) { |
| 1560 | javacTestName = testName; |
| 1561 | javacTestErrorFlag = false; |
| 1562 | javacFullLog.println("-----------------------------------------------------------------"); |
| 1563 | javacFullLog.println(CURRENT_CLASS_NAME + " " + testName); |
| 1564 | } |
| 1565 | if (exitValue != 0) { |
| 1566 | javacTestErrorFlag = true; |
| 1567 | } |
| 1568 | if (errorLogger.buffer.length() > 0) { |
| 1569 | javacFullLog.println("--- javac err: ---"); |
| 1570 | javacFullLog.println(errorLogger.buffer.toString()); |
| 1571 | } |
| 1572 | if (outputLogger.buffer.length() > 0) { |
| 1573 | javacFullLog.println("--- javac out: ---"); |
| 1574 | javacFullLog.println(outputLogger.buffer.toString()); |
| 1575 | } |
| 1576 | |
| 1577 | // Compare compilation results |
| 1578 | if (expectedProblemLog == null || expectedProblemLog.length() == 0) { |
| 1579 | // Eclipse found no error and no warning |
| 1580 | if (exitValue != 0) { |
| 1581 | // Javac found errors |
| 1582 | System.out.println("----------------------------------------"); |
| 1583 | System.out.println(testName + " - Javac has found error(s) but Eclipse expects conform result:\n"); |
| 1584 | javacFullLog.println("JAVAC_MISMATCH: Javac has found error(s) but Eclipse expects conform result"); |
| 1585 | System.out.println(errorLogger.buffer.toString()); |
| 1586 | printFiles(testFiles); |
| 1587 | DIFF_COUNTERS[0]++; |
| 1588 | } |
| 1589 | else { |
| 1590 | // Javac found no error - may have found warnings |
| 1591 | if (errorLogger.buffer.length() > 0) { |
| 1592 | System.out.println("----------------------------------------"); |
| 1593 | System.out.println(testName + " - Javac has found warning(s) but Eclipse expects conform result:\n"); |
| 1594 | javacFullLog.println("JAVAC_MISMATCH: Javac has found warning(s) but Eclipse expects conform result"); |
| 1595 | System.out.println(errorLogger.buffer.toString()); |
| 1596 | printFiles(testFiles); |
| 1597 | DIFF_COUNTERS[0]++; |
| 1598 | } |
| 1599 | if (expectedSuccessOutputString != null && !javacTestErrorFlag) { |
| 1600 | // Neither Eclipse nor Javac found errors, and we have a runtime |
| 1601 | // bench value |
| 1602 | StringBuffer javaCmdLine = new StringBuffer(javaCommandLineHeader); |
| 1603 | javaCmdLine.append(cp); |
| 1604 | javaCmdLine.append(' ').append(testFiles[0].substring(0, testFiles[0].indexOf('.'))); |
| 1605 | // assume executable class is name of first test file - PREMATURE check if this is also the case in other test fwk classes |
| 1606 | execProcess = Runtime.getRuntime().exec(javaCmdLine.toString(), null, this.outputTestDirectory); |
| 1607 | Logger logger = new Logger(execProcess.getInputStream(), ""); |
| 1608 | // PREMATURE implement consistent error policy |
| 1609 | logger.start(); |
| 1610 | exitValue = execProcess.waitFor(); |
| 1611 | logger.join(); // make sure we get the whole output |
| 1612 | String javaOutput = logger.buffer.toString().trim(); |
| 1613 | if (!expectedSuccessOutputString.equals(javaOutput)) { |
| 1614 | System.out.println("----------------------------------------"); |
| 1615 | System.out.println(testName + " - Javac and Eclipse runtime output is not the same:"); |
| 1616 | javacFullLog.println("JAVAC_MISMATCH: Javac and Eclipse runtime output is not the same"); |
| 1617 | dualPrintln("eclipse:"); |
| 1618 | dualPrintln(expectedSuccessOutputString); |
| 1619 | dualPrintln("javac:"); |
| 1620 | dualPrintln(javaOutput); |
| 1621 | System.out.println("\n"); |
| 1622 | printFiles(testFiles); // PREMATURE consider printing files to the log as well |
| 1623 | DIFF_COUNTERS[2]++; |
| 1624 | } |
| 1625 | } |
| 1626 | } |
| 1627 | } |
| 1628 | else { |
| 1629 | // Eclipse found errors or warnings |
| 1630 | if (errorLogger.buffer.length() == 0) { |
| 1631 | System.out.println("----------------------------------------"); |
| 1632 | System.out.println(testName + " - Eclipse has found error(s)/warning(s) but Javac did not find any:"); |
| 1633 | javacFullLog.println("JAVAC_MISMATCH: Eclipse has found error(s)/warning(s) but Javac did not find any"); |
| 1634 | dualPrintln("eclipse:"); |
| 1635 | dualPrintln(expectedProblemLog); |
| 1636 | printFiles(testFiles); |
| 1637 | DIFF_COUNTERS[1]++; |
| 1638 | } else if (expectedProblemLog.indexOf("ERROR") > 0 && exitValue == 0){ |
| 1639 | System.out.println("----------------------------------------"); |
| 1640 | System.out.println(testName + " - Eclipse has found error(s) but Javac only found warning(s):"); |
| 1641 | javacFullLog.println("JAVAC_MISMATCH: Eclipse has found error(s) but Javac only found warning(s)"); |
| 1642 | dualPrintln("eclipse:"); |
| 1643 | dualPrintln(expectedProblemLog); |
| 1644 | System.out.println("javac:"); |
| 1645 | System.out.println(errorLogger.buffer.toString()); |
| 1646 | printFiles(testFiles); |
| 1647 | DIFF_COUNTERS[1]++; |
| 1648 | } else { |
| 1649 | // PREMATURE refine comparison |
| 1650 | // TODO (frederic) compare warnings in each result and verify they are similar... |
| 1651 | // System.out.println(testName+": javac has found warnings :"); |
| 1652 | // System.out.print(errorLogger.buffer.toString()); |
| 1653 | // System.out.println(testName+": we're expecting warning results:"); |
| 1654 | // System.out.println(expectedProblemLog); |
| 1655 | } |
| 1656 | } |
| 1657 | } |
| 1658 | catch (InterruptedException e1) { |
| 1659 | if (compileProcess != null) compileProcess.destroy(); |
| 1660 | if (execProcess != null) execProcess.destroy(); |
| 1661 | System.out.println(testName+": Sun javac compilation was aborted!"); |
| 1662 | javacFullLog.println("JAVAC_WARNING: Sun javac compilation was aborted!"); |
| 1663 | e1.printStackTrace(javacFullLog); |
| 1664 | } |
| 1665 | catch (Throwable e) { |
| 1666 | System.out.println(testName+": could not launch Sun javac compilation!"); |
| 1667 | e.printStackTrace(); |
| 1668 | javacFullLog.println("JAVAC_ERROR: could not launch Sun javac compilation!"); |
| 1669 | e.printStackTrace(javacFullLog); |
| 1670 | // PREMATURE failing the javac pass or comparison could also fail |
| 1671 | // the test itself |
| 1672 | } |
| 1673 | finally { |
| 1674 | // Clean up written file(s) |
| 1675 | Util.delete(this.outputTestDirectory); |
| 1676 | } |
| 1677 | } |
| 1678 | // WORK factorize all runJavac implementations, including overrides |
| 1679 | protected boolean runJavac(String options, String[] testFileNames, String currentDirectoryPath) { |
| 1680 | Process compileProcess = null; |
| 1681 | try { |
| 1682 | // Prepare command line |
| 1683 | StringBuffer cmdLine = new StringBuffer(javacCommandLineHeader); |
| 1684 | cmdLine.append(' '); |
| 1685 | cmdLine.append(options); |
| 1686 | // add source files |
| 1687 | for (int i = 0; i < testFileNames.length; i ++) { |
| 1688 | // *.java is not enough (p1/X.java, p2/Y.java) |
| 1689 | cmdLine.append(' '); |
| 1690 | cmdLine.append(testFileNames[i]); |
| 1691 | } |
| 1692 | // Launch process |
| 1693 | File currentDirectory = new File(currentDirectoryPath); |
| 1694 | compileProcess = Runtime.getRuntime().exec( |
| 1695 | cmdLine.toString(), null, currentDirectory); |
| 1696 | |
| 1697 | // Log errors |
| 1698 | Logger errorLogger = new Logger(compileProcess.getErrorStream(), "ERROR"); |
| 1699 | errorLogger.start(); |
| 1700 | |
| 1701 | // Wait for end of process |
| 1702 | int exitValue = compileProcess.waitFor(); |
| 1703 | errorLogger.join(); // make sure we get the whole output |
| 1704 | |
| 1705 | // Check results |
| 1706 | if (exitValue != 0) { |
| 1707 | return false; |
| 1708 | } |
| 1709 | if (errorLogger.buffer.length() > 0) { |
| 1710 | System.err.println("--- javac err: ---"); |
| 1711 | System.err.println(errorLogger.buffer.toString()); |
| 1712 | return false; |
| 1713 | } |
| 1714 | } |
| 1715 | catch (Throwable e) { |
| 1716 | e.printStackTrace(System.err); |
| 1717 | } |
| 1718 | finally { |
| 1719 | if (compileProcess != null) { |
| 1720 | compileProcess.destroy(); // closes process streams |
| 1721 | } |
| 1722 | } |
| 1723 | return true; |
| 1724 | } |
| 1725 | /* |
| 1726 | * Run Sun compilation using one or more versions of javac. Compare the |
| 1727 | * results to expected ones, raising mismatches as needed. |
| 1728 | * To enable such tests, specify the following VM properies in the launch |
| 1729 | * configuration: |
| 1730 | * -Drun.javac=enabled |
| 1731 | * mandatory - tells the test suite to run javac tests |
| 1732 | * -Djdk.roots=<the root directories of the tested javac(s)> |
| 1733 | * optional - enables to find the versions of javac that will be run by |
| 1734 | * the tests suite; the root directories must be specified as a |
| 1735 | * File.pathSeparator separated list of absolute paths which should |
| 1736 | * point each to a JDK root, aka /opt/jdk1.5.0_05 for Linux or |
| 1737 | * c:/JDK_50 for Windows; in case this property is not specified, the |
| 1738 | * tests suite will use the runtime JRE of the launching configuration. |
| 1739 | * Note that enabling javac tests implies running into 1.5 compliance level |
| 1740 | * (or higher). |
| 1741 | */ |
| 1742 | // WORK unify use of output, error, log, etc... |
| 1743 | protected void runJavac( |
| 1744 | String[] testFiles, |
| 1745 | boolean expectingCompilerErrors, |
| 1746 | String expectedCompilerLog, |
| 1747 | String expectedOutputString, |
| 1748 | String expectedErrorString, |
| 1749 | boolean shouldFlushOutputDirectory, |
| 1750 | JavacTestOptions options, |
| 1751 | String[] vmArguments) { |
| 1752 | // WORK we're probably doing too much around class libraries in general - java should be able to fetch its own runtime libs |
| 1753 | // WORK reorder parameters |
| 1754 | if (options == JavacTestOptions.SKIP) { |
| 1755 | return; |
| 1756 | } |
Stephan Herrmann | 4d07945 | 2014-03-27 18:01:49 +0100 | [diff] [blame] | 1757 | if (options == null) { |
| 1758 | options = JavacTestOptions.DEFAULT; |
| 1759 | } |
| 1760 | String newOptions = options.getCompilerOptions(); |
| 1761 | if (newOptions.indexOf(" -d ") < 0) { |
| 1762 | options.setCompilerOptions(newOptions.concat(" -d .")); |
| 1763 | } |
Stephan Herrmann | ae70795 | 2015-10-30 22:28:02 +0100 | [diff] [blame^] | 1764 | if (newOptions.indexOf(" -Xlint") < 0) { |
| 1765 | options.setCompilerOptions(newOptions.concat(" -Xlint")); |
| 1766 | } |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 1767 | String testName = testName(); |
| 1768 | Iterator compilers = javacCompilers.iterator(); |
| 1769 | while (compilers.hasNext()) { |
| 1770 | JavacCompiler compiler = (JavacCompiler) compilers.next(); |
| 1771 | if (!options.skip(compiler) && compiler.compliance == this.complianceLevel) { |
| 1772 | // WORK this may exclude some compilers under some conditions (when |
| 1773 | // complianceLevel is not set); consider accepting the compiler |
| 1774 | // in such case and see what happens |
| 1775 | JavacTestOptions.Excuse excuse = options.excuseFor(compiler); |
| 1776 | StringBuffer compilerLog = new StringBuffer(); |
| 1777 | File javacOutputDirectory = null; |
| 1778 | int mismatch = 0; |
| 1779 | String sourceFileNames[] = null; |
| 1780 | try { |
| 1781 | // cleanup javac output dir if needed |
| 1782 | javacOutputDirectory = new File(JAVAC_OUTPUT_DIR_NAME + |
| 1783 | File.separator + compiler.rawVersion); // need to change output directory per javac version |
| 1784 | if (shouldFlushOutputDirectory) { |
| 1785 | Util.delete(javacOutputDirectory); |
| 1786 | } |
| 1787 | javacOutputDirectory.mkdirs(); |
| 1788 | // write test files |
| 1789 | for (int i = 0, length = testFiles.length; i < length; ) { |
| 1790 | String fileName = testFiles[i++]; |
| 1791 | String contents = testFiles[i++]; |
| 1792 | File file = new File(javacOutputDirectory, fileName); |
| 1793 | if (fileName.lastIndexOf('/') >= 0) { |
| 1794 | File dir = file.getParentFile(); |
| 1795 | if (!dir.exists()) { |
| 1796 | dir.mkdirs(); |
| 1797 | } |
| 1798 | } |
| 1799 | Util.writeToFile(contents, file.getPath()); |
| 1800 | } |
| 1801 | // compute source file names |
| 1802 | int testFilesLength = testFiles.length; |
| 1803 | sourceFileNames = new String[testFilesLength / 2]; |
| 1804 | for (int i = 0, j = 0; i < testFilesLength; i += 2, j++) { |
| 1805 | sourceFileNames[j] = testFiles[i]; |
| 1806 | } |
| 1807 | // compile |
| 1808 | long compilerResult = compiler.compile(javacOutputDirectory, options.getCompilerOptions() /* options */, sourceFileNames, compilerLog); |
| 1809 | // check cumulative javac results |
| 1810 | // WORK need to use a per compiler approach |
| 1811 | if (! testName.equals(javacTestName)) { |
| 1812 | javacTestName = testName; |
| 1813 | javacTestErrorFlag = false; |
| 1814 | } |
| 1815 | if ((compilerResult & JavacCompiler.EXIT_VALUE_MASK) != 0) { |
| 1816 | javacTestErrorFlag = true; |
| 1817 | } |
| 1818 | // compare compilation results |
| 1819 | if (expectingCompilerErrors) { |
| 1820 | if ((compilerResult & JavacCompiler.EXIT_VALUE_MASK) == 0) { |
| 1821 | if ((compilerResult & JavacCompiler.ERROR_LOG_MASK) == 0) { |
| 1822 | mismatch = JavacTestOptions.MismatchType.EclipseErrorsJavacNone; |
| 1823 | } else { |
| 1824 | mismatch = JavacTestOptions.MismatchType.EclipseErrorsJavacWarnings; |
| 1825 | } |
| 1826 | } |
| 1827 | } else { |
| 1828 | if ((compilerResult & JavacCompiler.EXIT_VALUE_MASK) != 0) { |
| 1829 | if (expectedCompilerLog != null /* null skips warnings test */ && expectedCompilerLog.length() > 0) { |
| 1830 | mismatch = JavacTestOptions.MismatchType.JavacErrorsEclipseWarnings; |
| 1831 | } else { |
| 1832 | mismatch = JavacTestOptions.MismatchType.JavacErrorsEclipseNone; |
| 1833 | } |
| 1834 | } else if (expectedCompilerLog != null /* null skips warnings test */) { |
| 1835 | if (expectedCompilerLog.length() > 0 && (compilerResult & JavacCompiler.ERROR_LOG_MASK) == 0) { |
| 1836 | mismatch = JavacTestOptions.MismatchType.EclipseWarningsJavacNone; |
| 1837 | } else if (expectedCompilerLog.length() == 0 && (compilerResult & JavacCompiler.ERROR_LOG_MASK) != 0) { |
| 1838 | mismatch = JavacTestOptions.MismatchType.JavacWarningsEclipseNone; |
| 1839 | } |
| 1840 | } |
| 1841 | } |
| 1842 | } |
| 1843 | catch (InterruptedException e1) { |
| 1844 | e1.printStackTrace(); |
| 1845 | mismatch = JavacTestOptions.MismatchType.JavacAborted; |
| 1846 | } |
| 1847 | catch (Throwable e) { |
| 1848 | e.printStackTrace(); |
| 1849 | mismatch = JavacTestOptions.MismatchType.JavacNotLaunched; |
| 1850 | } |
| 1851 | String output = null; |
| 1852 | String err = null; |
| 1853 | try { |
| 1854 | if ((expectedOutputString != null || expectedErrorString != null) && |
| 1855 | !javacTestErrorFlag && mismatch == 0 && sourceFileNames != null) { |
| 1856 | JavaRuntime runtime = JavaRuntime.runtimeFor(compiler); |
| 1857 | StringBuffer stderr = new StringBuffer(); |
| 1858 | StringBuffer stdout = new StringBuffer(); |
| 1859 | String vmOptions = ""; |
| 1860 | if (vmArguments != null) { |
| 1861 | int l = vmArguments.length; |
| 1862 | if (l > 0) { |
| 1863 | StringBuffer buffer = new StringBuffer(vmArguments[0]); |
| 1864 | for (int i = 1; i < l; i++) { |
| 1865 | buffer.append(' '); |
| 1866 | buffer.append(vmArguments[i]); |
| 1867 | } |
| 1868 | vmOptions = buffer.toString(); |
| 1869 | } |
| 1870 | } |
| 1871 | runtime.execute(javacOutputDirectory, vmOptions, testFiles[0].substring(0, testFiles[0].length() - 5), stdout, stderr); |
| 1872 | if (expectedOutputString != null /* null skips output test */) { |
| 1873 | output = stdout.toString().trim(); |
| 1874 | if (!expectedOutputString.equals(output)) { |
| 1875 | mismatch = JavacTestOptions.MismatchType.StandardOutputMismatch; |
| 1876 | } |
| 1877 | } |
| 1878 | // WORK move to a logic in which if stdout is empty whereas |
| 1879 | // it should have had contents, stderr is leveraged as |
| 1880 | // potentially holding indications regarding the failure |
| 1881 | if (expectedErrorString != null /* null skips error test */ && mismatch == 0) { |
| 1882 | err = stderr.toString().trim(); |
| 1883 | if (!expectedErrorString.equals(err) && // special case: command-line java does not like missing main methods |
| 1884 | !(expectedErrorString.length() == 0 && |
Stephan Herrmann | c1c4862 | 2014-01-04 23:19:31 +0100 | [diff] [blame] | 1885 | (err.indexOf("java.lang.NoSuchMethodError: main") != -1) |
| 1886 | || err.indexOf("Error: Main method not found in class") != -1)) { |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 1887 | mismatch = JavacTestOptions.MismatchType.ErrorOutputMismatch; |
| 1888 | } |
| 1889 | } |
| 1890 | } |
| 1891 | } |
| 1892 | catch (InterruptedException e1) { |
| 1893 | e1.printStackTrace(); |
| 1894 | mismatch = JavacTestOptions.MismatchType.JavaAborted; |
| 1895 | } |
| 1896 | catch (Throwable e) { |
| 1897 | e.printStackTrace(); |
| 1898 | mismatch = JavacTestOptions.MismatchType.JavaNotLaunched; |
| 1899 | } |
| 1900 | if (mismatch != 0) { |
| 1901 | if (excuse != null && excuse.clears(mismatch)) { |
| 1902 | excuse = null; |
| 1903 | } else { |
| 1904 | System.err.println("----------------------------------------"); |
| 1905 | logTestFiles(true, testFiles); |
| 1906 | switch (mismatch) { |
| 1907 | case JavacTestOptions.MismatchType.EclipseErrorsJavacNone: |
| 1908 | assertEquals(testName + " - Eclipse found error(s) but Javac did not find any", |
| 1909 | "", expectedCompilerLog.toString()); |
| 1910 | break; |
| 1911 | case JavacTestOptions.MismatchType.EclipseErrorsJavacWarnings: |
| 1912 | assertEquals(testName + " - Eclipse found error(s) but Javac only found warning(s)", |
| 1913 | expectedCompilerLog.toString(), compilerLog.toString()); |
| 1914 | break; |
| 1915 | case JavacTestOptions.MismatchType.JavacErrorsEclipseNone: |
| 1916 | assertEquals(testName + " - Javac found error(s) but Eclipse did not find any", |
| 1917 | "", compilerLog.toString()); |
| 1918 | break; |
| 1919 | case JavacTestOptions.MismatchType.JavacErrorsEclipseWarnings: |
| 1920 | assertEquals(testName + " - Javac found error(s) but Eclipse only found warning(s)", |
| 1921 | expectedCompilerLog.toString(), compilerLog.toString()); |
| 1922 | break; |
| 1923 | case JavacTestOptions.MismatchType.EclipseWarningsJavacNone: |
| 1924 | assertEquals(testName + " - Eclipse found warning(s) but Javac did not find any", |
| 1925 | "", expectedCompilerLog.toString()); |
| 1926 | break; |
| 1927 | case JavacTestOptions.MismatchType.JavacWarningsEclipseNone: |
| 1928 | assertEquals(testName + " - Javac found warning(s) but Eclipse did not find any", |
| 1929 | "", compilerLog.toString()); |
| 1930 | break; |
| 1931 | case JavacTestOptions.MismatchType.StandardOutputMismatch: |
| 1932 | assertEquals(testName + " - Eclipse/Javac standard output mismatch", |
| 1933 | expectedOutputString, output); |
| 1934 | break; |
| 1935 | case JavacTestOptions.MismatchType.ErrorOutputMismatch: |
| 1936 | assertEquals(testName + " - Eclipse/Javac standard error mismatch", |
| 1937 | expectedErrorString, err); |
| 1938 | break; |
| 1939 | case JavacTestOptions.MismatchType.JavacAborted: |
| 1940 | case JavacTestOptions.MismatchType.JavacNotLaunched: |
| 1941 | fail(testName + " - Javac failure"); |
| 1942 | break; |
| 1943 | case JavacTestOptions.MismatchType.JavaAborted: |
| 1944 | case JavacTestOptions.MismatchType.JavaNotLaunched: |
| 1945 | fail(testName + " - Java failure"); |
| 1946 | break; |
| 1947 | default: |
| 1948 | throw new RuntimeException("unexpected mismatch value: " + mismatch); |
| 1949 | } |
| 1950 | } |
| 1951 | } |
| 1952 | if (excuse != null) { |
| 1953 | fail(testName + ": unused excuse " + excuse + " for compiler " + compiler); |
| 1954 | } |
| 1955 | } |
| 1956 | } |
| 1957 | } |
| 1958 | |
| 1959 | //runNegativeTest( |
| 1960 | // // test directory preparation |
| 1961 | // new String[] { /* test files */ |
| 1962 | // }, |
| 1963 | // // compiler results |
| 1964 | // "" /* expected compiler log */); |
| 1965 | protected void runNegativeTest(String[] testFiles, String expectedCompilerLog) { |
Stephan Herrmann | ae70795 | 2015-10-30 22:28:02 +0100 | [diff] [blame^] | 1966 | runNegativeTest(false/*skipJavac*/, null, testFiles, expectedCompilerLog); |
| 1967 | } |
| 1968 | //runNegativeTest( |
| 1969 | // skipJavac |
| 1970 | // javacTestOptions |
| 1971 | //// test directory preparation |
| 1972 | //new String[] { /* test files */ |
| 1973 | // }, |
| 1974 | //// compiler results |
| 1975 | //"" /* expected compiler log */); |
| 1976 | protected void runNegativeTest(boolean skipJavac, JavacTestOptions javacTestOptions, String[] testFiles, String expectedCompilerLog) { |
| 1977 | runTest( |
| 1978 | // test directory preparation |
| 1979 | true /* flush output directory */, |
| 1980 | testFiles /* test files */, |
| 1981 | // compiler options |
| 1982 | null /* no class libraries */, |
| 1983 | null /* no custom options */, |
| 1984 | false /* do not perform statements recovery */, |
| 1985 | new Requestor( /* custom requestor */ |
| 1986 | false, |
| 1987 | null /* no custom requestor */, |
| 1988 | false, |
| 1989 | false), |
| 1990 | // compiler results |
| 1991 | expectedCompilerLog == null || /* expecting compiler errors */ |
| 1992 | expectedCompilerLog.indexOf("ERROR") != -1, |
| 1993 | expectedCompilerLog /* expected compiler log */, |
| 1994 | // runtime options |
| 1995 | false /* do not force execution */, |
| 1996 | null /* no vm arguments */, |
| 1997 | // runtime results |
| 1998 | null /* do not check output string */, |
| 1999 | null /* do not check error string */, |
| 2000 | // javac options |
| 2001 | skipJavac ? JavacTestOptions.SKIP : |
| 2002 | javacTestOptions != null ? javacTestOptions : |
| 2003 | JavacTestOptions.DEFAULT /* default javac test options */); |
| 2004 | } |
Stephan Herrmann | 5fa7f31 | 2012-07-13 01:52:51 +0200 | [diff] [blame] | 2005 | protected void runNegativeTest(String[] testFiles, String expectedCompilerLog, boolean performStatementRecovery) { |
Stephan Herrmann | ae70795 | 2015-10-30 22:28:02 +0100 | [diff] [blame^] | 2006 | runNegativeTest(false/*skipJavac*/, null, testFiles, expectedCompilerLog, performStatementRecovery); |
| 2007 | } |
| 2008 | protected void runNegativeTest(boolean skipJavac, JavacTestOptions javacTestOptions, String[] testFiles, String expectedCompilerLog, boolean performStatementRecovery) { |
Stephan Herrmann | 5fa7f31 | 2012-07-13 01:52:51 +0200 | [diff] [blame] | 2009 | runTest( |
| 2010 | // test directory preparation |
| 2011 | true /* flush output directory */, |
| 2012 | testFiles /* test files */, |
| 2013 | // compiler options |
| 2014 | null /* no class libraries */, |
| 2015 | null /* no custom options */, |
| 2016 | performStatementRecovery, |
| 2017 | new Requestor( /* custom requestor */ |
| 2018 | false, |
| 2019 | null /* no custom requestor */, |
| 2020 | false, |
| 2021 | false), |
| 2022 | // compiler results |
| 2023 | expectedCompilerLog == null || /* expecting compiler errors */ |
| 2024 | expectedCompilerLog.indexOf("ERROR") != -1, |
| 2025 | expectedCompilerLog /* expected compiler log */, |
| 2026 | // runtime options |
| 2027 | false /* do not force execution */, |
| 2028 | null /* no vm arguments */, |
| 2029 | // runtime results |
| 2030 | null /* do not check output string */, |
| 2031 | null /* do not check error string */, |
| 2032 | // javac options |
Stephan Herrmann | ae70795 | 2015-10-30 22:28:02 +0100 | [diff] [blame^] | 2033 | skipJavac ? JavacTestOptions.SKIP : |
| 2034 | javacTestOptions != null ? javacTestOptions : |
Stephan Herrmann | 5fa7f31 | 2012-07-13 01:52:51 +0200 | [diff] [blame] | 2035 | JavacTestOptions.DEFAULT /* default javac test options */); |
| 2036 | } |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 2037 | // WORK potential elimination candidate (24 calls) - else clean up inline |
| 2038 | protected void runNegativeTest( |
| 2039 | String[] testFiles, |
| 2040 | String expectedProblemLog, |
| 2041 | String[] classLib, |
| 2042 | boolean shouldFlushOutputDirectory) { |
Stephan Herrmann | ae70795 | 2015-10-30 22:28:02 +0100 | [diff] [blame^] | 2043 | runNegativeTest(false, null, testFiles, expectedProblemLog, classLib, shouldFlushOutputDirectory); |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 2044 | } |
| 2045 | protected void runNegativeTest( |
Stephan Herrmann | ae70795 | 2015-10-30 22:28:02 +0100 | [diff] [blame^] | 2046 | boolean skipJavac, |
| 2047 | JavacTestOptions javacTestOptions, |
| 2048 | String[] testFiles, |
| 2049 | String expectedProblemLog, |
| 2050 | String[] classLib, |
| 2051 | boolean shouldFlushOutputDirectory) { |
| 2052 | runTest( |
| 2053 | shouldFlushOutputDirectory, |
| 2054 | testFiles, |
| 2055 | classLib, |
| 2056 | null, |
| 2057 | false, |
| 2058 | new Requestor( /* custom requestor */ |
| 2059 | false, |
| 2060 | null /* no custom requestor */, |
| 2061 | false, |
| 2062 | false), |
| 2063 | // compiler results |
| 2064 | expectedProblemLog == null || /* expecting compiler errors */ |
| 2065 | expectedProblemLog.indexOf("ERROR") != -1, |
| 2066 | expectedProblemLog, |
| 2067 | // runtime options |
| 2068 | false /* do not force execution */, |
| 2069 | null /* no vm arguments */, |
| 2070 | // runtime results |
| 2071 | null /* do not check output string */, |
| 2072 | null /* do not check error string */, |
| 2073 | // javac options |
| 2074 | skipJavac ? JavacTestOptions.SKIP : |
| 2075 | javacTestOptions != null ? javacTestOptions : |
| 2076 | JavacTestOptions.DEFAULT /* javac test options */); |
| 2077 | } |
| 2078 | protected void runNegativeTest( |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 2079 | String[] testFiles, |
| 2080 | String expectedCompilerLog, |
| 2081 | String[] classLibraries, |
| 2082 | boolean shouldFlushOutputDirectory, |
| 2083 | Map customOptions) { |
| 2084 | runTest( |
| 2085 | // test directory preparation |
| 2086 | shouldFlushOutputDirectory /* should flush output directory */, |
| 2087 | testFiles /* test files */, |
| 2088 | // compiler options |
| 2089 | classLibraries /* class libraries */, |
| 2090 | customOptions /* custom options */, |
| 2091 | false /* do not perform statements recovery */, |
| 2092 | new Requestor( /* custom requestor */ |
| 2093 | false, |
| 2094 | null /* no custom requestor */, |
| 2095 | false, |
| 2096 | false), |
| 2097 | // compiler results |
| 2098 | expectedCompilerLog == null || /* expecting compiler errors */ |
| 2099 | expectedCompilerLog.indexOf("ERROR") != -1, |
| 2100 | expectedCompilerLog /* expected compiler log */, |
| 2101 | // runtime options |
| 2102 | false /* do not force execution */, |
| 2103 | null /* no vm arguments */, |
| 2104 | // runtime results |
| 2105 | null /* do not check output string */, |
| 2106 | null /* do not check error string */, |
| 2107 | // javac options |
| 2108 | JavacTestOptions.DEFAULT /* default javac test options */); |
| 2109 | } |
| 2110 | protected void runNegativeTest( |
Stephan Herrmann | ae70795 | 2015-10-30 22:28:02 +0100 | [diff] [blame^] | 2111 | boolean skipJavac, |
| 2112 | JavacTestOptions javacTestOptions, |
| 2113 | String[] testFiles, |
| 2114 | String expectedCompilerLog, |
| 2115 | String[] classLibraries, |
| 2116 | boolean shouldFlushOutputDirectory, |
| 2117 | Map customOptions) { |
| 2118 | runTest( |
| 2119 | // test directory preparation |
| 2120 | shouldFlushOutputDirectory /* should flush output directory */, |
| 2121 | testFiles /* test files */, |
| 2122 | // compiler options |
| 2123 | classLibraries /* class libraries */, |
| 2124 | customOptions /* custom options */, |
| 2125 | false /* do not perform statements recovery */, |
| 2126 | new Requestor( /* custom requestor */ |
| 2127 | false, |
| 2128 | null /* no custom requestor */, |
| 2129 | false, |
| 2130 | false), |
| 2131 | // compiler results |
| 2132 | expectedCompilerLog == null || /* expecting compiler errors */ |
| 2133 | expectedCompilerLog.indexOf("ERROR") != -1, |
| 2134 | expectedCompilerLog /* expected compiler log */, |
| 2135 | // runtime options |
| 2136 | false /* do not force execution */, |
| 2137 | null /* no vm arguments */, |
| 2138 | // runtime results |
| 2139 | null /* do not check output string */, |
| 2140 | null /* do not check error string */, |
| 2141 | // javac options |
| 2142 | skipJavac ? JavacTestOptions.SKIP : |
| 2143 | javacTestOptions != null ? javacTestOptions : |
| 2144 | JavacTestOptions.DEFAULT /* default javac test options */); |
| 2145 | } |
| 2146 | protected void runNegativeTest( |
Stephan Herrmann | 13a070b | 2010-04-02 03:54:26 +0000 | [diff] [blame] | 2147 | String[] testFiles, |
| 2148 | String expectedCompilerLog, |
| 2149 | String[] classLibraries, |
| 2150 | boolean shouldFlushOutputDirectory, |
| 2151 | Map customOptions, |
| 2152 | String expectedErrorString) { |
| 2153 | runTest( |
| 2154 | // test directory preparation |
| 2155 | shouldFlushOutputDirectory /* should flush output directory */, |
| 2156 | testFiles /* test files */, |
| 2157 | // compiler options |
| 2158 | classLibraries /* class libraries */, |
| 2159 | customOptions /* custom options */, |
| 2160 | false /* do not perform statements recovery */, |
| 2161 | new Requestor( /* custom requestor */ |
| 2162 | false, |
| 2163 | null /* no custom requestor */, |
| 2164 | false, |
| 2165 | false), |
| 2166 | // compiler results |
| 2167 | expectedCompilerLog == null || /* expecting compiler errors */ |
| 2168 | expectedCompilerLog.indexOf("ERROR") != -1, |
| 2169 | expectedCompilerLog /* expected compiler log */, |
| 2170 | // runtime options |
| 2171 | false /* do not force execution */, |
| 2172 | null /* no vm arguments */, |
| 2173 | // runtime results |
| 2174 | null /* do not check output string */, |
| 2175 | expectedErrorString /* do not check error string */, |
| 2176 | // javac options |
| 2177 | JavacTestOptions.DEFAULT /* default javac test options */); |
| 2178 | } |
| 2179 | protected void runNegativeTest( |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 2180 | String[] testFiles, |
| 2181 | String expectedProblemLog, |
| 2182 | String[] classLibraries, |
| 2183 | boolean shouldFlushOutputDirectory, |
| 2184 | Map customOptions, |
| 2185 | boolean generateOutput, |
| 2186 | boolean showCategory, |
| 2187 | boolean showWarningToken) { |
| 2188 | runTest( |
| 2189 | // test directory preparation |
| 2190 | shouldFlushOutputDirectory /* should flush output directory */, |
| 2191 | testFiles /* test files */, |
| 2192 | // compiler options |
| 2193 | classLibraries /* class libraries */, |
| 2194 | customOptions /* custom options */, |
| 2195 | false, |
| 2196 | new Requestor( /* custom requestor */ |
| 2197 | generateOutput, |
| 2198 | null /* no custom requestor */, |
| 2199 | showCategory, |
| 2200 | showWarningToken), |
| 2201 | // compiler results |
| 2202 | expectedProblemLog == null || /* expecting compiler errors */ |
| 2203 | expectedProblemLog.indexOf("ERROR") != -1, |
| 2204 | expectedProblemLog, |
| 2205 | // runtime options |
| 2206 | false /* do not force execution */, |
| 2207 | null /* no vm arguments */, |
| 2208 | // runtime results |
| 2209 | null /* do not check output string */, |
| 2210 | null /* do not check error string */, |
| 2211 | // javac options |
| 2212 | JavacTestOptions.DEFAULT /* javac test options */); |
| 2213 | } |
| 2214 | |
| 2215 | /** |
| 2216 | * Log contains all problems (warnings+errors) |
| 2217 | */ |
| 2218 | // WORK potential candidate for elimination (19 calls) |
| 2219 | protected void runNegativeTest( |
| 2220 | String[] testFiles, |
| 2221 | String expectedCompilerLog, |
| 2222 | String[] classLibraries, |
| 2223 | boolean shouldFlushOutputDirectory, |
| 2224 | Map customOptions, |
| 2225 | boolean generateOutput, |
| 2226 | boolean showCategory, |
| 2227 | boolean showWarningToken, |
| 2228 | boolean skipJavac, |
| 2229 | boolean performStatementsRecovery) { |
| 2230 | runTest( |
| 2231 | // test directory preparation |
| 2232 | shouldFlushOutputDirectory /* should flush output directory */, |
| 2233 | testFiles /* test files */, |
| 2234 | // compiler options |
| 2235 | classLibraries /* class libraries */, |
| 2236 | customOptions /* custom options */, |
| 2237 | performStatementsRecovery /* perform statements recovery */, |
| 2238 | new Requestor( /* custom requestor */ |
| 2239 | generateOutput, |
| 2240 | null /* no custom requestor */, |
| 2241 | showCategory, |
| 2242 | showWarningToken), |
| 2243 | // compiler results |
| 2244 | expectedCompilerLog == null || /* expecting compiler errors */ |
| 2245 | expectedCompilerLog.indexOf("ERROR") != -1, |
| 2246 | expectedCompilerLog /* expected compiler log */, |
| 2247 | // runtime options |
| 2248 | false /* do not force execution */, |
| 2249 | null /* no vm arguments */, |
| 2250 | // runtime results |
| 2251 | null /* do not check output string */, |
| 2252 | null /* do not check error string */, |
| 2253 | // javac options |
| 2254 | skipJavac ? |
| 2255 | JavacTestOptions.SKIP : |
| 2256 | JavacTestOptions.DEFAULT /* javac test options */); |
| 2257 | } |
Stephan Herrmann | 4d07945 | 2014-03-27 18:01:49 +0100 | [diff] [blame] | 2258 | protected void runNegativeTest( |
| 2259 | String[] testFiles, |
| 2260 | String expectedCompilerLog, |
| 2261 | String[] classLibraries, |
| 2262 | boolean shouldFlushOutputDirectory, |
| 2263 | Map customOptions, |
| 2264 | boolean generateOutput, |
| 2265 | boolean showCategory, |
| 2266 | boolean showWarningToken, |
| 2267 | boolean skipJavac, |
| 2268 | JavacTestOptions javacOptions, |
| 2269 | boolean performStatementsRecovery) { |
| 2270 | runTest( |
| 2271 | // test directory preparation |
| 2272 | shouldFlushOutputDirectory /* should flush output directory */, |
| 2273 | testFiles /* test files */, |
| 2274 | // compiler options |
| 2275 | classLibraries /* class libraries */, |
| 2276 | customOptions /* custom options */, |
| 2277 | performStatementsRecovery /* perform statements recovery */, |
| 2278 | new Requestor( /* custom requestor */ |
| 2279 | generateOutput, |
| 2280 | null /* no custom requestor */, |
| 2281 | showCategory, |
| 2282 | showWarningToken), |
| 2283 | // compiler results |
| 2284 | expectedCompilerLog == null || /* expecting compiler errors */ |
| 2285 | expectedCompilerLog.indexOf("ERROR") != -1, |
| 2286 | expectedCompilerLog /* expected compiler log */, |
| 2287 | // runtime options |
| 2288 | false /* do not force execution */, |
| 2289 | null /* no vm arguments */, |
| 2290 | // runtime results |
| 2291 | null /* do not check output string */, |
| 2292 | null /* do not check error string */, |
| 2293 | // javac options |
| 2294 | skipJavac ? |
| 2295 | JavacTestOptions.SKIP : |
| 2296 | javacOptions/* javac test options */); |
| 2297 | } |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 2298 | protected void runTest( |
| 2299 | String[] testFiles, |
| 2300 | boolean expectingCompilerErrors, |
| 2301 | String expectedCompilerLog, |
| 2302 | String expectedOutputString, |
| 2303 | String expectedErrorString, |
| 2304 | boolean forceExecution, |
| 2305 | String[] classLibraries, |
| 2306 | boolean shouldFlushOutputDirectory, |
| 2307 | String[] vmArguments, |
| 2308 | Map customOptions, |
| 2309 | ICompilerRequestor customRequestor, |
| 2310 | boolean skipJavac) { |
| 2311 | runTest( |
| 2312 | // test directory preparation |
| 2313 | shouldFlushOutputDirectory /* should flush output directory */, |
| 2314 | testFiles /* test files */, |
| 2315 | // compiler options |
| 2316 | classLibraries /* class libraries */, |
| 2317 | customOptions /* custom options */, |
| 2318 | false /* do not perform statements recovery */, |
| 2319 | customRequestor /* custom requestor */, |
| 2320 | // compiler results |
| 2321 | expectingCompilerErrors /* expecting compiler errors */, |
| 2322 | expectedCompilerLog /* expected compiler log */, |
| 2323 | // runtime options |
| 2324 | forceExecution /* force execution */, |
| 2325 | vmArguments /* vm arguments */, |
| 2326 | // runtime results |
| 2327 | expectedOutputString /* expected output string */, |
| 2328 | expectedErrorString /* expected error string */, |
| 2329 | // javac options |
| 2330 | skipJavac ? |
| 2331 | JavacTestOptions.SKIP : |
| 2332 | JavacTestOptions.DEFAULT /* javac test options */); |
| 2333 | |
| 2334 | } |
| 2335 | |
| 2336 | // WORK get this out |
| 2337 | protected void runTest( |
| 2338 | String[] testFiles, |
| 2339 | boolean expectingCompilerErrors, |
| 2340 | String expectedCompilerLog, |
| 2341 | String expectedOutputString, |
| 2342 | String expectedErrorString, |
| 2343 | boolean forceExecution, |
| 2344 | String[] classLibraries, |
| 2345 | boolean shouldFlushOutputDirectory, |
| 2346 | String[] vmArguments, |
| 2347 | Map customOptions, |
| 2348 | ICompilerRequestor clientRequestor, |
| 2349 | JavacTestOptions javacTestOptions) { |
| 2350 | runTest( |
| 2351 | // test directory preparation |
| 2352 | shouldFlushOutputDirectory /* should flush output directory */, |
| 2353 | testFiles /* test files */, |
| 2354 | // compiler options |
| 2355 | classLibraries /* class libraries */, |
| 2356 | customOptions /* custom options */, |
| 2357 | false /* do not perform statements recovery */, |
| 2358 | clientRequestor /* custom requestor */, |
| 2359 | // compiler results |
| 2360 | expectingCompilerErrors /* expecting compiler errors */, |
| 2361 | expectedCompilerLog /* expected compiler log */, |
| 2362 | // runtime options |
| 2363 | forceExecution /* force execution */, |
| 2364 | vmArguments /* vm arguments */, |
| 2365 | // runtime results |
| 2366 | expectedOutputString /* expected output string */, |
| 2367 | expectedErrorString /* expected error string */, |
| 2368 | // javac options |
| 2369 | javacTestOptions /* javac test options */); |
| 2370 | } |
Stephan Herrmann | 024160d | 2013-05-02 04:29:33 +0200 | [diff] [blame] | 2371 | //{ObjectTeams: made accessible to sub-classes: |
| 2372 | protected void runTest( |
| 2373 | // SH} |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 2374 | // test directory preparation |
| 2375 | boolean shouldFlushOutputDirectory, |
| 2376 | String[] testFiles, |
| 2377 | // compiler options |
| 2378 | String[] classLibraries, |
| 2379 | Map customOptions, |
| 2380 | boolean performStatementsRecovery, |
| 2381 | ICompilerRequestor customRequestor, |
| 2382 | // compiler results |
| 2383 | boolean expectingCompilerErrors, |
| 2384 | String expectedCompilerLog, |
| 2385 | // runtime options |
| 2386 | boolean forceExecution, |
| 2387 | String[] vmArguments, |
| 2388 | // runtime results |
| 2389 | String expectedOutputString, |
| 2390 | String expectedErrorString, |
| 2391 | // javac options |
| 2392 | JavacTestOptions javacTestOptions) { |
Stephan Herrmann | de4efa9 | 2010-09-26 16:11:28 +0000 | [diff] [blame] | 2393 | runTest( |
| 2394 | shouldFlushOutputDirectory, |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 2395 | testFiles, |
Stephan Herrmann | de4efa9 | 2010-09-26 16:11:28 +0000 | [diff] [blame] | 2396 | new String[] {}, |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 2397 | classLibraries, |
| 2398 | customOptions, |
| 2399 | performStatementsRecovery, |
| 2400 | customRequestor, |
| 2401 | expectingCompilerErrors, |
| 2402 | expectedCompilerLog, |
Stephan Herrmann | 4d07945 | 2014-03-27 18:01:49 +0100 | [diff] [blame] | 2403 | null, // alternate compile errors |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 2404 | forceExecution, |
| 2405 | vmArguments, |
| 2406 | expectedOutputString, |
| 2407 | expectedErrorString, |
| 2408 | null, |
| 2409 | javacTestOptions); |
| 2410 | } |
Stephan Herrmann | 4d07945 | 2014-03-27 18:01:49 +0100 | [diff] [blame] | 2411 | /** Call this if the compiler randomly produces different error logs. */ |
| 2412 | protected void runNegativeTestMultiResult(String[] testFiles, Map options, String[] alternateCompilerErrorLogs) { |
| 2413 | runTest( |
| 2414 | false, |
| 2415 | testFiles, |
| 2416 | new String[] {}, |
| 2417 | null, |
| 2418 | options, |
| 2419 | false, |
| 2420 | new Requestor( /* custom requestor */ |
| 2421 | false, |
| 2422 | null /* no custom requestor */, |
| 2423 | false, |
| 2424 | false), |
| 2425 | true, |
| 2426 | null, |
| 2427 | alternateCompilerErrorLogs, |
| 2428 | false, |
| 2429 | null, |
| 2430 | null, |
| 2431 | null, |
| 2432 | null, |
| 2433 | JavacTestOptions.DEFAULT); |
| 2434 | } |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 2435 | // This is a worker method to support regression tests. To ease policy changes, |
| 2436 | // it should not be called directly, but through the runConformTest and |
| 2437 | // runNegativeTest series. |
| 2438 | // calling templates: |
| 2439 | // runTest( |
| 2440 | // // test directory preparation |
| 2441 | // true /* flush output directory */, |
| 2442 | // false /* do not flush output directory */, |
| 2443 | // shouldFlushOutputDirectory /* should flush output directory */, |
| 2444 | // |
| 2445 | // new String[] { /* test files */ |
| 2446 | // }, |
| 2447 | // null /* no test files */, |
| 2448 | // testFiles /* test files */, |
| 2449 | // |
| 2450 | // // compiler options |
| 2451 | // null /* no class libraries */, |
| 2452 | // new String[] { /* class libraries */ |
| 2453 | // }, |
| 2454 | // classLibraries /* class libraries */, |
| 2455 | // |
| 2456 | // null /* no custom options */, |
| 2457 | // customOptions /* custom options */, |
| 2458 | // |
| 2459 | // true /* perform statements recovery */, |
| 2460 | // false /* do not perform statements recovery */, |
| 2461 | // performStatementsRecovery /* perform statements recovery */, |
| 2462 | // |
| 2463 | // null /* no custom requestor */, |
| 2464 | // customRequestor /* custom requestor */, |
| 2465 | // |
| 2466 | // // compiler results |
| 2467 | // false /* expecting no compiler errors */, |
| 2468 | // true /* expecting compiler errors */, |
| 2469 | // expectingCompilerErrors /* expecting compiler errors */, |
| 2470 | // |
| 2471 | // null /* do not check compiler log */, |
| 2472 | // "" /* expected compiler log */, |
| 2473 | // expectedCompilerLog /* expected compiler log */, |
| 2474 | // |
| 2475 | // // runtime options |
| 2476 | // false /* do not force execution */, |
| 2477 | // true /* force execution */, |
| 2478 | // forceExecution /* force execution */, |
| 2479 | // |
| 2480 | // null /* no vm arguments */, |
| 2481 | // new String[] { /* vm arguments */ |
| 2482 | // }, |
| 2483 | // vmArguments /* vm arguments */, |
| 2484 | // |
| 2485 | // // runtime results |
| 2486 | // null /* do not check output string */, |
| 2487 | // "" /* expected output string */, |
| 2488 | // expectedOutputString /* expected output string */, |
| 2489 | // |
| 2490 | // null /* do not check error string */, |
| 2491 | // "" /* expected error string */, |
| 2492 | // expectedErrorString /* expected error string */, |
| 2493 | // |
| 2494 | // // javac options |
| 2495 | // JavacTestOptions.SKIP /* skip javac tests */); |
| 2496 | // JavacTestOptions.DEFAULT /* default javac test options */); |
| 2497 | // javacTestOptions /* javac test options */); |
| 2498 | // TODO Maxime future work: |
| 2499 | // - reduce the number of tests that implicitly skip parts like logs |
| 2500 | // comparisons; while this is due to eat up more time, we will gain in |
| 2501 | // coverage (and detection of unwanted changes); of course, this will tend |
| 2502 | // to 'over constrain' some tests, but a reasonable approach would be to |
| 2503 | // unable the comparison for tests which just happen to be fine; |
| 2504 | // - check the callees statistics for wrapper methods and tune them accordingly |
| 2505 | // (aka, suppress low profile ones). |
| 2506 | // WORK log test files in all failure cases (ez cut and paste) |
| 2507 | private void runTest( |
| 2508 | // test directory preparation |
| 2509 | boolean shouldFlushOutputDirectory, |
| 2510 | String[] testFiles, |
Stephan Herrmann | de4efa9 | 2010-09-26 16:11:28 +0000 | [diff] [blame] | 2511 | String[] dependantFiles, |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 2512 | // compiler options |
| 2513 | String[] classLibraries, |
| 2514 | Map customOptions, |
| 2515 | boolean performStatementsRecovery, |
| 2516 | ICompilerRequestor customRequestor, |
| 2517 | // compiler results |
| 2518 | boolean expectingCompilerErrors, |
| 2519 | String expectedCompilerLog, |
Stephan Herrmann | 4d07945 | 2014-03-27 18:01:49 +0100 | [diff] [blame] | 2520 | String[] alternateCompilerLogs, |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 2521 | // runtime options |
| 2522 | boolean forceExecution, |
| 2523 | String[] vmArguments, |
| 2524 | // runtime results |
| 2525 | String expectedOutputString, |
| 2526 | String expectedErrorString, |
| 2527 | final ASTVisitor visitor, |
| 2528 | // javac options |
| 2529 | JavacTestOptions javacTestOptions) { |
| 2530 | // non-javac part |
| 2531 | if (shouldFlushOutputDirectory) |
| 2532 | Util.flushDirectoryContent(new File(OUTPUT_DIR)); |
| 2533 | // complain early in RUN_JAVAC mode (avoid to do it else until we've fixed all tests) |
| 2534 | if (RUN_JAVAC && testFiles != null && (testFiles.length % 2) != 0) { |
| 2535 | fail("odd number of strings in testFiles"); |
| 2536 | } |
| 2537 | |
| 2538 | Requestor requestor = |
| 2539 | customRequestor instanceof Requestor ? |
| 2540 | (Requestor) customRequestor : |
| 2541 | new Requestor( |
| 2542 | forceExecution, |
| 2543 | customRequestor, |
| 2544 | false, /* show category */ |
| 2545 | false /* show warning token*/); |
| 2546 | requestor.outputPath = OUTPUT_DIR.endsWith(File.separator) ? OUTPUT_DIR : OUTPUT_DIR + File.separator; |
| 2547 | // WORK should not have to test a constant? |
| 2548 | |
| 2549 | Map options = getCompilerOptions(); |
| 2550 | if (customOptions != null) { |
| 2551 | options.putAll(customOptions); |
| 2552 | } |
| 2553 | CompilerOptions compilerOptions = new CompilerOptions(options); |
| 2554 | compilerOptions.performMethodsFullRecovery = performStatementsRecovery; |
| 2555 | compilerOptions.performStatementsRecovery = performStatementsRecovery; |
Stephan Herrmann | de4efa9 | 2010-09-26 16:11:28 +0000 | [diff] [blame] | 2556 | INameEnvironment nameEnvironment = getNameEnvironment(dependantFiles, classLibraries); |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 2557 | Compiler batchCompiler = |
| 2558 | new Compiler( |
| 2559 | nameEnvironment, |
| 2560 | getErrorHandlingPolicy(), |
| 2561 | compilerOptions, |
| 2562 | requestor, |
| 2563 | getProblemFactory()) { |
| 2564 | public void process(org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration unit, int i) { |
| 2565 | super.process(unit, i); |
| 2566 | if (visitor != null) { |
| 2567 | unit.traverse(visitor, unit.scope); |
| 2568 | } |
| 2569 | } |
| 2570 | }; |
Stephan Herrmann | 8f59a94 | 2015-02-01 15:13:21 +0100 | [diff] [blame] | 2571 | if (this.enableAPT) { |
| 2572 | batchCompiler.annotationProcessorManager = getAnnotationProcessorManager(batchCompiler); |
| 2573 | } |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 2574 | compilerOptions.produceReferenceInfo = true; |
| 2575 | Throwable exception = null; |
| 2576 | try { |
Stephan Herrmann | ed07f3b | 2010-04-21 21:57:08 +0000 | [diff] [blame] | 2577 | //{ObjectTeams: extracted as new hook: |
| 2578 | /* orig: |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 2579 | batchCompiler.compile(Util.compilationUnits(testFiles)); // compile all files together |
Stephan Herrmann | ed07f3b | 2010-04-21 21:57:08 +0000 | [diff] [blame] | 2580 | :giro */ |
Stephan Herrmann | c6f9766 | 2015-05-01 20:55:29 +0200 | [diff] [blame] | 2581 | batchCompiler.sortCompilationUnits = false; // maintain original order for JDT/Core tests |
Stephan Herrmann | ed07f3b | 2010-04-21 21:57:08 +0000 | [diff] [blame] | 2582 | compileTestFiles(batchCompiler, testFiles); |
| 2583 | // SH} |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 2584 | } catch(RuntimeException e){ |
| 2585 | exception = e; |
| 2586 | throw e; |
| 2587 | } catch(Error e) { |
| 2588 | exception = e; |
| 2589 | throw e; |
| 2590 | } finally { |
| 2591 | nameEnvironment.cleanup(); |
Stephan Herrmann | 4d07945 | 2014-03-27 18:01:49 +0100 | [diff] [blame] | 2592 | String[] alternatePlatformIndepentLogs = null; |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 2593 | if (expectedCompilerLog != null) { |
Stephan Herrmann | 4d07945 | 2014-03-27 18:01:49 +0100 | [diff] [blame] | 2594 | alternatePlatformIndepentLogs = new String[] {Util.convertToIndependantLineDelimiter(expectedCompilerLog)}; |
| 2595 | } else if (alternateCompilerLogs != null) { |
| 2596 | alternatePlatformIndepentLogs = new String[alternateCompilerLogs.length]; |
| 2597 | for (int i = 0; i < alternateCompilerLogs.length; i++) |
| 2598 | alternatePlatformIndepentLogs[i] = Util.convertToIndependantLineDelimiter(alternateCompilerLogs[i]); |
| 2599 | } |
| 2600 | if (alternatePlatformIndepentLogs != null) { |
| 2601 | checkCompilerLog(testFiles, requestor, alternatePlatformIndepentLogs, exception); |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 2602 | } |
| 2603 | if (exception == null) { |
| 2604 | if (expectingCompilerErrors) { |
| 2605 | if (!requestor.hasErrors) { |
| 2606 | logTestFiles(true, testFiles); |
| 2607 | fail("Unexpected success"); |
| 2608 | } |
| 2609 | } else if (requestor.hasErrors) { |
| 2610 | if (!"".equals(requestor.problemLog)) { |
| 2611 | logTestFiles(true, testFiles); |
| 2612 | System.out.println("Copy-paste compiler log:"); |
| 2613 | System.out.println(Util.displayString(Util.convertToIndependantLineDelimiter(requestor.problemLog.toString()), INDENT, SHIFT)); |
| 2614 | assertEquals("Unexpected failure", "", requestor.problemLog); |
| 2615 | } |
| 2616 | } |
| 2617 | } |
| 2618 | } |
| 2619 | if (!requestor.hasErrors || forceExecution) { |
| 2620 | String sourceFile = testFiles[0]; |
| 2621 | |
| 2622 | // Compute class name by removing ".java" and replacing slashes with dots |
| 2623 | String className = sourceFile.substring(0, sourceFile.length() - 5).replace('/', '.').replace('\\', '.'); |
| 2624 | if (className.endsWith(PACKAGE_INFO_NAME)) return; |
| 2625 | |
Stephan Herrmann | ed07f3b | 2010-04-21 21:57:08 +0000 | [diff] [blame] | 2626 | //{ObjectTeams: also reuse if same set of vmArguments: |
| 2627 | /* orig: |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 2628 | if (vmArguments != null) { |
Stephan Herrmann | ed07f3b | 2010-04-21 21:57:08 +0000 | [diff] [blame] | 2629 | :giro */ |
| 2630 | if (this.verifier != null && !this.verifier.vmArgsEqual(vmArguments)) { |
| 2631 | // SH} |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 2632 | if (this.verifier != null) { |
| 2633 | this.verifier.shutDown(); |
| 2634 | } |
Stephan Herrmann | ed07f3b | 2010-04-21 21:57:08 +0000 | [diff] [blame] | 2635 | //{ObjectTeams: make configurable: |
| 2636 | /* orig: |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 2637 | this.verifier = new TestVerifier(false); |
Stephan Herrmann | ed07f3b | 2010-04-21 21:57:08 +0000 | [diff] [blame] | 2638 | :giro */ |
| 2639 | this.verifier = getTestVerifier(false); |
| 2640 | // SH} |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 2641 | this.createdVerifier = true; |
| 2642 | } |
| 2643 | boolean passed = |
| 2644 | this.verifier.verifyClassFiles( |
| 2645 | sourceFile, |
| 2646 | className, |
| 2647 | expectedOutputString, |
| 2648 | expectedErrorString, |
| 2649 | this.classpaths, |
| 2650 | null, |
| 2651 | vmArguments); |
| 2652 | if (!passed) { |
| 2653 | System.out.println(getClass().getName() + '#' + getName()); |
| 2654 | String execErrorString = this.verifier.getExecutionError(); |
| 2655 | if (execErrorString != null && execErrorString.length() > 0) { |
| 2656 | System.out.println("[ERR]:"+execErrorString); //$NON-NLS-1$ |
| 2657 | } |
| 2658 | String execOutputString = this.verifier.getExecutionOutput(); |
| 2659 | if (execOutputString != null && execOutputString.length() > 0) { |
| 2660 | System.out.println("[OUT]:"+execOutputString); //$NON-NLS-1$ |
| 2661 | } |
| 2662 | for (int i = 0; i < testFiles.length; i += 2) { |
| 2663 | System.out.print(testFiles[i]); |
| 2664 | System.out.println(" ["); //$NON-NLS-1$ |
| 2665 | System.out.println(testFiles[i + 1]); |
| 2666 | System.out.println("]"); //$NON-NLS-1$ |
| 2667 | } |
| 2668 | } |
| 2669 | assertTrue(this.verifier.failureReason, // computed by verifyClassFiles(...) action |
| 2670 | passed); |
| 2671 | if (vmArguments != null) { |
| 2672 | if (this.verifier != null) { |
| 2673 | this.verifier.shutDown(); |
| 2674 | } |
| 2675 | this.verifier = new TestVerifier(false); |
| 2676 | this.createdVerifier = true; |
| 2677 | } |
| 2678 | } |
| 2679 | // javac part |
| 2680 | if (RUN_JAVAC && javacTestOptions != JavacTestOptions.SKIP) { |
| 2681 | runJavac(testFiles, expectingCompilerErrors, expectedCompilerLog, |
| 2682 | expectedOutputString, expectedErrorString, shouldFlushOutputDirectory, |
| 2683 | javacTestOptions, vmArguments); |
| 2684 | } |
| 2685 | } |
Stephan Herrmann | 8f59a94 | 2015-02-01 15:13:21 +0100 | [diff] [blame] | 2686 | |
| 2687 | class DummyAnnotationProcessingManager extends BaseAnnotationProcessorManager { |
| 2688 | |
| 2689 | ProcessorInfo processorInfo = null; |
| 2690 | public ProcessorInfo discoverNextProcessor() { |
| 2691 | ProcessorInfo temp = this.processorInfo; |
| 2692 | this.processorInfo = null; |
| 2693 | return temp; |
| 2694 | } |
| 2695 | |
| 2696 | public void reportProcessorException(Processor p, Exception e) { |
| 2697 | throw new AbortCompilation(null, e); |
| 2698 | } |
| 2699 | |
| 2700 | @Override |
| 2701 | public void setProcessors(Object[] processors) { |
| 2702 | // Nothing to do here |
| 2703 | } |
| 2704 | |
| 2705 | @Override |
| 2706 | public void configure(Object batchCompiler, String[] options) { |
| 2707 | this._processingEnv = new DummyEnvironmentImpl((Compiler) batchCompiler); |
| 2708 | } |
| 2709 | public void processAnnotations(CompilationUnitDeclaration[] units, ReferenceBinding[] referenceBindings, boolean isLastRound) { |
| 2710 | if (this.processorInfo == null) { |
| 2711 | this.processorInfo = new ProcessorInfo(new DummyProcessor()); |
| 2712 | } |
| 2713 | super.processAnnotations(units, referenceBindings, isLastRound); |
| 2714 | } |
| 2715 | |
| 2716 | @Override |
| 2717 | public void configureFromPlatform(Compiler compiler, Object compilationUnitLocator, Object javaProject) { |
| 2718 | // Nothing to do here |
| 2719 | } |
| 2720 | @SupportedAnnotationTypes("*") |
| 2721 | class DummyProcessor extends AbstractProcessor { |
| 2722 | @Override |
| 2723 | public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
| 2724 | return true; |
| 2725 | } |
| 2726 | } |
| 2727 | |
| 2728 | class DummyEnvironmentImpl extends BaseProcessingEnvImpl { |
| 2729 | public DummyEnvironmentImpl(Compiler compiler) { |
| 2730 | this._compiler = compiler; |
| 2731 | } |
| 2732 | @Override |
| 2733 | public Locale getLocale() { |
| 2734 | return Locale.getDefault(); |
| 2735 | } |
| 2736 | } |
| 2737 | } |
| 2738 | |
| 2739 | protected AbstractAnnotationProcessorManager getAnnotationProcessorManager(Compiler compiler) { |
| 2740 | try { |
| 2741 | AbstractAnnotationProcessorManager annotationManager = new DummyAnnotationProcessingManager(); |
| 2742 | annotationManager.configure(compiler, new String[0]); |
| 2743 | annotationManager.setErr(new PrintWriter(System.err)); |
| 2744 | annotationManager.setOut(new PrintWriter(System.out)); |
| 2745 | return annotationManager; |
| 2746 | } catch(UnsupportedClassVersionError e) { |
| 2747 | System.err.println(e); |
| 2748 | } |
| 2749 | return null; |
| 2750 | } |
| 2751 | |
Stephan Herrmann | ed07f3b | 2010-04-21 21:57:08 +0000 | [diff] [blame] | 2752 | //{ObjectTeams: new hooks: |
| 2753 | protected TestVerifier getTestVerifier(boolean reuseVM) { |
| 2754 | return new TestVerifier(reuseVM); |
| 2755 | } |
| 2756 | protected void compileTestFiles(Compiler batchCompiler, String[] testFiles) { |
| 2757 | batchCompiler.compile(Util.compilationUnits(testFiles)); // compile all files together |
| 2758 | } |
| 2759 | // SH} |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 2760 | |
| 2761 | // runConformTest( |
| 2762 | // // test directory preparation |
| 2763 | // new String[] { /* test files */ |
| 2764 | // }, |
| 2765 | // // javac options |
| 2766 | // JavacTestOptions.SKIP /* skip javac tests */); |
| 2767 | // JavacTestOptions.DEFAULT /* default javac test options */); |
| 2768 | // javacTestOptions /* javac test options */); |
| 2769 | public void runConformTest( |
| 2770 | // test directory preparation |
| 2771 | String[] testFiles, |
| 2772 | // javac options |
| 2773 | JavacTestOptions javacTestOptions) { |
| 2774 | runTest( |
| 2775 | // test directory preparation |
| 2776 | true /* flush output directory */, |
| 2777 | testFiles /* test files */, |
| 2778 | // compiler options |
| 2779 | null /* no class libraries */, |
| 2780 | null /* no custom options */, |
| 2781 | false /* do not perform statements recovery */, |
| 2782 | null /* no custom requestor */, |
| 2783 | // compiler results |
| 2784 | false /* expecting no compiler errors */, |
| 2785 | "" /* expected compiler log */, |
| 2786 | // runtime options |
| 2787 | false /* do not force execution */, |
| 2788 | null /* no vm arguments */, |
| 2789 | // runtime results |
| 2790 | "" /* expected output string */, |
| 2791 | "" /* expected error string */, |
| 2792 | // javac options |
| 2793 | javacTestOptions /* javac test options */); |
| 2794 | } |
| 2795 | // runConformTest( |
| 2796 | // // test directory preparation |
| 2797 | // true /* flush output directory */, |
| 2798 | // false /* do not flush output directory */, |
| 2799 | // shouldFlushOutputDirectory /* should flush output directory */, |
| 2800 | // |
| 2801 | // new String[] { /* test files */ |
| 2802 | // }, |
| 2803 | // null /* no test files */, |
| 2804 | // testFiles /* test files */, |
| 2805 | // |
| 2806 | // // compiler results |
| 2807 | // null /* do not check compiler log */, |
| 2808 | // "" /* expected compiler log */, |
| 2809 | // expectedCompilerLog /* expected compiler log */, |
| 2810 | // |
| 2811 | // // runtime results |
| 2812 | // null /* do not check output string */, |
| 2813 | // "" /* expected output string */, |
| 2814 | // expectedOutputString /* expected output string */, |
| 2815 | // |
| 2816 | // null /* do not check error string */, |
| 2817 | // "" /* expected error string */, |
| 2818 | // expectedErrorString /* expected error string */, |
| 2819 | // |
| 2820 | // // javac options |
| 2821 | // JavacTestOptions.SKIP /* skip javac tests */); |
| 2822 | // JavacTestOptions.DEFAULT /* default javac test options */); |
| 2823 | // javacTestOptions /* javac test options */); |
| 2824 | protected void runConformTest( |
| 2825 | // test directory preparation |
| 2826 | boolean shouldFlushOutputDirectory, |
| 2827 | String[] testFiles, |
| 2828 | // compiler results |
| 2829 | String expectedCompilerLog, |
| 2830 | // runtime results |
| 2831 | String expectedOutputString, |
| 2832 | String expectedErrorString, |
| 2833 | // javac options |
| 2834 | JavacTestOptions javacTestOptions) { |
| 2835 | runTest( |
| 2836 | // test directory preparation |
| 2837 | shouldFlushOutputDirectory /* should flush output directory */, |
| 2838 | testFiles /* test files */, |
| 2839 | // compiler options |
| 2840 | null /* no class libraries */, |
| 2841 | null /* no custom options */, |
| 2842 | false /* do not perform statements recovery */, |
| 2843 | null /* no custom requestor */, |
| 2844 | // compiler results |
| 2845 | false /* expecting no compiler errors */, |
| 2846 | expectedCompilerLog /* expected compiler log */, |
| 2847 | // runtime options |
| 2848 | false /* do not force execution */, |
| 2849 | null /* no vm arguments */, |
| 2850 | // runtime results |
| 2851 | expectedOutputString /* expected output string */, |
| 2852 | expectedErrorString /* expected error string */, |
| 2853 | // javac options |
| 2854 | javacTestOptions /* javac test options */); |
| 2855 | } |
| 2856 | // runConformTest( |
| 2857 | // // test directory preparation |
| 2858 | // true /* flush output directory */, |
| 2859 | // false /* do not flush output directory */, |
| 2860 | // |
| 2861 | // new String[] { /* test files */ |
| 2862 | // }, |
| 2863 | // null /* no test files */, |
| 2864 | // |
| 2865 | // // compiler options |
| 2866 | // null /* no class libraries */, |
| 2867 | // new String[] { /* class libraries */ |
| 2868 | // }, |
| 2869 | // |
| 2870 | // null /* no custom options */, |
| 2871 | // customOptions /* custom options */, |
| 2872 | // |
| 2873 | // // compiler results |
| 2874 | // null /* do not check compiler log */, |
| 2875 | // "----------\n" + /* expected compiler log */ |
| 2876 | // "" /* expected compiler log */, |
| 2877 | // |
| 2878 | // // runtime results |
| 2879 | // null /* do not check output string */, |
| 2880 | // "" /* expected output string */, |
| 2881 | // expectedOutputString /* expected output string */, |
| 2882 | // |
| 2883 | // null /* do not check error string */, |
| 2884 | // "" /* expected error string */, |
| 2885 | // expectedErrorString /* expected error string */, |
| 2886 | // |
| 2887 | // // javac options |
| 2888 | // JavacTestOptions.SKIP /* skip javac tests */); |
| 2889 | // JavacTestOptions.DEFAULT /* default javac test options */); |
| 2890 | // javacTestOptions /* javac test options */); |
| 2891 | protected void runConformTest( |
| 2892 | // test directory preparation |
| 2893 | boolean shouldFlushOutputDirectory, |
| 2894 | String[] testFiles, |
| 2895 | //compiler options |
| 2896 | String[] classLibraries /* class libraries */, |
| 2897 | Map customOptions /* custom options */, |
| 2898 | // compiler results |
| 2899 | String expectedCompilerLog, |
| 2900 | // runtime results |
| 2901 | String expectedOutputString, |
| 2902 | String expectedErrorString, |
| 2903 | // javac options |
| 2904 | JavacTestOptions javacTestOptions) { |
| 2905 | runTest( |
| 2906 | // test directory preparation |
| 2907 | shouldFlushOutputDirectory /* should flush output directory */, |
| 2908 | testFiles /* test files */, |
| 2909 | // compiler options |
| 2910 | classLibraries /* class libraries */, |
| 2911 | customOptions /* custom options */, |
| 2912 | false /* do not perform statements recovery */, |
| 2913 | null /* no custom requestor */, |
| 2914 | // compiler results |
| 2915 | false /* expecting no compiler errors */, |
| 2916 | expectedCompilerLog /* expected compiler log */, |
| 2917 | // runtime options |
| 2918 | false /* do not force execution */, |
| 2919 | null /* no vm arguments */, |
| 2920 | // runtime results |
| 2921 | expectedOutputString /* expected output string */, |
| 2922 | expectedErrorString /* expected error string */, |
| 2923 | // javac options |
| 2924 | javacTestOptions /* javac test options */); |
| 2925 | } |
| 2926 | // runNegativeTest( |
| 2927 | // // test directory preparation |
| 2928 | // new String[] { /* test files */ |
| 2929 | // }, |
| 2930 | // null /* no test files */, |
| 2931 | // // compiler results |
| 2932 | // "----------\n" + /* expected compiler log */ |
| 2933 | // // javac options |
| 2934 | // JavacTestOptions.SKIP /* skip javac tests */); |
| 2935 | // JavacTestOptions.DEFAULT /* default javac test options */); |
| 2936 | // javacTestOptions /* javac test options */); |
| 2937 | protected void runNegativeTest( |
| 2938 | // test directory preparation |
| 2939 | String[] testFiles, |
| 2940 | // compiler results |
| 2941 | String expectedCompilerLog, |
| 2942 | // javac options |
| 2943 | JavacTestOptions javacTestOptions) { |
| 2944 | runTest( |
| 2945 | // test directory preparation |
| 2946 | true /* flush output directory */, |
| 2947 | testFiles /* test files */, |
| 2948 | // compiler options |
| 2949 | null /* no class libraries */, |
| 2950 | null /* no custom options */, |
| 2951 | false /* do not perform statements recovery */, |
| 2952 | null /* no custom requestor */, |
| 2953 | // compiler results |
Stephan Herrmann | b0a2f8b | 2013-09-08 15:00:03 +0200 | [diff] [blame] | 2954 | true /* expecting compiler errors */, |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 2955 | expectedCompilerLog /* expected compiler log */, |
| 2956 | // runtime options |
| 2957 | false /* do not force execution */, |
| 2958 | null /* no vm arguments */, |
| 2959 | // runtime results |
| 2960 | null /* do not check output string */, |
| 2961 | null /* do not check error string */, |
| 2962 | // javac options |
| 2963 | javacTestOptions /* javac test options */); |
| 2964 | } |
| 2965 | // runNegativeTest( |
| 2966 | // // test directory preparation |
| 2967 | // true /* flush output directory */, |
| 2968 | // false /* do not flush output directory */, |
| 2969 | // shouldFlushOutputDirectory /* should flush output directory */, |
| 2970 | // |
| 2971 | // new String[] { /* test files */ |
| 2972 | // }, |
| 2973 | // null /* no test files */, |
| 2974 | // |
| 2975 | // // compiler options |
| 2976 | // null /* no class libraries */, |
| 2977 | // new String[] { /* class libraries */ |
| 2978 | // }, |
| 2979 | // classLibraries /* class libraries */, |
| 2980 | // |
| 2981 | // null /* no custom options */, |
| 2982 | // customOptions /* custom options */, |
| 2983 | // |
| 2984 | // // compiler results |
| 2985 | // null /* do not check compiler log */, |
| 2986 | // "----------\n" + /* expected compiler log */ |
| 2987 | // |
| 2988 | // // javac options |
| 2989 | // JavacTestOptions.SKIP /* skip javac tests */); |
| 2990 | // JavacTestOptions.DEFAULT /* default javac test options */); |
| 2991 | // javacTestOptions /* javac test options */); |
| 2992 | protected void runNegativeTest( |
| 2993 | // test directory preparation |
| 2994 | boolean shouldFlushOutputDirectory, |
| 2995 | String[] testFiles, |
| 2996 | // compiler options |
| 2997 | String[] classLibraries, |
| 2998 | Map customOptions, |
| 2999 | // compiler results |
| 3000 | String expectedCompilerLog, |
| 3001 | // javac options |
| 3002 | JavacTestOptions javacTestOptions) { |
| 3003 | runTest( |
| 3004 | // test directory preparation |
| 3005 | shouldFlushOutputDirectory /* should flush output directory */, |
| 3006 | testFiles /* test files */, |
| 3007 | // compiler options |
| 3008 | classLibraries /* class libraries */, |
| 3009 | customOptions /* custom options */, |
| 3010 | false /* do not perform statements recovery */, |
| 3011 | null /* no custom requestor */, |
| 3012 | // compiler results |
Stephan Herrmann | b0a2f8b | 2013-09-08 15:00:03 +0200 | [diff] [blame] | 3013 | expectedCompilerLog == null || /* expecting compiler errors */ |
| 3014 | expectedCompilerLog.indexOf("ERROR") != -1, |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 3015 | expectedCompilerLog /* expected compiler log */, |
| 3016 | // runtime options |
| 3017 | false /* do not force execution */, |
| 3018 | null /* no vm arguments */, |
| 3019 | // runtime results |
| 3020 | null /* do not check output string */, |
| 3021 | null /* do not check error string */, |
| 3022 | // javac options |
| 3023 | javacTestOptions /* javac test options */); |
| 3024 | } |
| 3025 | // runNegativeTest( |
| 3026 | // // test directory preparation |
| 3027 | // true /* flush output directory */, |
| 3028 | // false /* do not flush output directory */, |
| 3029 | // shouldFlushOutputDirectory /* should flush output directory */, |
| 3030 | // |
| 3031 | // new String[] { /* test files */ |
| 3032 | // }, |
| 3033 | // null /* no test files */, |
| 3034 | // |
| 3035 | // // compiler options |
| 3036 | // null /* no class libraries */, |
| 3037 | // new String[] { /* class libraries */ |
| 3038 | // }, |
| 3039 | // classLibraries /* class libraries */, |
| 3040 | // |
| 3041 | // null /* no custom options */, |
| 3042 | // customOptions /* custom options */, |
| 3043 | // |
| 3044 | // // compiler results |
| 3045 | // null /* do not check compiler log */, |
| 3046 | // "----------\n" + /* expected compiler log */ |
| 3047 | // |
| 3048 | // //runtime results |
| 3049 | // null /* do not check output string */, |
| 3050 | // "" /* expected output string */, |
| 3051 | // expectedOutputString /* expected output string */, |
| 3052 | // |
| 3053 | // null /* do not check error string */, |
| 3054 | // "" /* expected error string */, |
| 3055 | // expectedErrorString /* expected error string */, |
| 3056 | // |
| 3057 | // // javac options |
| 3058 | // JavacTestOptions.SKIP /* skip javac tests */); |
| 3059 | // JavacTestOptions.DEFAULT /* default javac test options */); |
| 3060 | // javacTestOptions /* javac test options */); |
Stephan Herrmann | c6f6284 | 2011-01-27 12:07:14 +0000 | [diff] [blame] | 3061 | protected void runNegativeTest( |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 3062 | // test directory preparation |
| 3063 | boolean shouldFlushOutputDirectory, |
| 3064 | String[] testFiles, |
| 3065 | // compiler options |
| 3066 | String[] classLibraries, |
| 3067 | Map customOptions, |
| 3068 | // compiler results |
| 3069 | String expectedCompilerLog, |
| 3070 | // runtime results |
| 3071 | String expectedOutputString, |
| 3072 | String expectedErrorString, |
| 3073 | // javac options |
| 3074 | JavacTestOptions javacTestOptions) { |
| 3075 | runTest( |
| 3076 | // test directory preparation |
| 3077 | shouldFlushOutputDirectory /* should flush output directory */, |
| 3078 | testFiles /* test files */, |
| 3079 | // compiler options |
| 3080 | classLibraries /* class libraries */, |
| 3081 | customOptions /* custom options */, |
| 3082 | false /* do not perform statements recovery */, |
| 3083 | null /* no custom requestor */, |
| 3084 | // compiler results |
| 3085 | true /* expecting compiler errors */, |
| 3086 | expectedCompilerLog /* expected compiler log */, |
| 3087 | // runtime options |
| 3088 | true /* force execution */, |
| 3089 | null /* no vm arguments */, |
| 3090 | // runtime results |
| 3091 | expectedOutputString /* expected output string */, |
| 3092 | expectedErrorString /* expected error string */, |
| 3093 | // javac options |
| 3094 | javacTestOptions /* javac test options */); |
| 3095 | } |
| 3096 | protected void setUp() throws Exception { |
| 3097 | super.setUp(); |
| 3098 | if (this.verifier == null) { |
| 3099 | this.verifier = new TestVerifier(true); |
| 3100 | this.createdVerifier = true; |
| 3101 | } |
| 3102 | if (RUN_JAVAC) { |
| 3103 | // WORK make all needed inits once and for all |
| 3104 | if (isFirst()) { |
| 3105 | if (javacFullLog == null) { |
| 3106 | // One time initialization of javac related concerns |
| 3107 | // compute command lines and extract javac version |
| 3108 | JAVAC_OUTPUT_DIR = new File(JAVAC_OUTPUT_DIR_NAME); |
| 3109 | // WORK simplify jdk.root out |
| 3110 | String jdkRootDirectory = System.getProperty("jdk.root"); |
| 3111 | if (jdkRootDirectory == null) |
| 3112 | jdkRootDirPath = (new Path(Util.getJREDirectory())).removeLastSegments(1); |
| 3113 | else |
| 3114 | jdkRootDirPath = new Path(jdkRootDirectory); |
| 3115 | |
| 3116 | StringBuffer cmdLineHeader = new StringBuffer(jdkRootDirPath. |
| 3117 | append("bin").append(JAVA_NAME).toString()); // PREMATURE replace JAVA_NAME and JAVAC_NAME with locals? depends on potential reuse |
| 3118 | javaCommandLineHeader = cmdLineHeader.toString(); |
| 3119 | cmdLineHeader = new StringBuffer(jdkRootDirPath. |
| 3120 | append("bin").append(JAVAC_NAME).toString()); |
| 3121 | cmdLineHeader.append(" -classpath . "); |
| 3122 | // start with the current directory which contains the source files |
| 3123 | Process compileProcess = Runtime.getRuntime().exec( |
| 3124 | cmdLineHeader.toString() + " -version", null, null); |
| 3125 | Logger versionLogger = new Logger(compileProcess.getErrorStream(), ""); |
| 3126 | // PREMATURE implement consistent error policy |
| 3127 | versionLogger.start(); |
| 3128 | compileProcess.waitFor(); |
| 3129 | versionLogger.join(); // make sure we get the whole output |
| 3130 | String version = versionLogger.buffer.toString(); |
| 3131 | int eol = version.indexOf('\n'); |
| 3132 | version = version.substring(0, eol); |
| 3133 | cmdLineHeader.append(" -d "); |
| 3134 | cmdLineHeader.append(JAVAC_OUTPUT_DIR_NAME.indexOf(" ") != -1 ? "\"" + JAVAC_OUTPUT_DIR_NAME + "\"" : JAVAC_OUTPUT_DIR_NAME); |
Stephan Herrmann | ae70795 | 2015-10-30 22:28:02 +0100 | [diff] [blame^] | 3135 | cmdLineHeader.append(" -source 1.5 -deprecation -Xlint "); // enable recommended warnings |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 3136 | // WORK new javac system does not do that... reconsider |
| 3137 | // REVIEW consider enabling all warnings instead? Philippe does not see |
| 3138 | // this as ez to use (too many changes in logs) |
| 3139 | javacCommandLineHeader = cmdLineHeader.toString(); |
| 3140 | new File(Util.getOutputDirectory()).mkdirs(); |
| 3141 | // TODO maxime check why this happens to miss in some cases |
| 3142 | // WORK if we keep a full log, it should not mix javac versions... |
| 3143 | javacFullLogFileName = Util.getOutputDirectory() + File.separatorChar + |
| 3144 | version.replace(' ', '_') + "_" + |
| 3145 | (new SimpleDateFormat("yyyyMMdd_HHmmss")).format(new Date()) + |
| 3146 | ".txt"; |
| 3147 | javacFullLog = |
| 3148 | new PrintWriter(new FileOutputStream(javacFullLogFileName)); // static that is initialized once, closed at process end |
| 3149 | javacFullLog.println(version); // so that the contents is self sufficient |
| 3150 | System.out.println("***************************************************************************"); |
| 3151 | System.out.println("* Sun Javac compiler output archived into file:"); |
| 3152 | System.out.println("* " + javacFullLogFileName); |
| 3153 | System.out.println("***************************************************************************"); |
| 3154 | javacCompilers = new ArrayList(); |
| 3155 | String jdkRoots = System.getProperty("jdk.roots"); |
| 3156 | if (jdkRoots == null) { |
| 3157 | javacCompilers.add(new JavacCompiler(jdkRootDirPath.toString())); |
| 3158 | } else { |
| 3159 | StringTokenizer tokenizer = new StringTokenizer(jdkRoots, File.pathSeparator); |
| 3160 | while (tokenizer.hasMoreTokens()) { |
| 3161 | javacCompilers.add(new JavacCompiler(tokenizer.nextToken())); |
| 3162 | } |
| 3163 | } |
| 3164 | } |
| 3165 | // per class initialization |
| 3166 | CURRENT_CLASS_NAME = getClass().getName(); |
| 3167 | dualPrintln("***************************************************************************"); |
| 3168 | System.out.print("* Comparison with Sun Javac compiler for class "); |
| 3169 | dualPrintln(CURRENT_CLASS_NAME.substring(CURRENT_CLASS_NAME.lastIndexOf('.')+1) + |
| 3170 | " (" + TESTS_COUNTERS.get(CURRENT_CLASS_NAME) + " tests)"); |
| 3171 | System.out.println("***************************************************************************"); |
| 3172 | DIFF_COUNTERS[0] = 0; |
| 3173 | DIFF_COUNTERS[1] = 0; |
| 3174 | DIFF_COUNTERS[2] = 0; |
| 3175 | } |
| 3176 | } |
| 3177 | } |
| 3178 | |
| 3179 | public void stop() { |
| 3180 | this.verifier.shutDown(); |
| 3181 | } |
| 3182 | |
| 3183 | protected void tearDown() throws Exception { |
| 3184 | if (this.createdVerifier) { |
| 3185 | stop(); |
| 3186 | } |
| 3187 | // clean up output dir |
| 3188 | File outputDir = new File(OUTPUT_DIR); |
| 3189 | if (outputDir.exists()) { |
| 3190 | Util.flushDirectoryContent(outputDir); |
| 3191 | } |
| 3192 | super.tearDown(); |
| 3193 | if (RUN_JAVAC) { |
| 3194 | if (JAVAC_OUTPUT_DIR.exists()) { |
| 3195 | Util.flushDirectoryContent(JAVAC_OUTPUT_DIR); |
| 3196 | } |
| 3197 | printJavacResultsSummary(); |
| 3198 | } |
| 3199 | } |
Stephan Herrmann | 71432c0 | 2011-10-25 16:30:36 +0000 | [diff] [blame] | 3200 | /** |
| 3201 | * Returns the OS path to the directory that contains this plugin. |
| 3202 | */ |
| 3203 | protected String getCompilerTestsPluginDirectoryPath() { |
| 3204 | try { |
| 3205 | URL platformURL = Platform.getBundle("org.eclipse.jdt.core.tests.compiler").getEntry("/"); |
| 3206 | return new File(FileLocator.toFileURL(platformURL).getFile()).getAbsolutePath(); |
| 3207 | } catch (IOException e) { |
| 3208 | e.printStackTrace(); |
| 3209 | } |
| 3210 | return null; |
| 3211 | } |
Stephan Herrmann | 5ed21e4 | 2010-04-01 21:40:57 +0000 | [diff] [blame] | 3212 | } |