提交 c5d977ba 编写于 作者: S Skylot

test: always use runtime compiler for build dex (#536)

上级 b5344f45
......@@ -311,21 +311,13 @@ public abstract class IntegrationTest extends TestUtils {
}
public File getJarForClass(Class<?> cls) throws IOException {
String path = cls.getPackage().getName().replace('.', '/');
List<File> list;
if (!withDebugInfo) {
list = compileClass(cls);
} else {
list = getClassFilesWithInners(cls);
if (list.isEmpty()) {
list = compileClass(cls);
}
}
assertThat("File list is empty", list, not(empty()));
List<File> files = compileClass(cls);
assertThat("File list is empty", files, not(empty()));
String path = cls.getPackage().getName().replace('.', '/');
File temp = createTempFile(".jar");
try (JarOutputStream jo = new JarOutputStream(new FileOutputStream(temp))) {
for (File file : list) {
for (File file : files) {
addFileToJar(jo, file, path + '/' + file.getName());
}
}
......@@ -382,27 +374,29 @@ public abstract class IntegrationTest extends TestUtils {
}
private List<File> compileClass(Class<?> cls) throws IOException {
String fileName = cls.getName();
int end = fileName.indexOf('$');
String clsFullName = cls.getName();
String rootClsName;
int end = clsFullName.indexOf('$');
if (end != -1) {
fileName = fileName.substring(0, end);
rootClsName = clsFullName.substring(0, end);
} else {
rootClsName = clsFullName;
}
fileName = fileName.replace('.', '/') + ".java";
File file = new File(TEST_DIRECTORY, fileName);
String javaFileName = rootClsName.replace('.', '/') + ".java";
File file = new File(TEST_DIRECTORY, javaFileName);
if (!file.exists()) {
file = new File(TEST_DIRECTORY2, fileName);
file = new File(TEST_DIRECTORY2, javaFileName);
}
assertThat("Test source file not found: " + fileName, file.exists(), is(true));
assertThat("Test source file not found: " + javaFileName, file.exists(), is(true));
List<File> compileFileList = Collections.singletonList(file);
File outTmp = createTempDir("jadx-tmp-classes");
outTmp.deleteOnExit();
List<File> files = StaticCompiler.compile(compileFileList, outTmp, withDebugInfo);
files.forEach(File::deleteOnExit);
// remove classes which are parents for test class
files.removeIf(next -> !next.getName().contains(cls.getSimpleName()));
for (File clsFile : files) {
clsFile.deleteOnExit();
}
String clsName = clsFullName.substring(clsFullName.lastIndexOf('.') + 1);
files.removeIf(next -> !next.getName().contains(clsName));
return files;
}
......
......@@ -11,29 +11,29 @@ import static org.hamcrest.MatcherAssert.assertThat;
public class TestImportGenericMap extends IntegrationTest {
@Test
public void test() {
ClassNode cls = getClassNode(SuperClass.class);
String code = cls.getCode().toString();
public static class SuperClass<O extends SuperClass.ToImport> {
assertThat(code, containsString(
"import " + SuperClass.ToImport.class.getName().replace('$', '.') + ';'));
assertThat(code, not(containsString(
"import " + SuperClass.NotToImport.class.getName().replace('$', '.') + ';')));
}
}
interface ToImport {
}
final class SuperClass<O extends SuperClass.ToImport> {
interface NotToImport {
}
interface ToImport {
}
static final class Class1<C extends NotToImport> {
}
interface NotToImport {
public <C extends NotToImport> SuperClass(Class1<C> zzf) {
}
}
static final class Class1<C extends NotToImport> {
}
@Test
public void test() {
ClassNode cls = getClassNode(SuperClass.class);
String code = cls.getCode().toString();
public <C extends NotToImport> SuperClass(Class1<C> zzf) {
assertThat(code, containsString(
"import " + SuperClass.ToImport.class.getName().replace("$ToImport", ".ToImport") + ';'));
assertThat(code, not(containsString(
"import " + SuperClass.NotToImport.class.getName().replace("NotToImport", ".NotToImport") + ';')));
}
}
......@@ -13,7 +13,6 @@ import static org.hamcrest.Matchers.not;
public class TestInner2Samples extends IntegrationTest {
public static class TestInner2 {
private String a;
public class A {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册