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 |
public int errorCounter; |
45 |
private PrintWriter writer; |
46 |
|
47 |
public TestDiagnosticListener(PrintWriter writer) { |
48 |
this.writer = writer; |
49 |
} |
50 |
|
51 |
@Override |
52 |
public void report(Diagnostic<? extends JavaFileObject> diagnostic) { |
53 |
switch(diagnostic.getKind()) { |
54 |
case ERROR : |
55 |
this.writer.print(diagnostic.getMessage(null)); |
56 |
this.errorCounter++; |
57 |
break; |
58 |
} |
59 |
} |
60 |
} |
61 |
|
34 |
// See corresponding usages in the NegativeModelProc class |
62 |
// See corresponding usages in the NegativeModelProc class |
35 |
private static final String NEGATIVEMODELPROCNAME = "org.eclipse.jdt.compiler.apt.tests.processors.negative.NegativeModelProc"; |
63 |
private static final String NEGATIVEMODELPROCNAME = "org.eclipse.jdt.compiler.apt.tests.processors.negative.NegativeModelProc"; |
36 |
private static final String IGNOREJAVACBUGS = "ignoreJavacBugs"; |
64 |
private static final String IGNOREJAVACBUGS = "ignoreJavacBugs"; |
Lines 149-154
Link Here
|
149 |
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler(); |
177 |
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler(); |
150 |
internalTestNegativeModel(compiler, 9, null); |
178 |
internalTestNegativeModel(compiler, 9, null); |
151 |
} |
179 |
} |
|
|
180 |
|
181 |
/* |
182 |
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=328575 |
183 |
*/ |
184 |
public void testNegativeModel10WithEclipseCompiler() throws IOException { |
185 |
JavaCompiler compiler = BatchTestUtils.getEclipseCompiler(); |
186 |
System.clearProperty(NEGATIVEMODELPROCNAME); |
187 |
File targetFolder = TestUtils.concatPath(BatchTestUtils.getSrcFolderName(), "targets", "inherited"); |
188 |
BatchTestUtils.copyResources("targets/inherited", targetFolder); |
189 |
|
190 |
// Invoke processing by compiling the targets.model resources |
191 |
ByteArrayOutputStream errBuffer = new ByteArrayOutputStream(); |
192 |
PrintWriter printWriter = new PrintWriter(errBuffer); |
193 |
TestDiagnosticListener diagnosticListener = new TestDiagnosticListener(printWriter); |
194 |
boolean success = BatchTestUtils.compileTreeWithErrors(compiler, new ArrayList<String>(), targetFolder, diagnosticListener); |
195 |
|
196 |
assertTrue("Compilation should have failed due to expected errors, but it didn't", !success); |
197 |
assertEquals("Two errors should be reported", 2, diagnosticListener.errorCounter); |
198 |
printWriter.flush(); |
199 |
printWriter.close(); |
200 |
String expectedErrors = |
201 |
"Class targets.inherited.TestGenericChild lacks a public constructor with args: java.awt.Point" + |
202 |
"Class targets.inherited.TestNormalChild lacks a public constructor with args: java.awt.Point"; |
203 |
|
204 |
assertEquals("Wrong output", expectedErrors, String.valueOf(errBuffer)); |
205 |
} |
206 |
|
152 |
/** |
207 |
/** |
153 |
* Attempt to report errors on various elements. |
208 |
* Attempt to report errors on various elements. |
154 |
* @throws IOException |
209 |
* @throws IOException |
Lines 168-174
Link Here
|
168 |
boolean success = BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, null); |
223 |
boolean success = BatchTestUtils.compileTreeWithErrors(compiler, options, targetFolder, null); |
169 |
|
224 |
|
170 |
assertTrue("Compilation should have failed due to expected errors, but it didn't", !success); |
225 |
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"; |
226 |
// If it succeeded, the processor will have set this property to "succeeded"; |
173 |
// if not, it will set it to an error value. |
227 |
// if not, it will set it to an error value. |
174 |
String property = System.getProperty(NEGATIVEMODELPROCNAME); |
228 |
String property = System.getProperty(NEGATIVEMODELPROCNAME); |