Commit c5d977ba authored by Skylot's avatar Skylot

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

parent b5344f45
...@@ -311,21 +311,13 @@ public abstract class IntegrationTest extends TestUtils { ...@@ -311,21 +311,13 @@ public abstract class IntegrationTest extends TestUtils {
} }
public File getJarForClass(Class<?> cls) throws IOException { public File getJarForClass(Class<?> cls) throws IOException {
String path = cls.getPackage().getName().replace('.', '/'); List<File> files = compileClass(cls);
List<File> list; assertThat("File list is empty", files, not(empty()));
if (!withDebugInfo) {
list = compileClass(cls);
} else {
list = getClassFilesWithInners(cls);
if (list.isEmpty()) {
list = compileClass(cls);
}
}
assertThat("File list is empty", list, not(empty()));
String path = cls.getPackage().getName().replace('.', '/');
File temp = createTempFile(".jar"); File temp = createTempFile(".jar");
try (JarOutputStream jo = new JarOutputStream(new FileOutputStream(temp))) { try (JarOutputStream jo = new JarOutputStream(new FileOutputStream(temp))) {
for (File file : list) { for (File file : files) {
addFileToJar(jo, file, path + '/' + file.getName()); addFileToJar(jo, file, path + '/' + file.getName());
} }
} }
...@@ -382,27 +374,29 @@ public abstract class IntegrationTest extends TestUtils { ...@@ -382,27 +374,29 @@ public abstract class IntegrationTest extends TestUtils {
} }
private List<File> compileClass(Class<?> cls) throws IOException { private List<File> compileClass(Class<?> cls) throws IOException {
String fileName = cls.getName(); String clsFullName = cls.getName();
int end = fileName.indexOf('$'); String rootClsName;
int end = clsFullName.indexOf('$');
if (end != -1) { if (end != -1) {
fileName = fileName.substring(0, end); rootClsName = clsFullName.substring(0, end);
} else {
rootClsName = clsFullName;
} }
fileName = fileName.replace('.', '/') + ".java"; String javaFileName = rootClsName.replace('.', '/') + ".java";
File file = new File(TEST_DIRECTORY, fileName); File file = new File(TEST_DIRECTORY, javaFileName);
if (!file.exists()) { 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); List<File> compileFileList = Collections.singletonList(file);
File outTmp = createTempDir("jadx-tmp-classes"); File outTmp = createTempDir("jadx-tmp-classes");
outTmp.deleteOnExit(); outTmp.deleteOnExit();
List<File> files = StaticCompiler.compile(compileFileList, outTmp, withDebugInfo); List<File> files = StaticCompiler.compile(compileFileList, outTmp, withDebugInfo);
files.forEach(File::deleteOnExit);
// remove classes which are parents for test class // remove classes which are parents for test class
files.removeIf(next -> !next.getName().contains(cls.getSimpleName())); String clsName = clsFullName.substring(clsFullName.lastIndexOf('.') + 1);
for (File clsFile : files) { files.removeIf(next -> !next.getName().contains(clsName));
clsFile.deleteOnExit();
}
return files; return files;
} }
......
...@@ -11,29 +11,29 @@ import static org.hamcrest.MatcherAssert.assertThat; ...@@ -11,29 +11,29 @@ import static org.hamcrest.MatcherAssert.assertThat;
public class TestImportGenericMap extends IntegrationTest { public class TestImportGenericMap extends IntegrationTest {
@Test public static class SuperClass<O extends SuperClass.ToImport> {
public void test() {
ClassNode cls = getClassNode(SuperClass.class);
String code = cls.getCode().toString();
assertThat(code, containsString( interface ToImport {
"import " + SuperClass.ToImport.class.getName().replace('$', '.') + ';')); }
assertThat(code, not(containsString(
"import " + SuperClass.NotToImport.class.getName().replace('$', '.') + ';')));
}
}
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; ...@@ -13,7 +13,6 @@ import static org.hamcrest.Matchers.not;
public class TestInner2Samples extends IntegrationTest { public class TestInner2Samples extends IntegrationTest {
public static class TestInner2 { public static class TestInner2 {
private String a; private String a;
public class A { public class A {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment