diff --git a/compiler/testData/codegen/regressions/kt344.jet b/compiler/testData/codegen/regressions/kt344.jet index 1f35cb5e138..99f657592e1 100644 --- a/compiler/testData/codegen/regressions/kt344.jet +++ b/compiler/testData/codegen/regressions/kt344.jet @@ -186,8 +186,8 @@ fun box(): String { if (!t8()) return "t8 fail" if (!t9(0)) return "t9 fail" if (!t10()) return "t10 fail" - if (t11(1) != 104) return "t11 fail" + if (t11(1) != 101) return "t11 fail" if (t12(0) != 100) return "t12 fail" return "OK" -} \ No newline at end of file +} diff --git a/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java b/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java index 312db145222..4343c8a8991 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java +++ b/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java @@ -133,20 +133,7 @@ public abstract class CodegenTestCase extends UsefulTestCase { protected void blackBoxFile(String filename) { loadFile(filename); - Object actual; - try { - actual = blackBox(); - } catch (NoClassDefFoundError e) { - System.out.println(generateToText()); - throw e; - } catch (Throwable e) { - System.out.println(generateToText()); - throw new RuntimeException(e); - } - if (!Objects.equal(myFile.getExpectedValue(), actual)) { - System.out.println(generateToText()); - } - assertEquals(myFile.getExpectedValue(), actual); + blackBox(); } @NotNull @@ -188,11 +175,12 @@ public abstract class CodegenTestCase extends UsefulTestCase { } } - @NotNull - protected String blackBox() throws Exception { + protected void blackBox() { GenerationState state = generateClassesInFileGetState(); GeneratedClassLoader loader = createClassLoader(state.getFactory()); + String r; + try { if (myFile.getPsiFile().isScript()) { Class scriptClass = loader.loadClass("Script"); @@ -202,23 +190,38 @@ public abstract class CodegenTestCase extends UsefulTestCase { Field field = scriptClass.getDeclaredField("rv"); field.setAccessible(true); Object result = field.get(scriptInstance); - return result != null ? result.toString() : "null"; + r = result != null ? result.toString() : "null"; } else { String fqName = NamespaceCodegen.getJVMClassNameForKotlinNs(JetPsiUtil.getFQName(myFile.getPsiFile())).getFqName().getFqName(); Class namespaceClass = loader.loadClass(fqName); Method method = namespaceClass.getMethod("box"); - return (String) method.invoke(null); + r = (String) method.invoke(null); } + } catch (NoClassDefFoundError e) { + System.out.println(generateToText()); + throw e; + } catch (Throwable e) { + System.out.println(generateToText()); + throw new RuntimeException(e); } finally { - loader.dispose(); + loader.dispose(); } + + if (!Objects.equal(myFile.getExpectedValue(), r)) { + System.out.println(generateToText()); + } + assertEquals(myFile.getExpectedValue(), r); } - protected GeneratedClassLoader createClassLoader(ClassFileFactory codegens) throws MalformedURLException { + protected GeneratedClassLoader createClassLoader(ClassFileFactory codegens) { List urls = Lists.newArrayList(); for (File file : extraClasspath) { - urls.add(file.toURI().toURL()); + try { + urls.add(file.toURI().toURL()); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } } ClassLoader parentClassLoader = new URLClassLoader(urls.toArray(new URL[0]), CodegenTestCase.class.getClassLoader()); return new GeneratedClassLoader(codegens, parentClassLoader); @@ -255,8 +258,6 @@ public abstract class CodegenTestCase extends UsefulTestCase { return createClassLoader(state).loadClass(fqName); } catch (ClassNotFoundException e) { e.printStackTrace(); - } catch (MalformedURLException e) { - e.printStackTrace(); } return null; } @@ -265,7 +266,6 @@ public abstract class CodegenTestCase extends UsefulTestCase { try { return createClassLoader(state).loadClass(fqName); } catch (ClassNotFoundException e) { - } catch (MalformedURLException e) { } fail("No classfile was generated for: " + fqName); diff --git a/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java b/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java index 50700c26205..7e587af3167 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java @@ -337,7 +337,7 @@ public class PrimitiveTypesTest extends CodegenTestCase { public void testKt737() throws Exception { loadText("fun box() = if(3.compareTo(2) != 1) \"fail\" else if(5.toByte().compareTo(10.toLong()) >= 0) \"fail\" else \"OK\""); - assertEquals("OK", blackBox()); + blackBox(); } public void testKt665() throws Exception { diff --git a/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java b/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java index d2015cb0f0a..3b4a8c9c151 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java @@ -47,11 +47,15 @@ public class StdlibTest extends CodegenTestCase { } @Override - protected GeneratedClassLoader createClassLoader(ClassFileFactory codegens) throws MalformedURLException { - return new GeneratedClassLoader( - codegens, - new URLClassLoader(new URL[]{ForTestCompileRuntime.runtimeJarForTests().toURI().toURL()}, - getClass().getClassLoader())); + protected GeneratedClassLoader createClassLoader(ClassFileFactory codegens) { + try { + return new GeneratedClassLoader( + codegens, + new URLClassLoader(new URL[]{ForTestCompileRuntime.runtimeJarForTests().toURI().toURL()}, + getClass().getClassLoader())); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } } public void testKt533 () {