|
Lines 12-19
Link Here
|
| 12 |
|
12 |
|
| 13 |
package org.eclipse.jdt.compiler.apt.tests; |
13 |
package org.eclipse.jdt.compiler.apt.tests; |
| 14 |
|
14 |
|
|
|
15 |
import java.io.ByteArrayOutputStream; |
| 15 |
import java.io.File; |
16 |
import java.io.File; |
| 16 |
import java.io.IOException; |
17 |
import java.io.IOException; |
|
|
18 |
import java.io.PrintWriter; |
| 17 |
import java.util.ArrayList; |
19 |
import java.util.ArrayList; |
| 18 |
import java.util.Collection; |
20 |
import java.util.Collection; |
| 19 |
import java.util.Collections; |
21 |
import java.util.Collections; |
|
Lines 21-27
Link Here
|
| 21 |
import java.util.Set; |
23 |
import java.util.Set; |
| 22 |
|
24 |
|
| 23 |
import javax.lang.model.SourceVersion; |
25 |
import javax.lang.model.SourceVersion; |
|
|
26 |
import javax.tools.Diagnostic; |
| 27 |
import javax.tools.DiagnosticListener; |
| 24 |
import javax.tools.JavaCompiler; |
28 |
import javax.tools.JavaCompiler; |
|
|
29 |
import javax.tools.JavaFileObject; |
| 25 |
import javax.tools.ToolProvider; |
30 |
import javax.tools.ToolProvider; |
| 26 |
|
31 |
|
| 27 |
import junit.framework.TestCase; |
32 |
import junit.framework.TestCase; |
|
Lines 29-36
Link Here
|
| 29 |
/** |
34 |
/** |
| 30 |
* Test cases for annotation processing behavior when code contains semantic errors |
35 |
* Test cases for annotation processing behavior when code contains semantic errors |
| 31 |
*/ |
36 |
*/ |
| 32 |
public class NegativeTests extends TestCase |
37 |
public class NegativeTests extends TestCase { |
| 33 |
{ |
38 |
static class TestDiagnosticListener implements DiagnosticListener<JavaFileObject> { |
|
|
39 |
public static final int NONE = 0; |
| 40 |
public static final int ERROR = 1; |
| 41 |
public static final int INFO = 2; |
| 42 |
public static final int WARNING = 4; |
| 43 |
|
| 44 |
private PrintWriter err; |
| 45 |
public int errorCounter; |
| 46 |
|
| 47 |
public TestDiagnosticListener(PrintWriter err) { |
| 48 |
this.err = err; |
| 49 |
} |
| 50 |
@Override |
| 51 |
public void report(Diagnostic<? extends JavaFileObject> diagnostic) { |
| 52 |
err.println(diagnostic); |
| 53 |
switch(diagnostic.getKind()) { |
| 54 |
case ERROR : |
| 55 |
this.errorCounter++; |
| 56 |
break; |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 34 |
// See corresponding usages in the NegativeModelProc class |
61 |
// See corresponding usages in the NegativeModelProc class |
| 35 |
private static final String NEGATIVEMODELPROCNAME = "org.eclipse.jdt.compiler.apt.tests.processors.negative.NegativeModelProc"; |
62 |
private static final String NEGATIVEMODELPROCNAME = "org.eclipse.jdt.compiler.apt.tests.processors.negative.NegativeModelProc"; |
| 36 |
private static final String IGNOREJAVACBUGS = "ignoreJavacBugs"; |
63 |
private static final String IGNOREJAVACBUGS = "ignoreJavacBugs"; |
|
Lines 149-154
Link Here
|
| 149 |
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler(); |
176 |
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler(); |
| 150 |
internalTestNegativeModel(compiler, 9, null); |
177 |
internalTestNegativeModel(compiler, 9, null); |
| 151 |
} |
178 |
} |
|
|
179 |
|
| 180 |
/* |
| 181 |
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=328575 |
| 182 |
*/ |
| 183 |
public void testNegativeModel10WithEclipseCompiler() throws IOException { |
| 184 |
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler(); |
| 185 |
System.clearProperty(NEGATIVEMODELPROCNAME); |
| 186 |
File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "inherited"); |
| 187 |
BatchTestUtils.copyResources("targets/inherited", targetFolder); |
| 188 |
|
| 189 |
// Turn on the NegativeModelProc - without this, it will just return without doing anything |
| 190 |
List<String> options = new ArrayList<String>(); |
| 191 |
|
| 192 |
// Invoke processing by compiling the targets.model resources |
| 193 |
ByteArrayOutputStream errBuffer = new ByteArrayOutputStream(); |
| 194 |
PrintWriter printWriter = new PrintWriter(errBuffer); |
| 195 |
TestDiagnosticListener diagnosticListener = new TestDiagnosticListener(printWriter); |
| 196 |
boolean success = BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, diagnosticListener); |
| 197 |
|
| 198 |
assertTrue("Compilation should have failed due to expected errors, but it didn't", !success); |
| 199 |
assertEquals("Two errors should be reported", 2, diagnosticListener.errorCounter); |
| 200 |
} |
| 201 |
|
| 152 |
/** |
202 |
/** |
| 153 |
* Attempt to report errors on various elements. |
203 |
* Attempt to report errors on various elements. |
| 154 |
* @throws IOException |
204 |
* @throws IOException |
|
Lines 168-174
Link Here
|
| 168 |
boolean success = BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, null); |
218 |
boolean success = BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, null); |
| 169 |
|
219 |
|
| 170 |
assertTrue("Compilation should have failed due to expected errors, but it didn't", !success); |
220 |
assertTrue("Compilation should have failed due to expected errors, but it didn't", !success); |
| 171 |
|
|
|
| 172 |
// If it succeeded, the processor will have set this property to "succeeded"; |
221 |
// If it succeeded, the processor will have set this property to "succeeded"; |
| 173 |
// if not, it will set it to an error value. |
222 |
// if not, it will set it to an error value. |
| 174 |
String property = System.getProperty(NEGATIVEMODELPROCNAME); |
223 |
String property = System.getProperty(NEGATIVEMODELPROCNAME); |