Test stdlib with dx
#KT-7003 Fixed
This commit is contained in:
@@ -21,6 +21,7 @@ import com.android.dx.cf.direct.StdAttributeFactory;
|
|||||||
import com.android.dx.command.dexer.Main;
|
import com.android.dx.command.dexer.Main;
|
||||||
import com.android.dx.dex.cf.CfTranslator;
|
import com.android.dx.dex.cf.CfTranslator;
|
||||||
import com.android.dx.dex.file.DexFile;
|
import com.android.dx.dex.file.DexFile;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.kotlin.backend.common.output.OutputFile;
|
import org.jetbrains.kotlin.backend.common.output.OutputFile;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
@@ -46,15 +47,7 @@ public class DxChecker {
|
|||||||
for (OutputFile file : outputFiles.asList()) {
|
for (OutputFile file : outputFiles.asList()) {
|
||||||
try {
|
try {
|
||||||
byte[] bytes = file.asByteArray();
|
byte[] bytes = file.asByteArray();
|
||||||
DirectClassFile cf = new DirectClassFile(bytes, file.getRelativePath(), true);
|
checkFileWithDx(bytes, file.getRelativePath(), arguments);
|
||||||
cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
|
|
||||||
CfTranslator.translate(
|
|
||||||
cf,
|
|
||||||
bytes,
|
|
||||||
arguments.cfOptions,
|
|
||||||
arguments.dexOptions,
|
|
||||||
new DexFile(arguments.dexOptions)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
catch (Throwable e) {
|
catch (Throwable e) {
|
||||||
Assert.fail(generateExceptionMessage(e));
|
Assert.fail(generateExceptionMessage(e));
|
||||||
@@ -62,6 +55,26 @@ public class DxChecker {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void checkFileWithDx(byte[] bytes, @NotNull String relativePath) {
|
||||||
|
Main.Arguments arguments = new Main.Arguments();
|
||||||
|
String[] array = new String[1];
|
||||||
|
array[0] = "testArgs";
|
||||||
|
arguments.parse(array);
|
||||||
|
checkFileWithDx(bytes, relativePath, arguments);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void checkFileWithDx(byte[] bytes, @NotNull String relativePath, @NotNull Main.Arguments arguments) {
|
||||||
|
DirectClassFile cf = new DirectClassFile(bytes, relativePath, true);
|
||||||
|
cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
|
||||||
|
CfTranslator.translate(
|
||||||
|
cf,
|
||||||
|
bytes,
|
||||||
|
arguments.cfOptions,
|
||||||
|
arguments.dexOptions,
|
||||||
|
new DexFile(arguments.dexOptions)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private static String generateExceptionMessage(Throwable e) {
|
private static String generateExceptionMessage(Throwable e) {
|
||||||
StringWriter writer = new StringWriter();
|
StringWriter writer = new StringWriter();
|
||||||
PrintWriter printWriter = new PrintWriter(writer);
|
PrintWriter printWriter = new PrintWriter(writer);
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.codegen
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
||||||
|
import org.junit.Test
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileInputStream
|
||||||
|
import java.util.zip.ZipInputStream
|
||||||
|
|
||||||
|
public class TestStdlibWithDxTest {
|
||||||
|
Test public fun testRuntimeWithDx() {
|
||||||
|
doTest(ForTestCompileRuntime.runtimeJarForTests())
|
||||||
|
}
|
||||||
|
|
||||||
|
Test public fun testReflectWithDx() {
|
||||||
|
doTest(ForTestCompileRuntime.reflectJarForTests())
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun doTest(file: File) {
|
||||||
|
val zip = ZipInputStream(FileInputStream(file))
|
||||||
|
zip.use {
|
||||||
|
sequence { zip.getNextEntry() }.forEach {
|
||||||
|
if (it.getName().endsWith(".class")) {
|
||||||
|
DxChecker.checkFileWithDx(zip.readBytes(), it.getName())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user