equal
deleted
inserted
replaced
42 * for reading files from disk and a lot of assert* methods. |
42 * for reading files from disk and a lot of assert* methods. |
43 */ |
43 */ |
44 public class TestBase { |
44 public class TestBase { |
45 |
45 |
46 public static final String LINE_SEPARATOR = System.lineSeparator(); |
46 public static final String LINE_SEPARATOR = System.lineSeparator(); |
|
47 public static final boolean isDumpOfSourceEnabled = Boolean.getBoolean("dump.src"); |
47 |
48 |
48 private <S> InMemoryFileManager compile( |
49 private <S> InMemoryFileManager compile( |
49 List<String> options, |
50 List<String> options, |
50 Function<S, ? extends JavaFileObject> src2JavaFileObject, |
51 Function<S, ? extends JavaFileObject> src2JavaFileObject, |
51 List<S> sources) |
52 List<S> sources) |
174 * @return class file that is read from {@code file} |
175 * @return class file that is read from {@code file} |
175 * @throws IOException if I/O error occurs |
176 * @throws IOException if I/O error occurs |
176 * @throws ConstantPoolException if constant pool error occurs |
177 * @throws ConstantPoolException if constant pool error occurs |
177 */ |
178 */ |
178 public ClassFile readClassFile(File file) throws IOException, ConstantPoolException { |
179 public ClassFile readClassFile(File file) throws IOException, ConstantPoolException { |
179 return readClassFile(new FileInputStream(file)); |
180 try (InputStream is = new FileInputStream(file)) { |
|
181 return readClassFile(is); |
|
182 } |
180 } |
183 } |
181 |
184 |
182 public void assertEquals(Object actual, Object expected, String message) { |
185 public void assertEquals(Object actual, Object expected, String message) { |
183 if (!Objects.equals(actual, expected)) |
186 if (!Objects.equals(actual, expected)) |
184 throw new AssertionFailedException(String.format("%s%nGot: %s, Expected: %s", |
187 throw new AssertionFailedException(String.format("%s%nGot: %s, Expected: %s", |
213 try (BufferedWriter writer = Files.newBufferedWriter(path)) { |
216 try (BufferedWriter writer = Files.newBufferedWriter(path)) { |
214 writer.write(source); |
217 writer.write(source); |
215 } |
218 } |
216 } |
219 } |
217 |
220 |
|
221 public void writeToFileIfEnabled(Path path, String source) throws IOException { |
|
222 if (isDumpOfSourceEnabled) { |
|
223 writeToFile(path, source); |
|
224 } else { |
|
225 System.err.println("Source dumping disabled. To enable, run the test with '-Ddump.src=true'"); |
|
226 } |
|
227 } |
|
228 |
218 public File getSourceDir() { |
229 public File getSourceDir() { |
219 return new File(System.getProperty("test.src", ".")); |
230 return new File(System.getProperty("test.src", ".")); |
220 } |
231 } |
221 |
232 |
222 public File getClassDir() { |
233 public File getClassDir() { |