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.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
|
||||
import java.io.File;
|
||||
@@ -80,16 +81,15 @@ public class TestlibTest extends UsefulTestCase {
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
CompilerConfiguration configuration = JetTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL,
|
||||
TestJdkKind.FULL_JDK);
|
||||
CompilerConfiguration configuration = JetTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.FULL_JDK);
|
||||
configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, JetTestUtils.getAnnotationsJar());
|
||||
|
||||
junitJar = new File("libraries/lib/junit-4.9.jar");
|
||||
assertTrue(junitJar.exists());
|
||||
configuration.add(JVMConfigurationKeys.CLASSPATH_KEY, junitJar);
|
||||
|
||||
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, JetTestCaseBuilder.getTestDataPathBase() + "/../../libraries/stdlib/test");
|
||||
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, JetTestCaseBuilder.getTestDataPathBase() + "/../../libraries/kunit/src");
|
||||
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, JetTestCaseBuilder.getHomeDirectory() + "/libraries/stdlib/test");
|
||||
configuration.add(CommonConfigurationKeys.SOURCE_ROOTS_KEY, JetTestCaseBuilder.getHomeDirectory() + "/libraries/kunit/src");
|
||||
configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY,
|
||||
new MessageCollectorPlainTextToStream(System.out, MessageCollectorPlainTextToStream.NON_VERBOSE));
|
||||
|
||||
@@ -100,11 +100,9 @@ public class TestlibTest extends UsefulTestCase {
|
||||
throw new RuntimeException("There were compilation errors");
|
||||
}
|
||||
|
||||
ClassFileFactory classFileFactory = generationState.getFactory();
|
||||
|
||||
classLoader = new GeneratedClassLoader(classFileFactory,
|
||||
classLoader = new GeneratedClassLoader(generationState.getFactory(),
|
||||
new URLClassLoader(new URL[] {ForTestCompileRuntime.runtimeJarForTests().toURI().toURL()},
|
||||
null)) {
|
||||
null)) {
|
||||
@Override
|
||||
public Class<?> loadClass(String name) throws ClassNotFoundException {
|
||||
if (name.startsWith("junit.") || name.startsWith("org.junit.")) {
|
||||
@@ -119,35 +117,34 @@ public class TestlibTest extends UsefulTestCase {
|
||||
|
||||
for (JetFile jetFile : myEnvironment.getSourceFiles()) {
|
||||
for (JetDeclaration declaration : jetFile.getDeclarations()) {
|
||||
if (declaration instanceof JetClass) {
|
||||
ClassDescriptor descriptor = (ClassDescriptor) generationState.getBindingContext().get(
|
||||
BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
|
||||
if (!(declaration instanceof JetClass)) continue;
|
||||
|
||||
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)) {
|
||||
if ("junit/framework/Test".equals(typeMapper.mapClass(superClass).getInternalName())) {
|
||||
String name = typeMapper.mapClass(descriptor).getInternalName();
|
||||
for (ClassDescriptor superClass : DescriptorUtils.getAllSuperClasses(descriptor)) {
|
||||
if (!"junit/framework/Test".equals(typeMapper.mapClass(superClass).getInternalName())) continue;
|
||||
|
||||
System.out.println(name);
|
||||
String name = typeMapper.mapClass(descriptor).getInternalName();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<TestCase> aClass = (Class<TestCase>) classLoader.loadClass(name.replace('/', '.'));
|
||||
System.out.println(name);
|
||||
|
||||
if (!Modifier.isAbstract(aClass.getModifiers()) && Modifier.isPublic(aClass.getModifiers())) {
|
||||
try {
|
||||
if (Modifier.isPublic(aClass.getConstructor().getModifiers())) {
|
||||
suite.addTestSuite(aClass);
|
||||
}
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
// Ignore test classes we can't instantiate
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
Class<TestCase> aClass = (Class<TestCase>) classLoader.loadClass(name.replace('/', '.'));
|
||||
|
||||
if (!Modifier.isAbstract(aClass.getModifiers()) && Modifier.isPublic(aClass.getModifiers())) {
|
||||
try {
|
||||
if (Modifier.isPublic(aClass.getConstructor().getModifiers())) {
|
||||
suite.addTestSuite(aClass);
|
||||
}
|
||||
|
||||
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 java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -69,7 +68,7 @@ public abstract class AbstractWriteFlagsTest extends UsefulTestCase {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
protected void doTest(String path) throws IOException {
|
||||
protected void doTest(String path) throws Exception {
|
||||
File ktFile = new File(path);
|
||||
assertTrue("Cannot find a file " + ktFile.getAbsolutePath(), ktFile.exists());
|
||||
|
||||
@@ -99,51 +98,48 @@ public abstract class AbstractWriteFlagsTest extends UsefulTestCase {
|
||||
assertNotNull(outputFile);
|
||||
|
||||
ClassReader cr = new ClassReader(outputFile.asByteArray());
|
||||
TestClassVisitor classVisitor;
|
||||
classVisitor = getClassVisitor(testedObject.kind, testedObject.name);
|
||||
TestClassVisitor classVisitor = getClassVisitor(testedObject.kind, testedObject.name);
|
||||
cr.accept(classVisitor, ClassReader.SKIP_CODE);
|
||||
|
||||
boolean isObjectExists = !Boolean.valueOf(findStringWithPrefixes(testedObject.textData, "// ABSENT: "));
|
||||
assertEquals( "Wrong object existence state: " + testedObject, isObjectExists, classVisitor.isExists());
|
||||
int expectedAccess = getExpectedFlags(testedObject.textData);
|
||||
assertEquals("Wrong object existence state: " + testedObject, isObjectExists, classVisitor.isExists());
|
||||
|
||||
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) {
|
||||
testDescription = testDescription.substring(testDescription.indexOf("// TESTED_OBJECT_KIND"));
|
||||
String [] testObjectData = testDescription.split("\n\n");
|
||||
String[] testObjectData = testDescription.substring(testDescription.indexOf("// TESTED_OBJECT_KIND")).split("\n\n");
|
||||
ArrayList<TestedObject> objects = new ArrayList<TestedObject>();
|
||||
|
||||
for (int i = 0; i < testObjectData.length; i++) {
|
||||
String testData = testObjectData[i];
|
||||
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");
|
||||
}
|
||||
for (String testData : testObjectData) {
|
||||
if (testData.isEmpty()) continue;
|
||||
|
||||
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);
|
||||
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 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());
|
||||
return objects;
|
||||
|
||||
Reference in New Issue
Block a user