113 } 114 115 /* 116 * Check line terminator translation 117 */ 118 static void test4() { 119 String[] terminators = new String[] { "\n", "\r\n", "\r" }; 120 for (String terminator : terminators) { 121 String code = "public class LineTerminatorTest {" + terminator + 122 " public static void main(String... args) {" + terminator + 123 " String s =" + terminator + 124 "`" + terminator + 125 "abc" + terminator + 126 "`;" + terminator + 127 " System.out.println(s.equals(\"\\nabc\\n\"));" + terminator + 128 " }" + terminator + 129 "}" + terminator; 130 new JavacTask(TOOLBOX) 131 .sources(code) 132 .classpath(".") 133 .options("--enable-preview", "-source", "12") 134 .run(); 135 String output = new JavaTask(TOOLBOX) 136 .vmOptions("--enable-preview") 137 .classpath(".") 138 .classArgs("LineTerminatorTest") 139 .run() 140 .writeAll() 141 .getOutput(Task.OutputKind.STDOUT); 142 143 if (!output.contains("true")) { 144 throw new RuntimeException("Error detected"); 145 } 146 } 147 } 148 149 /* 150 * Test source for successful compile. 151 */ 152 static void compPass(String source) { 153 String output = new JavacTask(TOOLBOX) 154 .sources(source) 155 .classpath(".") 156 .options("--enable-preview", "-source", "12", "-encoding", "utf8") 157 .run() 158 .writeAll() 159 .getOutput(Task.OutputKind.DIRECT); 160 161 if (output.contains("compiler.err")) { 162 throw new RuntimeException("Error detected"); 163 } 164 } 165 166 /* 167 * Test source for unsuccessful compile and specific error. 168 */ 169 static void compFail(String source) { 170 String errors = new JavacTask(TOOLBOX) 171 .sources(source) 172 .classpath(".") 173 .options("-XDrawDiagnostics", "--enable-preview", "-source", "12", "-encoding", "utf8") 174 .run(Task.Expect.FAIL) 175 .writeAll() 176 .getOutput(Task.OutputKind.DIRECT); 177 178 if (!errors.contains("compiler.err")) { 179 throw new RuntimeException("No error detected"); 180 } 181 } 182 } | 113 } 114 115 /* 116 * Check line terminator translation 117 */ 118 static void test4() { 119 String[] terminators = new String[] { "\n", "\r\n", "\r" }; 120 for (String terminator : terminators) { 121 String code = "public class LineTerminatorTest {" + terminator + 122 " public static void main(String... args) {" + terminator + 123 " String s =" + terminator + 124 "`" + terminator + 125 "abc" + terminator + 126 "`;" + terminator + 127 " System.out.println(s.equals(\"\\nabc\\n\"));" + terminator + 128 " }" + terminator + 129 "}" + terminator; 130 new JavacTask(TOOLBOX) 131 .sources(code) 132 .classpath(".") 133 .options("--enable-preview", "-source", "13") 134 .run(); 135 String output = new JavaTask(TOOLBOX) 136 .vmOptions("--enable-preview") 137 .classpath(".") 138 .classArgs("LineTerminatorTest") 139 .run() 140 .writeAll() 141 .getOutput(Task.OutputKind.STDOUT); 142 143 if (!output.contains("true")) { 144 throw new RuntimeException("Error detected"); 145 } 146 } 147 } 148 149 /* 150 * Test source for successful compile. 151 */ 152 static void compPass(String source) { 153 String output = new JavacTask(TOOLBOX) 154 .sources(source) 155 .classpath(".") 156 .options("--enable-preview", "-source", "13", "-encoding", "utf8") 157 .run() 158 .writeAll() 159 .getOutput(Task.OutputKind.DIRECT); 160 161 if (output.contains("compiler.err")) { 162 throw new RuntimeException("Error detected"); 163 } 164 } 165 166 /* 167 * Test source for unsuccessful compile and specific error. 168 */ 169 static void compFail(String source) { 170 String errors = new JavacTask(TOOLBOX) 171 .sources(source) 172 .classpath(".") 173 .options("-XDrawDiagnostics", "--enable-preview", "-source", "13", "-encoding", "utf8") 174 .run(Task.Expect.FAIL) 175 .writeAll() 176 .getOutput(Task.OutputKind.DIRECT); 177 178 if (!errors.contains("compiler.err")) { 179 throw new RuntimeException("No error detected"); 180 } 181 } 182 } |