Thu, 10 Oct 2013 14:58:04 +0200
8001931: The new build system whitespace cleanup
Reviewed-by: tbell, simonis, erikj
2 /*
3 * @test /nodynamiccopyright/
4 * @bug 7144981
5 * @summary javac should ignore ignorable characters in input
6 * @run main IgnoreIgnorableCharactersInInput
7 */
9 import com.sun.source.util.JavacTask;
10 import java.io.File;
11 import java.net.URI;
12 import java.util.Arrays;
13 import java.util.Set;
14 import java.util.TreeSet;
15 import javax.tools.JavaCompiler;
16 import javax.tools.JavaFileObject;
17 import javax.tools.SimpleJavaFileObject;
18 import javax.tools.ToolProvider;
20 public class IgnoreIgnorableCharactersInInput {
22 public static void main(String... args) throws Exception {
23 new IgnoreIgnorableCharactersInInput().run();
24 }
26 void run() throws Exception {
27 JavaCompiler comp = ToolProvider.getSystemJavaCompiler();
28 File classesDir = new File(System.getProperty("user.dir"), "classes");
29 classesDir.mkdirs();
30 JavaSource[] sources = new JavaSource[]{
31 new JavaSource("TestOneIgnorableChar", "AA\\u0000BB"),
32 new JavaSource("TestMultipleIgnorableChar", "AA\\u0000\\u0000\\u0000BB")};
33 JavacTask ct = (JavacTask)comp.getTask(null, null, null,
34 Arrays.asList("-d", classesDir.getPath()),
35 null, Arrays.asList(sources));
36 try {
37 if (!ct.call()) {
38 throw new AssertionError("Error thrown when compiling test cases");
39 }
40 } catch (Throwable ex) {
41 throw new AssertionError("Error thrown when compiling test cases");
42 }
43 check(classesDir,
44 "TestOneIgnorableChar.class",
45 "TestOneIgnorableChar$AABB.class",
46 "TestMultipleIgnorableChar.class",
47 "TestMultipleIgnorableChar$AABB.class");
48 if (errors > 0)
49 throw new AssertionError("There are some errors in the test check the error output");
50 }
52 /**
53 * Check that a directory contains the expected files.
54 */
55 void check(File dir, String... paths) {
56 Set<String> found = new TreeSet<String>(Arrays.asList(dir.list()));
57 Set<String> expect = new TreeSet<String>(Arrays.asList(paths));
58 if (found.equals(expect))
59 return;
60 for (String f: found) {
61 if (!expect.contains(f))
62 error("Unexpected file found: " + f);
63 }
64 for (String e: expect) {
65 if (!found.contains(e))
66 error("Expected file not found: " + e);
67 }
68 }
70 int errors;
72 void error(String msg) {
73 System.err.println(msg);
74 errors++;
75 }
77 class JavaSource extends SimpleJavaFileObject {
79 String internalSource =
80 "public class #O {public class #I {} }";
81 public JavaSource(String outerClassName, String innerClassName) {
82 super(URI.create(outerClassName + ".java"), JavaFileObject.Kind.SOURCE);
83 internalSource =
84 internalSource.replace("#O", outerClassName).replace("#I", innerClassName);
85 }
87 @Override
88 public CharSequence getCharContent(boolean ignoreEncodingErrors) {
89 return internalSource;
90 }
91 }
92 }