Add verification by dx.jar to CodegenTests
A patch by Natalia Ukhorskaya: https://github.com/JetBrains/kotlin/pull/70 Adds Android verfication to our codegen tests
This commit is contained in:
Generated
+11
@@ -0,0 +1,11 @@
|
|||||||
|
<component name="libraryTable">
|
||||||
|
<library name="dx-android">
|
||||||
|
<CLASSES>
|
||||||
|
<root url="jar://$PROJECT_DIR$/dependencies/dx.jar!/" />
|
||||||
|
</CLASSES>
|
||||||
|
<JAVADOC />
|
||||||
|
<SOURCES>
|
||||||
|
<root url="jar://$PROJECT_DIR$/dependencies/dx-sources.jar!/" />
|
||||||
|
</SOURCES>
|
||||||
|
</library>
|
||||||
|
</component>
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
<orderEntry type="module" module-name="cli" />
|
<orderEntry type="module" module-name="cli" />
|
||||||
<orderEntry type="library" name="idea-full" level="project" />
|
<orderEntry type="library" name="idea-full" level="project" />
|
||||||
<orderEntry type="library" name="asm" level="project" />
|
<orderEntry type="library" name="asm" level="project" />
|
||||||
|
<orderEntry type="library" name="dx-android" level="project" />
|
||||||
</component>
|
</component>
|
||||||
</module>
|
</module>
|
||||||
|
|
||||||
|
|||||||
@@ -184,6 +184,11 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
|||||||
|
|
||||||
protected void blackBox() {
|
protected void blackBox() {
|
||||||
GenerationState state = generateClassesInFileGetState();
|
GenerationState state = generateClassesInFileGetState();
|
||||||
|
|
||||||
|
if (DxChecker.RUN_DX_CHECKER) {
|
||||||
|
DxChecker.check(state.getFactory());
|
||||||
|
}
|
||||||
|
|
||||||
GeneratedClassLoader loader = createClassLoader(state.getFactory());
|
GeneratedClassLoader loader = createClassLoader(state.getFactory());
|
||||||
|
|
||||||
String r;
|
String r;
|
||||||
@@ -224,7 +229,7 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
|||||||
r = (String) method.invoke(null);
|
r = (String) method.invoke(null);
|
||||||
assertEquals("OK", r);
|
assertEquals("OK", r);
|
||||||
}
|
}
|
||||||
} catch (NoClassDefFoundError e) {
|
} catch (Error e) {
|
||||||
System.out.println(generateToText());
|
System.out.println(generateToText());
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
@@ -268,6 +273,11 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
|||||||
|
|
||||||
protected Class generateNamespaceClass() {
|
protected Class generateNamespaceClass() {
|
||||||
ClassFileFactory state = generateClassesInFile();
|
ClassFileFactory state = generateClassesInFile();
|
||||||
|
|
||||||
|
if (DxChecker.RUN_DX_CHECKER) {
|
||||||
|
DxChecker.check(state);
|
||||||
|
}
|
||||||
|
|
||||||
return loadRootNamespaceClass(state);
|
return loadRootNamespaceClass(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,6 +309,11 @@ public abstract class CodegenTestCase extends UsefulTestCase {
|
|||||||
@NotNull
|
@NotNull
|
||||||
protected ClassFileFactory generateClassesInFile() {
|
protected ClassFileFactory generateClassesInFile() {
|
||||||
GenerationState generationState = generateClassesInFileGetState();
|
GenerationState generationState = generateClassesInFileGetState();
|
||||||
|
|
||||||
|
if (DxChecker.RUN_DX_CHECKER) {
|
||||||
|
DxChecker.check(generationState.getFactory());
|
||||||
|
}
|
||||||
|
|
||||||
return generationState.getFactory();
|
return generationState.getFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 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.jet.codegen;
|
||||||
|
|
||||||
|
import com.android.dx.command.dexer.Main;
|
||||||
|
import com.android.dx.dex.cf.CfTranslator;
|
||||||
|
import junit.framework.Assert;
|
||||||
|
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Natalia.Ukhorskaya
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class DxChecker {
|
||||||
|
|
||||||
|
public static final boolean RUN_DX_CHECKER = true;
|
||||||
|
private static final Pattern STACK_TRACE_PATTERN = Pattern.compile("[\\s]+at .*");
|
||||||
|
|
||||||
|
private DxChecker() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void check(ClassFileFactory factory) {
|
||||||
|
Main.Arguments arguments = new Main.Arguments();
|
||||||
|
String[] array = new String[1];
|
||||||
|
array[0] = "testArgs";
|
||||||
|
arguments.parse(array);
|
||||||
|
|
||||||
|
for (String file : factory.files()) {
|
||||||
|
try {
|
||||||
|
CfTranslator.translate(file, factory.asBytes(file), arguments.cfOptions, arguments.dexOptions);
|
||||||
|
}
|
||||||
|
catch (Throwable e) {
|
||||||
|
Assert.fail(generateExceptionMessage(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String generateExceptionMessage(Throwable e) {
|
||||||
|
StringWriter writer = new StringWriter();
|
||||||
|
PrintWriter printWriter = new PrintWriter(writer);
|
||||||
|
try {
|
||||||
|
e.printStackTrace(printWriter);
|
||||||
|
String stackTrace = writer.toString();
|
||||||
|
Matcher matcher = STACK_TRACE_PATTERN.matcher(stackTrace);
|
||||||
|
return matcher.replaceAll("");
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
printWriter.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -59,6 +59,10 @@
|
|||||||
<delete dir="dependencies/ant" failonerror="false"/>
|
<delete dir="dependencies/ant" failonerror="false"/>
|
||||||
<untar src="dependencies/download/apache-ant-1.7.0-bin.tar.gz" dest="dependencies" compression="gzip" />
|
<untar src="dependencies/download/apache-ant-1.7.0-bin.tar.gz" dest="dependencies" compression="gzip" />
|
||||||
<rename src="dependencies/apache-ant-1.7.0" dest="dependencies/ant" />
|
<rename src="dependencies/apache-ant-1.7.0" dest="dependencies/ant" />
|
||||||
|
|
||||||
|
<!-- dx.jar -->
|
||||||
|
<get src="http://search.maven.org/remotecontent?filepath=com/google/android/tools/dx/1.7/dx-1.7.jar" dest="dependencies/dx.jar"/>
|
||||||
|
<get src="http://search.maven.org/remotecontent?filepath=com/google/android/tools/dx/1.7/dx-1.7-sources.jar" dest="dependencies/dx-sources.jar"/>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<macrodef name="execute_update">
|
<macrodef name="execute_update">
|
||||||
|
|||||||
Reference in New Issue
Block a user