Minor refactorings in codegen tests
Unindent code, get rid of warnings, etc.
This commit is contained in:
@@ -40,6 +40,7 @@ import org.jetbrains.jet.lang.psi.JetClass;
|
|||||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
|
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -80,16 +81,15 @@ public class TestlibTest extends UsefulTestCase {
|
|||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
|
||||||
CompilerConfiguration configuration = JetTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL,
|
CompilerConfiguration configuration = JetTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.FULL_JDK);
|
||||||
TestJdkKind.FULL_JDK);
|
|
||||||
configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, JetTestUtils.getAnnotationsJar());
|
configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, JetTestUtils.getAnnotationsJar());
|
||||||
|
|
||||||
junitJar = new File("libraries/lib/junit-4.9.jar");
|
junitJar = new File("libraries/lib/junit-4.9.jar");
|
||||||
assertTrue(junitJar.exists());
|
assertTrue(junitJar.exists());
|
||||||
configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, junitJar);
|
configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, junitJar);
|
||||||
|
|
||||||
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, JetTestCaseBuilder.getTestDataPathBase() + "/../../libraries/stdlib/test");
|
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, JetTestCaseBuilder.getHomeDirectory() + "/libraries/stdlib/test");
|
||||||
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, JetTestCaseBuilder.getTestDataPathBase() + "/../../libraries/kunit/src");
|
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, JetTestCaseBuilder.getHomeDirectory() + "/libraries/kunit/src");
|
||||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY,
|
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY,
|
||||||
new MessageCollectorPlainTextToStream(System.out, MessageCollectorPlainTextToStream.NON_VERBOSE));
|
new MessageCollectorPlainTextToStream(System.out, MessageCollectorPlainTextToStream.NON_VERBOSE));
|
||||||
|
|
||||||
@@ -100,11 +100,9 @@ public class TestlibTest extends UsefulTestCase {
|
|||||||
throw new RuntimeException("There were compilation errors");
|
throw new RuntimeException("There were compilation errors");
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassFileFactory classFileFactory = generationState.getFactory();
|
classLoader = new GeneratedClassLoader(generationState.getFactory(),
|
||||||
|
|
||||||
classLoader = new GeneratedClassLoader(classFileFactory,
|
|
||||||
new URLClassLoader(new URL[] {ForTestCompileRuntime.runtimeJarForTests().toURI().toURL()},
|
new URLClassLoader(new URL[] {ForTestCompileRuntime.runtimeJarForTests().toURI().toURL()},
|
||||||
null)) {
|
null)) {
|
||||||
@Override
|
@Override
|
||||||
public Class<?> loadClass(String name) throws ClassNotFoundException {
|
public Class<?> loadClass(String name) throws ClassNotFoundException {
|
||||||
if (name.startsWith("junit.") || name.startsWith("org.junit.")) {
|
if (name.startsWith("junit.") || name.startsWith("org.junit.")) {
|
||||||
@@ -119,35 +117,34 @@ public class TestlibTest extends UsefulTestCase {
|
|||||||
|
|
||||||
for (JetFile jetFile : myEnvironment.getSourceFiles()) {
|
for (JetFile jetFile : myEnvironment.getSourceFiles()) {
|
||||||
for (JetDeclaration declaration : jetFile.getDeclarations()) {
|
for (JetDeclaration declaration : jetFile.getDeclarations()) {
|
||||||
if (declaration instanceof JetClass) {
|
if (!(declaration instanceof JetClass)) continue;
|
||||||
ClassDescriptor descriptor = (ClassDescriptor) generationState.getBindingContext().get(
|
|
||||||
BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
|
|
||||||
|
|
||||||
assertNotNull("Descriptor for declaration " + declaration + " shouldn't be null", descriptor);
|
ClassDescriptor descriptor = (ClassDescriptor) BindingContextUtils.getNotNull(generationState.getBindingContext(),
|
||||||
|
BindingContext.DECLARATION_TO_DESCRIPTOR,
|
||||||
|
declaration);
|
||||||
|
|
||||||
for (ClassDescriptor superClass : DescriptorUtils.getAllSuperClasses(descriptor)) {
|
for (ClassDescriptor superClass : DescriptorUtils.getAllSuperClasses(descriptor)) {
|
||||||
if ("junit/framework/Test".equals(typeMapper.mapClass(superClass).getInternalName())) {
|
if (!"junit/framework/Test".equals(typeMapper.mapClass(superClass).getInternalName())) continue;
|
||||||
String name = typeMapper.mapClass(descriptor).getInternalName();
|
|
||||||
|
|
||||||
System.out.println(name);
|
String name = typeMapper.mapClass(descriptor).getInternalName();
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
System.out.println(name);
|
||||||
Class<TestCase> aClass = (Class<TestCase>) classLoader.loadClass(name.replace('/', '.'));
|
|
||||||
|
|
||||||
if (!Modifier.isAbstract(aClass.getModifiers()) && Modifier.isPublic(aClass.getModifiers())) {
|
@SuppressWarnings("unchecked")
|
||||||
try {
|
Class<TestCase> aClass = (Class<TestCase>) classLoader.loadClass(name.replace('/', '.'));
|
||||||
if (Modifier.isPublic(aClass.getConstructor().getModifiers())) {
|
|
||||||
suite.addTestSuite(aClass);
|
if (!Modifier.isAbstract(aClass.getModifiers()) && Modifier.isPublic(aClass.getModifiers())) {
|
||||||
}
|
try {
|
||||||
}
|
if (Modifier.isPublic(aClass.getConstructor().getModifiers())) {
|
||||||
catch (NoSuchMethodException e) {
|
suite.addTestSuite(aClass);
|
||||||
// Ignore test classes we can't instantiate
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
catch (NoSuchMethodException e) {
|
||||||
|
// Ignore test classes we can't instantiate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import org.jetbrains.jet.codegen.GenerationUtils;
|
|||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -69,7 +68,7 @@ public abstract class AbstractWriteFlagsTest extends UsefulTestCase {
|
|||||||
super.tearDown();
|
super.tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void doTest(String path) throws IOException {
|
protected void doTest(String path) throws Exception {
|
||||||
File ktFile = new File(path);
|
File ktFile = new File(path);
|
||||||
assertTrue("Cannot find a file " + ktFile.getAbsolutePath(), ktFile.exists());
|
assertTrue("Cannot find a file " + ktFile.getAbsolutePath(), ktFile.exists());
|
||||||
|
|
||||||
@@ -99,51 +98,48 @@ public abstract class AbstractWriteFlagsTest extends UsefulTestCase {
|
|||||||
assertNotNull(outputFile);
|
assertNotNull(outputFile);
|
||||||
|
|
||||||
ClassReader cr = new ClassReader(outputFile.asByteArray());
|
ClassReader cr = new ClassReader(outputFile.asByteArray());
|
||||||
TestClassVisitor classVisitor;
|
TestClassVisitor classVisitor = getClassVisitor(testedObject.kind, testedObject.name);
|
||||||
classVisitor = getClassVisitor(testedObject.kind, testedObject.name);
|
|
||||||
cr.accept(classVisitor, ClassReader.SKIP_CODE);
|
cr.accept(classVisitor, ClassReader.SKIP_CODE);
|
||||||
|
|
||||||
boolean isObjectExists = !Boolean.valueOf(findStringWithPrefixes(testedObject.textData, "// ABSENT: "));
|
boolean isObjectExists = !Boolean.valueOf(findStringWithPrefixes(testedObject.textData, "// ABSENT: "));
|
||||||
assertEquals( "Wrong object existence state: " + testedObject, isObjectExists, classVisitor.isExists());
|
assertEquals("Wrong object existence state: " + testedObject, isObjectExists, classVisitor.isExists());
|
||||||
int expectedAccess = getExpectedFlags(testedObject.textData);
|
|
||||||
|
|
||||||
if (isObjectExists) {
|
if (isObjectExists) {
|
||||||
assertEquals("Wrong access flag for " + testedObject + " \n" + outputFile.asText(), expectedAccess, classVisitor.getAccess());
|
assertEquals("Wrong access flag for " + testedObject + " \n" + outputFile.asText(),
|
||||||
|
getExpectedFlags(testedObject.textData), classVisitor.getAccess());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<TestedObject> parseExpectedTestedObject(String testDescription) {
|
private static List<TestedObject> parseExpectedTestedObject(String testDescription) {
|
||||||
testDescription = testDescription.substring(testDescription.indexOf("// TESTED_OBJECT_KIND"));
|
String[] testObjectData = testDescription.substring(testDescription.indexOf("// TESTED_OBJECT_KIND")).split("\n\n");
|
||||||
String [] testObjectData = testDescription.split("\n\n");
|
|
||||||
ArrayList<TestedObject> objects = new ArrayList<TestedObject>();
|
ArrayList<TestedObject> objects = new ArrayList<TestedObject>();
|
||||||
|
|
||||||
for (int i = 0; i < testObjectData.length; i++) {
|
for (String testData : testObjectData) {
|
||||||
String testData = testObjectData[i];
|
if (testData.isEmpty()) continue;
|
||||||
if (!testData.isEmpty()) {
|
|
||||||
TestedObject testObject = new TestedObject();
|
|
||||||
testObject.textData = testData;
|
|
||||||
List<String> testedObjects = findListWithPrefixes(testData, "// TESTED_OBJECTS: ");
|
|
||||||
assertTrue("Cannot find TESTED_OBJECTS instruction", !testedObjects.isEmpty());
|
|
||||||
testObject.containingClass = testedObjects.get(0);
|
|
||||||
if (testedObjects.size() == 1) {
|
|
||||||
testObject.name = testedObjects.get(0);
|
|
||||||
}
|
|
||||||
else if (testedObjects.size() == 2) {
|
|
||||||
testObject.name = testedObjects.get(1);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"TESTED_OBJECTS instruction must contains one (for class) or two (for function and property) values");
|
|
||||||
}
|
|
||||||
|
|
||||||
testObject.kind = findStringWithPrefixes(testData, "// TESTED_OBJECT_KIND: ");
|
TestedObject testObject = new TestedObject();
|
||||||
List<String> isFullName = findListWithPrefixes(testData, "// IS_FULL_CONTAINING_CLASS_NAME: ");
|
testObject.textData = testData;
|
||||||
if (isFullName.size() == 1) {
|
List<String> testedObjects = findListWithPrefixes(testData, "// TESTED_OBJECTS: ");
|
||||||
testObject.isFullContainingClassName = Boolean.parseBoolean(isFullName.get(0));
|
assertTrue("Cannot find TESTED_OBJECTS instruction", !testedObjects.isEmpty());
|
||||||
}
|
testObject.containingClass = testedObjects.get(0);
|
||||||
objects.add(testObject);
|
if (testedObjects.size() == 1) {
|
||||||
|
testObject.name = testedObjects.get(0);
|
||||||
}
|
}
|
||||||
|
else if (testedObjects.size() == 2) {
|
||||||
|
testObject.name = testedObjects.get(1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"TESTED_OBJECTS instruction must contain one (for class) or two (for function and property) values");
|
||||||
|
}
|
||||||
|
|
||||||
|
testObject.kind = findStringWithPrefixes(testData, "// TESTED_OBJECT_KIND: ");
|
||||||
|
List<String> isFullName = findListWithPrefixes(testData, "// IS_FULL_CONTAINING_CLASS_NAME: ");
|
||||||
|
if (isFullName.size() == 1) {
|
||||||
|
testObject.isFullContainingClassName = Boolean.parseBoolean(isFullName.get(0));
|
||||||
|
}
|
||||||
|
objects.add(testObject);
|
||||||
}
|
}
|
||||||
assertTrue("Test description not present!", !objects.isEmpty());
|
assertTrue("Test description not present!", !objects.isEmpty());
|
||||||
return objects;
|
return objects;
|
||||||
|
|||||||
Reference in New Issue
Block a user