Bug 404648 - [1.8][compiler] investigate differences between ECJ & Javac

Change-Id: I9443e4a255eb3b91da41ef68f6dcafddeb8e3de6
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
index 6507032..34ff37a 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
@@ -435,7 +435,10 @@
 		Process executionProcess = null;
 		try {
 			StringBuffer cmdLine = new StringBuffer(this.javaPathName);
-			cmdLine.append(" -classpath . "); // default classpath
+			if (options.contains("-cp "))
+				cmdLine.append(' '); // i.e., -cp will be appended below, just ensure separation from javaPathname
+			else
+				cmdLine.append(" -classpath . "); // default classpath
 			cmdLine.append(options);
 			cmdLine.append(' ');
 			cmdLine.append(className);
@@ -464,6 +467,15 @@
 			return true;
 		}
 	};
+	@java.lang.SuppressWarnings("synthetic-access")
+	static JavacTestOptions forRelease(String release) {
+		JavacTestOptions options = new JavacTestOptions();
+		if (isJRE9Plus)
+			options.setCompilerOptions("-release "+release);
+		else
+			options.setCompilerOptions("-source 1."+release+" -target 1."+release);
+		return options;
+	}
 	public static class SuppressWarnings extends JavacTestOptions {
 		public SuppressWarnings(String token) {
 			setCompilerOptions("-Xlint:-"+token);
@@ -2185,7 +2197,7 @@
 					//      it should have had contents, stderr is leveraged as
 					//      potentially holding indications regarding the failure
 					if (expectedErrorString != null /* null skips error test */ && mismatch == 0) {
-						err = stderr.toString().trim();
+						err = adjustErrorOutput(stderr.toString().trim());
 						if (!expectedErrorString.equals(err) && // special case: command-line java does not like missing main methods
 								!(expectedErrorString.length() == 0 &&
 									(err.indexOf("java.lang.NoSuchMethodError: main") != -1)
@@ -2262,6 +2274,15 @@
 	}
 }
 
+private String adjustErrorOutput(String error) {
+	// VerifyTests performs an explicit e.printStackTrace() which has slightly different format
+	// from a stack trace written directly by a dying JVM (during javac testing), adjust if needed:
+	final String excPrefix = "Exception in thread \"main\" ";
+	if (error.startsWith(excPrefix))
+		return error.substring(excPrefix.length())+'\n';
+	return error;
+}
+
 //runNegativeTest(
 //	// test directory preparation
 //	new String[] { /* test files */
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java
index 5b3e711..497fc2f 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TryWithResourcesStatementTest.java
@@ -513,13 +513,15 @@
 }
 // Resource nullness tests
 public void test015() {
-	this.runNegativeTest(
+	Runner runner = new Runner();
+	runner.testFiles =
 		new String[] {
 			"X.java",
 			"public class X {\n" +
 			"	public static void main(String [] args) {    \n" +
 			"		try (Y y = new Y();) {\n" +
-			"           if (y == null)\n {}\n" +
+			"           if (y == null)\n" +
+			"				{}\n" +
 			"		}\n" +
 			"	}\n" +
 			"} \n" +
@@ -528,13 +530,16 @@
 			"	public void close() {\n" +
 			"	}\n" +
 			"}\n"
-		},
+		};
+	runner.expectedCompilerLog =
 		"----------\n" + 
 		"1. WARNING in X.java (at line 5)\n" + 
 		"	{}\n" + 
 		"	^^\n" + 
 		"Dead code\n" + 
-		"----------\n");
+		"----------\n";
+	runner.javacTestOptions = JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings;
+	runner.runWarningTest();
 }
 // Dead code tests, resource nullness, unhandled exception tests
 public void test016() {
@@ -596,13 +601,15 @@
 }
 // Dead code tests
 public void test017() {
-	this.runNegativeTest(
+	Runner runner = new Runner();
+	runner.testFiles =
 		new String[] {
 			"X.java",
 			"public class X {\n" +
 			"	public static void main(String [] args) {    \n" +
 			"		try (Y y = new Y();) {\n" +
-			"           if (y == null)\n {}\n" +
+			"           if (y == null)\n" +
+			"				{}\n" +
 			"		} finally {\n" +
 			"       }\n" +
 			"	}\n" +
@@ -612,13 +619,16 @@
 			"	public void close() {\n" +
 			"	}\n" +
 			"}\n"
-		},
+		};
+	runner.expectedCompilerLog =
 		"----------\n" + 
 		"1. WARNING in X.java (at line 5)\n" + 
 		"	{}\n" + 
 		"	^^\n" + 
 		"Dead code\n" + 
-		"----------\n");
+		"----------\n";
+	runner.javacTestOptions = JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings;
+	runner.runWarningTest();
 }
 // Syntax error tests
 public void test018() {
@@ -3138,11 +3148,12 @@
 }
 //ensure that it doesn't completely fail when using TWR and 1.5 mode
 public void test049() {
-	Map options = getCompilerOptions();
-	options.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
-	options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
-	options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
-	this.runNegativeTest(
+	Runner runner = new Runner();
+	runner.customOptions = getCompilerOptions();
+	runner.customOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
+	runner.customOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
+	runner.customOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
+	runner.testFiles =
 		new String[] {
 			"X.java",
 			"import java.io.File;\n" +
@@ -3163,16 +3174,16 @@
 			"        new X().foo();\n" +
 			"    }\n" +
 			"}\n"
-		},
+		};
+	runner.expectedCompilerLog =
 		"----------\n" + 
 		"1. ERROR in X.java (at line 7)\n" + 
 		"	try(FileReader fileReader = new FileReader(file);) {\n" + 
 		"	    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" + 
 		"Resource specification not allowed here for source level below 1.7\n" + 
-		"----------\n",
-		null,
-		true,
-		options);
+		"----------\n";
+	runner.javacTestOptions = JavacTestOptions.forRelease("5");
+	runner.runNegativeTest();
 }
 public void test050() {
 	this.runConformTest(
@@ -4192,7 +4203,7 @@
 				"    public static I getX() { return null;}\n"+
 				"    public X(){}\n" +
 				"}\n"
-			}, "Done", libs, true, new String[] {"-cp", path});
+			}, "Done", libs, true, new String[] {"-cp", "."+File.pathSeparator+path});
 }
 //https://bugs.eclipse.org/bugs/show_bug.cgi?id=394780
 public void test394780() {