8081472: Add a mode to the tests for class-file attributes which dumps in-memory sources to disk

Reviewed-by: ksrini
This commit is contained in:
Andrei Eremeev 2015-09-28 13:23:35 +03:00
parent 96f1486b0a
commit b403bd3715
4 changed files with 27 additions and 7 deletions

View file

@ -44,6 +44,7 @@ import com.sun.tools.classfile.ConstantPoolException;
public class TestBase {
public static final String LINE_SEPARATOR = System.lineSeparator();
public static final boolean isDumpOfSourceEnabled = Boolean.getBoolean("dump.src");
private <S> InMemoryFileManager compile(
List<String> options,
@ -176,7 +177,9 @@ public class TestBase {
* @throws ConstantPoolException if constant pool error occurs
*/
public ClassFile readClassFile(File file) throws IOException, ConstantPoolException {
return readClassFile(new FileInputStream(file));
try (InputStream is = new FileInputStream(file)) {
return readClassFile(is);
}
}
public void assertEquals(Object actual, Object expected, String message) {
@ -215,6 +218,14 @@ public class TestBase {
}
}
public void writeToFileIfEnabled(Path path, String source) throws IOException {
if (isDumpOfSourceEnabled) {
writeToFile(path, source);
} else {
System.err.println("Source dumping disabled. To enable, run the test with '-Ddump.src=true'");
}
}
public File getSourceDir() {
return new File(System.getProperty("test.src", "."));
}