mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-20 19:14:38 +02:00
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:
parent
96f1486b0a
commit
b403bd3715
4 changed files with 27 additions and 7 deletions
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
import com.sun.tools.classfile.*;
|
import com.sun.tools.classfile.*;
|
||||||
|
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -62,6 +63,7 @@ public class LineNumberTestBase extends TestBase {
|
||||||
boolean failed = false;
|
boolean failed = false;
|
||||||
for (TestCase testCase : testCases) {
|
for (TestCase testCase : testCases) {
|
||||||
try {
|
try {
|
||||||
|
writeToFileIfEnabled(Paths.get(testCase.getName() + ".java"), testCase.src);
|
||||||
Set<Integer> coveredLines = new HashSet<>();
|
Set<Integer> coveredLines = new HashSet<>();
|
||||||
for (JavaFileObject file : compile(testCase.src).getClasses().values()) {
|
for (JavaFileObject file : compile(testCase.src).getClasses().values()) {
|
||||||
ClassFile classFile = ClassFile.read(file.openInputStream());
|
ClassFile classFile = ClassFile.read(file.openInputStream());
|
||||||
|
|
|
@ -218,7 +218,7 @@ public abstract class AnnotationsTestBase extends TestResult {
|
||||||
String source = testCase.generateSource();
|
String source = testCase.generateSource();
|
||||||
Path sourceFile = Paths.get(getClass().getSimpleName() + i + ".java");
|
Path sourceFile = Paths.get(getClass().getSimpleName() + i + ".java");
|
||||||
addTestCase(sourceFile.toAbsolutePath().toString());
|
addTestCase(sourceFile.toAbsolutePath().toString());
|
||||||
writeToFile(sourceFile, source);
|
writeToFileIfEnabled(sourceFile, source);
|
||||||
echo("Testing: " + sourceFile.toString());
|
echo("Testing: " + sourceFile.toString());
|
||||||
try {
|
try {
|
||||||
test(testCase, compile(source).getClasses());
|
test(testCase, compile(source).getClasses());
|
||||||
|
|
|
@ -26,8 +26,10 @@ import com.sun.tools.classfile.ClassFile;
|
||||||
import com.sun.tools.classfile.InnerClasses_attribute;
|
import com.sun.tools.classfile.InnerClasses_attribute;
|
||||||
import com.sun.tools.classfile.InnerClasses_attribute.Info;
|
import com.sun.tools.classfile.InnerClasses_attribute.Info;
|
||||||
|
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -87,8 +89,13 @@ public abstract class InnerClassesTestBase extends TestResult {
|
||||||
*/
|
*/
|
||||||
public void test(String classToTest, String...skipClasses) throws TestFailedException {
|
public void test(String classToTest, String...skipClasses) throws TestFailedException {
|
||||||
try {
|
try {
|
||||||
for (TestCase test : generateTestCases()) {
|
String testName = getClass().getName();
|
||||||
addTestCase(test.getSource());
|
List<TestCase> testCases = generateTestCases();
|
||||||
|
for (int i = 0; i < testCases.size(); ++i) {
|
||||||
|
TestCase test = testCases.get(i);
|
||||||
|
String testCaseName = testName + i + ".java";
|
||||||
|
addTestCase(testCaseName);
|
||||||
|
writeToFileIfEnabled(Paths.get(testCaseName), test.getSource());
|
||||||
test(classToTest, test, skipClasses);
|
test(classToTest, test, skipClasses);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -330,7 +337,7 @@ public abstract class InnerClassesTestBase extends TestResult {
|
||||||
list.add(Arrays.asList(access, mod1, mod2));
|
list.add(Arrays.asList(access, mod1, mod2));
|
||||||
}
|
}
|
||||||
if (mod1 == Modifier.EMPTY) {
|
if (mod1 == Modifier.EMPTY) {
|
||||||
list.add(Arrays.asList(access));
|
list.add(Collections.singletonList(access));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -413,7 +420,7 @@ public abstract class InnerClassesTestBase extends TestResult {
|
||||||
|
|
||||||
private final String classType;
|
private final String classType;
|
||||||
|
|
||||||
private ClassType(String clazz) {
|
ClassType(String clazz) {
|
||||||
this.classType = clazz;
|
this.classType = clazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,7 +442,7 @@ public abstract class InnerClassesTestBase extends TestResult {
|
||||||
|
|
||||||
private final String str;
|
private final String str;
|
||||||
|
|
||||||
private Modifier(String str) {
|
Modifier(String str) {
|
||||||
this.str = str;
|
this.str = str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,7 @@ import com.sun.tools.classfile.ConstantPoolException;
|
||||||
public class TestBase {
|
public class TestBase {
|
||||||
|
|
||||||
public static final String LINE_SEPARATOR = System.lineSeparator();
|
public static final String LINE_SEPARATOR = System.lineSeparator();
|
||||||
|
public static final boolean isDumpOfSourceEnabled = Boolean.getBoolean("dump.src");
|
||||||
|
|
||||||
private <S> InMemoryFileManager compile(
|
private <S> InMemoryFileManager compile(
|
||||||
List<String> options,
|
List<String> options,
|
||||||
|
@ -176,7 +177,9 @@ public class TestBase {
|
||||||
* @throws ConstantPoolException if constant pool error occurs
|
* @throws ConstantPoolException if constant pool error occurs
|
||||||
*/
|
*/
|
||||||
public ClassFile readClassFile(File file) throws IOException, ConstantPoolException {
|
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) {
|
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() {
|
public File getSourceDir() {
|
||||||
return new File(System.getProperty("test.src", "."));
|
return new File(System.getProperty("test.src", "."));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue