diff --git a/compiler/testData/codegen/classes/classObjectField.kt b/compiler/testData/codegen/classes/classObjectField.kt new file mode 100644 index 00000000000..7f7bd89c6c1 --- /dev/null +++ b/compiler/testData/codegen/classes/classObjectField.kt @@ -0,0 +1,7 @@ +class A() { + class object { + val value = 10 + } +} + +fun box() = if (A.value == 10) "OK" else "Fail ${A.value}" diff --git a/compiler/testData/codegen/primitiveTypes/kt665.kt b/compiler/testData/codegen/primitiveTypes/kt665.kt new file mode 100644 index 00000000000..b8bd69b6550 --- /dev/null +++ b/compiler/testData/codegen/primitiveTypes/kt665.kt @@ -0,0 +1,12 @@ +fun f(x: Long, zzz: Long = 1): Long +{ + return if (x <= 1) zzz + else f(x-1, x*zzz) +} + +fun box() : String +{ + val six: Long = 6; + if (f(six) != 720.toLong()) return "Fail" + return "OK" +} diff --git a/compiler/testData/codegen/primitiveTypes/kt711.kt b/compiler/testData/codegen/primitiveTypes/kt711.kt new file mode 100644 index 00000000000..ffe360595a5 --- /dev/null +++ b/compiler/testData/codegen/primitiveTypes/kt711.kt @@ -0,0 +1 @@ +fun box() = if ((1 ?: 0) == 1) "OK" else "fail" diff --git a/compiler/testData/codegen/primitiveTypes/kt737.kt b/compiler/testData/codegen/primitiveTypes/kt737.kt new file mode 100644 index 00000000000..bdf9a4f5af7 --- /dev/null +++ b/compiler/testData/codegen/primitiveTypes/kt737.kt @@ -0,0 +1,5 @@ +fun box(): String { + if (3.compareTo(2) != 1) return "Fail #1" + if (5.toByte().compareTo(10.toLong()) >= 0) return "Fail #2" + return "OK" +} diff --git a/compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java index 53f7aebc2be..ad2c29cc2b9 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/ClassGenTest.java @@ -248,9 +248,7 @@ public class ClassGenTest extends CodegenTestCase { } public void testClassObjFields() { - loadText("class A() { class object { val value = 10 } }\n" + - "fun box() = if(A.value == 10) \"OK\" else \"fail\""); - blackBox(); + blackBoxFile("classes/classObjectField.kt"); } public void testPrivateOuterProperty() { @@ -434,15 +432,15 @@ public class ClassGenTest extends CodegenTestCase { } public void testKt2395() { - blackBoxMultiFile("regressions/kt2395.kt"); + blackBoxFile("regressions/kt2395.kt"); } public void testKt2566() { - blackBoxMultiFile("regressions/kt2566.kt"); + blackBoxFile("regressions/kt2566.kt"); } public void testKt2566_2() { - blackBoxMultiFile("regressions/kt2566_2.kt"); + blackBoxFile("regressions/kt2566_2.kt"); } public void testKt2477() { @@ -450,11 +448,11 @@ public class ClassGenTest extends CodegenTestCase { } public void testKt2485() { - blackBoxMultiFile("regressions/kt2485.kt"); + blackBoxFile("regressions/kt2485.kt"); } public void testKt2482() { - blackBoxMultiFile("regressions/kt2482.kt"); + blackBoxFile("regressions/kt2482.kt"); } public void testKt2288() { diff --git a/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java b/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java index 514a0f5407a..7532c64fe5d 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java +++ b/compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java @@ -158,24 +158,19 @@ public abstract class CodegenTestCase extends UsefulTestCase { blackBoxFile(filename, false); } - protected void blackBoxFile(String filename, boolean classPathInTheSameClassLoader) { + private void blackBoxFile(String filename, boolean classPathInTheSameClassLoader) { loadFile(filename); blackBox(classPathInTheSameClassLoader); } protected void blackBoxFileByFullPath(String filename) { loadFileByFullPath(filename); - blackBox(); + blackBox(false); } protected void blackBoxMultiFile(String... filenames) { loadFiles(filenames); - blackBox(); - } - - protected void blackBoxMultiFile(boolean classPathInTheSameClassLoader, String... filenames) { - loadFiles(filenames); - blackBox(classPathInTheSameClassLoader); + blackBox(false); } @NotNull @@ -217,11 +212,7 @@ public abstract class CodegenTestCase extends UsefulTestCase { } } - protected void blackBox() { - blackBox(false); - } - - protected void blackBox(boolean classPathInTheSameClassLoader) { + private void blackBox(boolean classPathInTheSameClassLoader) { GenerationState state = generateClassesInFileGetState(); GeneratedClassLoader loader = createClassLoader(state.getFactory(), classPathInTheSameClassLoader); @@ -280,15 +271,15 @@ public abstract class CodegenTestCase extends UsefulTestCase { } } - protected void blackBoxFileWithJavaByFullPath(@NotNull String ktFile) throws Exception { + protected void blackBoxFileWithJavaByFullPath(@NotNull String ktFile) { blackBoxFileWithJava(ktFile.substring("compiler/testData/codegen/".length()), false); } - protected void blackBoxFileWithJava(@NotNull String ktFile) throws Exception { + protected void blackBoxFileWithJava(@NotNull String ktFile) { blackBoxFileWithJava(ktFile, false); } - protected void blackBoxFileWithJava(@NotNull String ktFile, boolean classPathInTheSameClassLoader) throws Exception { + protected void blackBoxFileWithJava(@NotNull String ktFile, boolean classPathInTheSameClassLoader) { File javaClassesTempDirectory = compileJava(ktFile.replaceFirst("\\.kt$", ".java")); myEnvironment = new JetCoreEnvironment(getTestRootDisposable(), JetTestUtils.compilerConfigurationForTests( @@ -297,19 +288,24 @@ public abstract class CodegenTestCase extends UsefulTestCase { blackBoxFile(ktFile, classPathInTheSameClassLoader); } - protected File compileJava(@NotNull String filename) throws IOException { - File javaClassesTempDirectory = new File(FileUtil.getTempDirectory(), "java-classes"); - JetTestUtils.mkdirs(javaClassesTempDirectory); - String classPath = "out/production/runtime" + File.pathSeparator + JetTestUtils.getAnnotationsJar().getPath(); - List options = Arrays.asList( - "-classpath", classPath, - "-d", javaClassesTempDirectory.getPath() - ); + protected File compileJava(@NotNull String filename) { + try { + File javaClassesTempDirectory = new File(FileUtil.getTempDirectory(), "java-classes"); + JetTestUtils.mkdirs(javaClassesTempDirectory); + String classPath = "out/production/runtime" + File.pathSeparator + JetTestUtils.getAnnotationsJar().getPath(); + List options = Arrays.asList( + "-classpath", classPath, + "-d", javaClassesTempDirectory.getPath() + ); - File javaFile = new File("compiler/testData/codegen/" + filename); - JetTestUtils.compileJavaFiles(Collections.singleton(javaFile), options); + File javaFile = new File("compiler/testData/codegen/" + filename); + JetTestUtils.compileJavaFiles(Collections.singleton(javaFile), options); - return javaClassesTempDirectory; + return javaClassesTempDirectory; + } + catch (IOException e) { + throw ExceptionUtils.rethrow(e); + } } protected GeneratedClassLoader createClassLoader(ClassFileFactory codegens) { diff --git a/compiler/tests/org/jetbrains/jet/codegen/GenerateNotNullAssertionsTest.java b/compiler/tests/org/jetbrains/jet/codegen/GenerateNotNullAssertionsTest.java index 83a82f392f4..f1c5edaa0a4 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/GenerateNotNullAssertionsTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/GenerateNotNullAssertionsTest.java @@ -55,7 +55,7 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase { setUpEnvironment(generateAssertions, false, javaClassesTempDirectory); - blackBoxMultiFile(false, "notNullAssertions/AssertionChecker.kt", ktFile); + blackBoxMultiFile("notNullAssertions/AssertionChecker.kt", ktFile); } public void testGenerateAssertions() throws Exception { diff --git a/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java b/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java index 144b714a462..8f00993f9a9 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/PrimitiveTypesTest.java @@ -300,9 +300,8 @@ public class PrimitiveTypesTest extends CodegenTestCase { blackBoxFile("regressions/kt518.kt"); } - public void testKt711 () throws Exception { - loadText("fun box() = if ((1 ?: 0) == 1) \"OK\" else \"fail\""); - blackBox(); + public void testKt711() { + blackBoxFile("primitiveTypes/kt711.kt"); } public void testSureNonnull () throws Exception { @@ -325,25 +324,12 @@ public class PrimitiveTypesTest extends CodegenTestCase { assertTrue(generateToText().contains("IFNULL")); } - 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\""); - blackBox(); + public void testKt737() { + blackBoxFile("primitiveTypes/kt737.kt"); } - public void testKt665() throws Exception { - loadText("fun f(x: Long, zzz: Long = 1): Long\n" + - "{\n" + - " return if (x <= 1) zzz\n" + - " else f(x-1, x*zzz)\n" + - "}\n" + - "\n" + - "fun box() : String\n" + - "{\n" + - " val six: Long = 6;\n" + - " System.out?.println(f(six))\n" + - " return \"OK\"" + - "}"); - blackBox(); + public void testKt665() { + blackBoxFile("primitiveTypes/kt665.kt"); } public void testKt752 () { diff --git a/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java b/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java index 51a678fffde..fdcc7a9e58b 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/StdlibTest.java @@ -93,10 +93,8 @@ public class StdlibTest extends CodegenTestCase { blackBoxFile("regressions/kt274.kt"); } - //from ClassGenTest - public void testKt344 () throws Exception { - loadFile("regressions/kt344.kt"); - blackBox(); + public void testKt344 () { + blackBoxFile("regressions/kt344.kt"); } //from ExtensionFunctionsTest