Refactor codegen tests

- initialize environment only once in setUp()
- add comments on why some tests are disabled
- modify and rename some tests
- re-enable now working tests
- extract some tests into files with box()
- remove useless 'throws' declarations and commented code
This commit is contained in:
Alexander Udalov
2013-01-22 22:22:53 +04:00
committed by Alexander Udalov
parent 99827d10a8
commit 0df71bd696
76 changed files with 601 additions and 704 deletions
@@ -87,9 +87,7 @@ public class SpecialFiles {
excludedFiles.add("namespaceQualifiedMethod.kt"); // Cannot change package name excludedFiles.add("namespaceQualifiedMethod.kt"); // Cannot change package name
excludedFiles.add("kt1482_2279.kt"); // Cannot change package name excludedFiles.add("kt1482_2279.kt"); // Cannot change package name
excludedFiles.add("kt1482.kt"); // Cannot change package name excludedFiles.add("kt1482.kt"); // Cannot change package name
excludedFiles.add("importFromClassObject.kt"); // Cannot find usages in Codegen tests
excludedFiles.add("withtypeparams.kt"); // Cannot find usages in Codegen tests excludedFiles.add("withtypeparams.kt"); // Cannot find usages in Codegen tests
excludedFiles.add("kt1113.kt"); // Commented
excludedFiles.add("kt326.kt"); // Commented excludedFiles.add("kt326.kt"); // Commented
excludedFiles.add("kt1213.kt"); // Commented excludedFiles.add("kt1213.kt"); // Commented
excludedFiles.add("kt882.kt"); // Commented excludedFiles.add("kt882.kt"); // Commented
@@ -0,0 +1,11 @@
fun Array<String>.get(index1: Int, index2: Int) = this[index1 + index2]
fun Array<String>.set(index1: Int, index2: Int, elem: String) {
this[index1 + index2] = elem
}
fun box(): String {
val s = Array<String>(1, { "" })
s[1, -1] = "O"
s[2, -2] += "K"
return s[-3, 3]
}
@@ -0,0 +1,11 @@
fun Array<String>.get(index1: Int, index2: Int) = this[index1 + index2]
fun Array<String>.set(index1: Int, index2: Int, elem: String) {
this[index1 + index2] = elem
}
fun box(): String {
val s = Array<String>(1, { "" })
s[1, -1] = "OK"
return s[-2, 2]
}
@@ -0,0 +1,6 @@
fun box(): String {
val s = IntArray(1)
s[0] = 5
s[0] += 7
return if (s[0] == 12) "OK" else "Fail ${s[0]}"
}
@@ -0,0 +1,14 @@
import java.util.ArrayList
fun ArrayList<String>.get(index1: Int, index2: Int) = this[index1 + index2]
fun ArrayList<String>.set(index1: Int, index2: Int, elem: String) {
this[index1 + index2] = elem
}
fun box(): String {
val s = ArrayList<String>(1)
s.add("")
s[1, -1] = "O"
s[2, -2] += "K"
return s[2, -2]
}
@@ -0,0 +1,13 @@
import java.util.ArrayList
fun ArrayList<String>.get(index1: Int, index2: Int) = this[index1 + index2]
fun ArrayList<String>.set(index1: Int, index2: Int, elem: String) {
this[index1 + index2] = elem
}
fun box(): String {
val s = ArrayList<String>(1)
s.add("")
s[1, -1] = "OK"
return s[2, -2]
}
@@ -0,0 +1,6 @@
fun box(): String {
for (x in BooleanArray(5)) {
if (x != false) return "Fail $x"
}
return "OK"
}
@@ -0,0 +1,6 @@
fun box(): String {
for (x in ByteArray(5)) {
if (x != 0.toByte()) return "Fail $x"
}
return "OK"
}
@@ -0,0 +1,6 @@
fun box(): String {
for (x in CharArray(5)) {
if (x != 0.toChar()) return "Fail $x"
}
return "OK"
}
@@ -0,0 +1,6 @@
fun box(): String {
for (x in DoubleArray(5)) {
if (x != 0.toDouble()) return "Fail $x"
}
return "OK"
}
@@ -0,0 +1,6 @@
fun box(): String {
for (x in FloatArray(5)) {
if (x != 0.toFloat()) return "Fail $x"
}
return "OK"
}
@@ -0,0 +1,6 @@
fun box(): String {
for (x in IntArray(5)) {
if (x != 0) return "Fail $x"
}
return "OK"
}
@@ -0,0 +1,6 @@
fun box(): String {
for (x in LongArray(5)) {
if (x != 0.toLong()) return "Fail $x"
}
return "OK"
}
@@ -0,0 +1,6 @@
fun box(): String {
for (x in ShortArray(5)) {
if (x != 0.toShort()) return "Fail $x"
}
return "OK"
}
@@ -0,0 +1,11 @@
import java.util.HashMap
fun HashMap<String, Int?>.set(index: String, elem: Int?) {
this.put(index, elem)
}
fun box(): String {
val s = HashMap<String, Int?>()
s["239"] = 239
return if (s["239"] == 239) "OK" else "Fail"
}
@@ -0,0 +1,9 @@
fun box(): String {
val a = Array<Int>(5, {it})
val x = a.indices.iterator()
while (x.hasNext()) {
val i = x.next()
if (a[i] != i) return "Fail $i ${a[i]}"
}
return "OK"
}
@@ -0,0 +1,9 @@
fun box(): String {
val a = CharArray(5)
val x = a.indices.iterator()
while (x.hasNext()) {
val i = x.next()
if (a[i] != 0.toChar()) return "Fail $i ${a[i]}"
}
return "OK"
}
@@ -0,0 +1,9 @@
fun box(): String {
val x = Array<Int>(5, { it } ).iterator()
var i = 0
while (x.hasNext()) {
if (x.next() != i) return "Fail $i"
i++
}
return "OK"
}
@@ -0,0 +1,10 @@
fun box(): String {
val a = BooleanArray(5)
val x = a.iterator()
var i = 0
while (x.hasNext()) {
if (a[i] != x.next()) return "Fail $i"
i++
}
return "OK"
}
@@ -0,0 +1,10 @@
fun box(): String {
val a = ByteArray(5)
val x = a.iterator()
var i = 0
while (x.hasNext()) {
if (a[i] != x.next()) return "Fail $i"
i++
}
return "OK"
}
@@ -0,0 +1,10 @@
fun box(): String {
val a = ByteArray(5)
val x = a.iterator()
var i = 0
while (x.hasNext()) {
if (a[i] != x.nextByte()) return "Fail $i"
i++
}
return "OK"
}
@@ -0,0 +1,10 @@
fun box(): String {
val a = CharArray(5)
val x = a.iterator()
var i = 0
while (x.hasNext()) {
if (a[i] != x.next()) return "Fail $i"
i++
}
return "OK"
}
@@ -0,0 +1,10 @@
fun box(): String {
val a = DoubleArray(5)
val x = a.iterator()
var i = 0
while (x.hasNext()) {
if (a[i] != x.next()) return "Fail $i"
i++
}
return "OK"
}
@@ -0,0 +1,10 @@
fun box(): String {
val a = FloatArray(5)
val x = a.iterator()
var i = 0
while (x.hasNext()) {
if (a[i] != x.next()) return "Fail $i"
i++
}
return "OK"
}
@@ -0,0 +1,10 @@
fun box(): String {
val a = IntArray(5)
val x = a.iterator()
var i = 0
while (x.hasNext()) {
if (a[i] != x.next()) return "Fail $i"
i++
}
return "OK"
}
@@ -0,0 +1,10 @@
fun box(): String {
val a = LongArray(5)
val x = a.iterator()
var i = 0
while (x.hasNext()) {
if (a[i] != x.next()) return "Fail $i"
i++
}
return "OK"
}
@@ -0,0 +1,10 @@
fun box(): String {
val a = LongArray(5)
val x = a.iterator()
var i = 0
while (x.hasNext()) {
if (a[i] != x.nextLong()) return "Fail $i"
i++
}
return "OK"
}
@@ -0,0 +1,10 @@
fun box(): String {
val a = ShortArray(5)
val x = a.iterator()
var i = 0
while (x.hasNext()) {
if (a[i] != x.next()) return "Fail $i"
i++
}
return "OK"
}
@@ -0,0 +1,9 @@
fun IntArray.set(index: Long, elem: Int) { this[index.toInt()] = elem }
fun IntArray.get(index: Long) = this[index.toInt()]
fun box(): String {
var l = IntArray(1)
l[0.toLong()] = 4
l[0.toLong()] += 6
return if (l[0.toLong()] == 10) "OK" else "Fail"
}
@@ -1,5 +1,3 @@
import java.lang.Integer
open class C { open class C {
open fun f(): Any = "C f" open fun f(): Any = "C f"
} }
@@ -12,12 +12,14 @@ class X {
fun test() { fun test() {
for (i in C()) { for (i in C()) {
System.out.println(i) foo(i)
} }
} }
} }
fun foo(x: Int) {}
fun main(args: Array<String>) { fun main(args: Array<String>) {
X().test() X().test()
} }
@@ -12,12 +12,14 @@ class X {
fun test() { fun test() {
for (i in C()) { for (i in C()) {
System.out.println(i) foo(i)
} }
} }
} }
fun foo(x: Int) {}
fun main(args: Array<String>) { fun main(args: Array<String>) {
X().test() X().test()
} }
@@ -12,12 +12,14 @@ class X {
fun test() { fun test() {
for (i in C()) { for (i in C()) {
System.out.println(i) foo(i)
} }
} }
} }
fun foo(x: Int) {}
fun main(args: Array<String>) { fun main(args: Array<String>) {
X().test() X().test()
} }
@@ -9,7 +9,6 @@ fun box() : String {
for (el in b) { for (el in b) {
sum = sum + (el ?: 0) sum = sum + (el ?: 0)
} }
System.out?.println(sum)
if(sum != 10) return "b failed" if(sum != 10) return "b failed"
return "OK" return "OK"
@@ -4,7 +4,6 @@ fun box() : String {
val processors = Runtime.getRuntime()!!.availableProcessors() val processors = Runtime.getRuntime()!!.availableProcessors()
var threadNum = 1 var threadNum = 1
while(threadNum <= 1024) { while(threadNum <= 1024) {
System.out?.println(threadNum)
if(threadNum < 2 * processors) if(threadNum < 2 * processors)
threadNum += 1 threadNum += 1
else else
@@ -34,9 +34,8 @@ fun box() : String {
a[2*i+1] = -2*i-1 a[2*i+1] = -2*i-1
} }
a.quicksort() a.quicksort()
for(i in 0..9) { for(i in 0..a.size-2) {
System.out?.print(a[i]) if (a[i] > a[i+1]) return "Fail $i: ${a[i]} > ${a[i+1]}"
System.out?.print(' ')
} }
return "OK" return "OK"
} }
@@ -4,7 +4,6 @@ class C() {
fun testReceiver() : String { fun testReceiver() : String {
val res : String = "mama".toMyPrefixedString("111", "222") val res : String = "mama".toMyPrefixedString("111", "222")
System.out?.println(res)
return res return res
} }
@@ -1,7 +1,9 @@
fun foo(x: Int) {}
fun loop(var times : Int) { fun loop(var times : Int) {
while(times > 0) { while(times > 0) {
val u : (value : Int) -> Unit = { val u : (value : Int) -> Unit = {
System.out?.println(it) foo(it)
} }
u(times--) u(times--)
} }
@@ -1,15 +0,0 @@
import A.B.foo
import A.B.x
class A() {
class object {
class B() {
class object {
val x = 1
fun foo() = "2"
}
}
}
}
fun box() = if (x == 1 && foo() == "2") "OK" else "fail"
@@ -1,3 +1,6 @@
// KT-2148
fun f(p: Int?): Int { fun f(p: Int?): Int {
return when(p) { return when(p) {
null -> 3 null -> 3
@@ -6,4 +6,13 @@ fun test(a : A) {
if (a.method != null) { if (a.method != null) {
a.method!!() a.method!!()
} }
} }
class B : A {
override val method = { }
}
fun box(): String {
test(B())
return "OK"
}
@@ -6,4 +6,13 @@ fun test(a : A) {
if (a.method != null) { if (a.method != null) {
a.method!!() a.method!!()
} }
} }
class B : A {
override val method = { }
}
fun box(): String {
test(B())
return "OK"
}
@@ -12,15 +12,14 @@ fun t2() : Boolean {
fun t3() { fun t3() {
val d: D = D("s") val d: D = D("s")
System.out?.println(d?.s) val x = d?.s
System.out?.println(d?.s == "s") //prints true if (!(d?.s == "s")) throw AssertionError()
System.out?.println(d) //ok
} }
fun t4() { fun t4() {
val e: E? = E() val e: E? = E()
System.out?.println(e?.bar() == e) //verify error if (!(e?.bar() == e)) throw AssertionError()
System.out?.println(e?.foo()) //verify error val x = e?.foo()
} }
fun box() : String { fun box() : String {
@@ -1,6 +1,6 @@
import java.util.LinkedList import java.util.ArrayList
open class BaseStringList: LinkedList<String>() { open class BaseStringList: ArrayList<String>() {
} }
class StringList: BaseStringList() { class StringList: BaseStringList() {
@@ -14,6 +14,6 @@ fun box(): String {
myStringList.add("first element") myStringList.add("first element")
if (myStringList.get(0) != "StringList.get()") return "Fail #1" if (myStringList.get(0) != "StringList.get()") return "Fail #1"
if ((myStringList: BaseStringList).get(0) != "StringList.get()") return "Fail #2" if ((myStringList: BaseStringList).get(0) != "StringList.get()") return "Fail #2"
if ((myStringList: LinkedList<String>).get(0) != "StringList.get()") return "Fail #3" if ((myStringList: ArrayList<String>).get(0) != "StringList.get()") return "Fail #3"
return "OK" return "OK"
} }
+14 -12
View File
@@ -1,7 +1,5 @@
package test class List<T>(len: Int) {
val a = Array<T?>(len) { null }
class List<T>(len: Int, cls : java.lang.Class) {
val a : Array<T?> = Array<T?>(len)
fun reverse() { fun reverse() {
var i = 0 var i = 0
@@ -17,19 +15,19 @@ class List<T>(len: Int, cls : java.lang.Class) {
fun box() : String { fun box() : String {
val d = List<Int>(1) val d = List<Int>(1)
d.a[0] = 10 d.a[0] = 10
println(d.a[0]) checkEquals(d.a[0], 10)
val a = List<String>(1) val a = List<String>(1)
a.a[0] = "1" a.a[0] = "1"
println(a.a[0]) checkEquals(a.a[0], "1")
val b = List<Int?>(1) val b = List<Int?>(1)
b.a[0] = 10 b.a[0] = 10
println(b.a[0]) checkEquals(b.a[0], 10)
val c = List<Array<Int>>(1) val c = List<Array<Int>>(1)
c.a[0] = Array<Int>(4,{-1}) c.a[0] = Array<Int>(4,{-1})
println(c.a[0]?.size) checkEquals(c.a[0]?.size, 4)
val e = List<Int>(5) val e = List<Int>(5)
e.a[0] = 0 e.a[0] = 0
@@ -38,12 +36,16 @@ fun box() : String {
e.a[3] = 3 e.a[3] = 3
e.a[4] = 4 e.a[4] = 4
e.reverse() e.reverse()
for(el in e.a) for (i in 0..4)
println(el) checkEquals(e.a[i], 4-i)
return "OK" return "OK"
} }
fun println(s : Any?) { fun checkEquals(a: Any?, b: Any?) {
System.out?.println(s); if (a != b) throw AssertionError("Expected: $b, actual: $a")
}
fun main(args: Array<String>) {
println(box())
} }
@@ -15,7 +15,8 @@ fun box() : String {
for (i in vals.indices) for (i in vals.indices)
for (j in i..vals.lastIndex()) for (j in i..vals.lastIndex())
diffs.add(vals[i] - vals[j]) diffs.add(vals[i] - vals[j])
System.out?.println(diffs.size()) val size = diffs.size()
if (size != 8) return "Fail $size"
return "OK" return "OK"
} }
@@ -1,7 +1,7 @@
import java.util.* import java.util.*
class Template() { class Template() {
val collected = LinkedList<String>() val collected = ArrayList<String>()
fun String.plus() { fun String.plus() {
collected.add(this@plus) collected.add(this@plus)
@@ -16,7 +16,9 @@ class N() : M() {
fun box(): String { fun box(): String {
val n = N() val n = N()
System.out?.println("a: " + n.a + " b: " + n.b + " superb: " + n.superb) n.a
n.b
n.superb
if (n.b == 3 && n.a == 4 && n.superb == 3) return "OK"; if (n.b == 3 && n.a == 4 && n.superb == 3) return "OK";
return "fail"; return "fail";
} }
@@ -23,7 +23,9 @@ class N() : M {
fun box(): String { fun box(): String {
val n = N() val n = N()
System.out?.println("a: " + n.a + " b: " + n.b + " superb: " + n.superb) n.a
n.b
n.superb
if (n.b == 3 && n.a == 4 && n.superb == 3) return "OK"; if (n.b == 3 && n.a == 4 && n.superb == 3) return "OK";
return "fail"; return "fail";
} }
@@ -53,7 +53,6 @@ public class AnnotationGenTest extends CodegenTestCase {
public void testPropSetter() throws NoSuchFieldException, NoSuchMethodException { public void testPropSetter() throws NoSuchFieldException, NoSuchMethodException {
loadText("var x = 0\n" + loadText("var x = 0\n" +
"[Deprecated] set"); "[Deprecated] set");
// System.out.println(generateToText());
Class aClass = generateNamespaceClass(); Class aClass = generateNamespaceClass();
assertNull(aClass.getDeclaredMethod("getX").getAnnotation(Deprecated.class)); assertNull(aClass.getDeclaredMethod("getX").getAnnotation(Deprecated.class));
assertNotNull(aClass.getDeclaredMethod("setX", int.class).getAnnotation(Deprecated.class)); assertNotNull(aClass.getDeclaredMethod("setX", int.class).getAnnotation(Deprecated.class));
@@ -21,25 +21,25 @@ import org.jetbrains.jet.ConfigurationKind;
import java.lang.reflect.Method; import java.lang.reflect.Method;
public class ArrayGenTest extends CodegenTestCase { public class ArrayGenTest extends CodegenTestCase {
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
} }
public void testKt238() throws Exception { public void testKt238() {
blackBoxFile("regressions/kt238.kt"); blackBoxFile("regressions/kt238.kt");
} }
public void testKt326() throws Exception { public void testKt326() {
// blackBoxFile("regressions/kt326.kt"); // Disabled: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.Integer;
// System.out.println(generateToText()); /*
blackBoxFile("regressions/kt326.kt");
*/
} }
public void testKt779() throws Exception { public void testKt779() {
blackBoxFile("regressions/kt779.kt"); blackBoxFile("regressions/kt779.kt");
// System.out.println(generateToText());
} }
public void testCreateMultiInt() throws Exception { public void testCreateMultiInt() throws Exception {
@@ -69,244 +69,141 @@ public class ArrayGenTest extends CodegenTestCase {
loadText("fun foo() = Array<Array<String>> (5, { Array<String>(0,{\"\"}) })"); loadText("fun foo() = Array<Array<String>> (5, { Array<String>(0,{\"\"}) })");
Method foo = generateFunction(); Method foo = generateFunction();
Object invoke = foo.invoke(null); Object invoke = foo.invoke(null);
System.out.println(invoke.getClass());
assertTrue(invoke instanceof Object[]); assertTrue(invoke instanceof Object[]);
} }
public void testCreateMultiGenerics() throws Exception { public void testCreateMultiGenerics() throws Exception {
// loadText("class L<T>() { val a = Array<T?>(5) } fun foo() = L<Int>.a"); // Disabled: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.Integer;
// System.out.println(generateToText()); /*
// Method foo = generateFunction(); loadText("class L<T>() { val a = Array<T?>(5) { null } } fun foo() = L<Int>().a");
// Object invoke = foo.invoke(null); System.out.println(generateToText());
// System.out.println(invoke.getClass()); Method foo = generateFunction();
// assertTrue(invoke.getClass() == Object[].class); Object invoke = foo.invoke(null);
assertTrue(invoke.getClass() == Object[].class);
*/
} }
public void testIntGenerics() throws Exception { public void testIntGenerics() throws Exception {
loadText("class L<T>(var a : T) {} fun foo() = L<Int>(5).a"); loadText("class L<T>(var a : T) {} fun foo() = L<Int>(5).a");
//System.out.println(generateToText());
Method foo = generateFunction(); Method foo = generateFunction();
Object invoke = foo.invoke(null); Object invoke = foo.invoke(null);
System.out.println(invoke.getClass());
assertTrue(invoke instanceof Integer); assertTrue(invoke instanceof Integer);
} }
public void testIterator() throws Exception { public void testIterator() {
loadText("fun box() { val x = Array<Int>(5, { it } ).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }"); blackBoxFile("arrays/iterator.kt");
// System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
} }
public void testPrimitiveIterator() throws Exception { public void testIteratorLongArrayNextLong() {
loadText("fun box() { val x = ByteArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.nextByte()) } }"); blackBoxFile("arrays/iteratorLongArrayNextLong.kt");
// System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
} }
public void testPrimitiveIteratorByte() throws Exception { public void testIteratorByteArrayNextByte() {
loadText("fun box() { for(x in ByteArray(5)) { java.lang.System.out?.println(x) } }"); blackBoxFile("arrays/iteratorByteArrayNextByte.kt");
// System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
} }
public void testPrimitiveIteratorShort() throws Exception { public void testForEachBooleanArray() {
loadText("fun box() { for(x in ShortArray(5)) { java.lang.System.out?.println(x) } }"); blackBoxFile("arrays/forEachBooleanArray.kt");
// System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
} }
public void testPrimitiveIteratorInt() throws Exception { public void testForEachByteArray() {
loadText("fun box() { for(x in IntArray(5)) { java.lang.System.out?.println(x) } }"); blackBoxFile("arrays/forEachByteArray.kt");
// System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
} }
public void testPrimitiveIteratorLong() throws Exception { public void testForEachCharArray() {
loadText("fun box() { for(x in LongArray(5)) { java.lang.System.out?.println(x) } }"); blackBoxFile("arrays/forEachCharArray.kt");
// System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
} }
public void testPrimitiveIteratorFloat() throws Exception { public void testForEachDoubleArray() {
loadText("fun box() { for(x in FloatArray(5)) { java.lang.System.out?.println(x) } }"); blackBoxFile("arrays/forEachDoubleArray.kt");
// System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
} }
public void testPrimitiveIteratorDouble() throws Exception { public void testForEachFloatArray() {
loadText("fun box() { for(x in DoubleArray(5)) { java.lang.System.out?.println(x) } }"); blackBoxFile("arrays/forEachFloatArray.kt");
// System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
} }
public void testPrimitiveIteratorChar() throws Exception { public void testForEachIntArray() {
loadText("fun box() { for(x in CharArray(5)) { java.lang.System.out?.println(x) } }"); blackBoxFile("arrays/forEachIntArray.kt");
// System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
} }
public void testPrimitiveIteratorBoolean() throws Exception { public void testForEachLongArray() {
loadText("fun box() { for(x in BooleanArray(5)) { java.lang.System.out?.println(x) } }"); blackBoxFile("arrays/forEachLongArray.kt");
// System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
} }
public void testLongIterator() throws Exception { public void testForEachShortArray() {
loadText("fun box() { val x = LongArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.nextLong()) } }"); blackBoxFile("arrays/forEachShortArray.kt");
// System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
} }
public void testCharIterator() throws Exception { public void testIteratorBooleanArray() {
loadText("fun box() { val x = CharArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }"); blackBoxFile("arrays/iteratorBooleanArray.kt");
// System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
} }
public void testByteIterator() throws Exception { public void testIteratorByteArray() {
loadText("fun box() { val x = ByteArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }"); blackBoxFile("arrays/iteratorByteArray.kt");
// System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
} }
public void testShortIterator() throws Exception { public void testIteratorCharArray() {
loadText("fun box() { val x = ShortArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }"); blackBoxFile("arrays/iteratorCharArray.kt");
// System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
} }
public void testIntIterator() throws Exception { public void testIteratorDoubleArray() {
loadText("fun box() { val x = IntArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }"); blackBoxFile("arrays/iteratorDoubleArray.kt");
// System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
} }
public void testLongIterator2() throws Exception { public void testIteratorFloatArray() {
loadText("fun box() { val x = LongArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }"); blackBoxFile("arrays/iteratorFloatArray.kt");
// System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
} }
public void testFloatIterator() throws Exception { public void testIteratorIntArray() {
loadText("fun box() { val x = FloatArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }"); blackBoxFile("arrays/iteratorIntArray.kt");
// System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
} }
public void testDoubleIterator() throws Exception { public void testIteratorLongArray() {
loadText("fun box() { val x = ShortArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }"); blackBoxFile("arrays/iteratorLongArray.kt");
// System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
} }
public void testBooleanIterator() throws Exception { public void testIteratorShortArray() {
loadText("fun box() { val x = BooleanArray(5).iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }"); blackBoxFile("arrays/iteratorShortArray.kt");
// System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
} }
public void testArrayIndices() throws Exception { public void testArrayIndices() {
loadText( blackBoxFile("arrays/indices.kt");
"fun box() { val x = Array<Int>(5, {it}).indices.iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }");
// System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
} }
public void testCharIndices() throws Exception { public void testIndicesChar() {
loadText("fun box() { val x = CharArray(5).indices.iterator(); while(x.hasNext()) { java.lang.System.out?.println(x.next()) } }"); blackBoxFile("arrays/indicesChar.kt");
// System.out.println(generateToText());
Method foo = generateFunction();
foo.invoke(null);
} }
public void testCollectionPlusAssign() throws Exception { public void testCollectionPlusAssign() {
blackBoxFile("regressions/kt33.kt"); blackBoxFile("regressions/kt33.kt");
} }
public void testArrayPlusAssign() throws Exception { public void testArrayPlusAssign() {
loadText("fun box() : Int { val s = IntArray(1); s [0] = 5; s[0] += 7; return s[0] }"); blackBoxFile("arrays/arrayPlusAssign.kt");
// System.out.println(generateToText());
Method foo = generateFunction();
assertTrue((Integer) foo.invoke(null) == 12);
} }
public void testCollectionAssignGetMultiIndex() throws Exception { public void testCollectionAssignGetMultiIndex() {
loadText("import java.util.ArrayList\n" + blackBoxFile("arrays/collectionAssignGetMultiIndex.kt");
"fun box() : String { val s = ArrayList<String>(1); s.add(\"\"); s [1, -1] = \"5\"; s[2, -2] += \"7\"; return s[2,-2] }\n" +
"fun ArrayList<String>.get(index1: Int, index2 : Int) = this[index1+index2]!!\n" +
"fun ArrayList<String>.set(index1: Int, index2 : Int, elem: String) { this[index1+index2] = elem }\n");
// System.out.println(generateToText());
Method foo = generateFunction("box");
assertTrue(foo.invoke(null).equals("57"));
} }
public void testArrayGetAssignMultiIndex() throws Exception { public void testArrayGetAssignMultiIndex() {
loadText( blackBoxFile("arrays/arrayGetAssignMultiIndex.kt");
"fun box() : String? { val s = Array<String>(1,{ \"\" }); s [1, -1] = \"5\"; s[2, -2] += \"7\"; return s[-3,3] }\n" +
"fun Array<String>.get(index1: Int, index2 : Int) = this[index1+index2]\n" +
"fun Array<String>.set(index1: Int, index2 : Int, elem: String) { this[index1+index2] = elem\n }");
// System.out.println(generateToText());
Method foo = generateFunction("box");
assertTrue(foo.invoke(null).equals("57"));
} }
public void testCollectionGetMultiIndex() throws Exception { public void testCollectionGetMultiIndex() {
loadText("import java.util.ArrayList\n" + blackBoxFile("arrays/collectionGetMultiIndex.kt");
"fun box() : String { val s = ArrayList<String>(1); s.add(\"\"); s [1, -1] = \"5\"; return s[2, -2] }\n" +
"fun ArrayList<String>.get(index1: Int, index2 : Int) = this[index1+index2]!!\n" +
"fun ArrayList<String>.set(index1: Int, index2 : Int, elem: String) { this[index1+index2] = elem }\n");
// System.out.println(generateToText());
Method foo = generateFunction("box");
assertTrue(foo.invoke(null).equals("5"));
} }
public void testArrayGetMultiIndex() throws Exception { public void testArrayGetMultiIndex() {
loadText( blackBoxFile("arrays/arrayGetMultiIndex.kt");
"fun box() : String? { val s = Array<String>(1,{ \"\" }); s [1, -1] = \"5\"; return s[-2, 2] }\n" +
"fun Array<String>.get(index1: Int, index2 : Int) = this[index1+index2]\n" +
"fun Array<String>.set(index1: Int, index2 : Int, elem: String) { this[index1+index2] = elem\n }");
// System.out.println(generateToText());
Method foo = generateFunction("box");
assertTrue(foo.invoke(null).equals("5"));
} }
public void testMap() throws Exception { public void testHashMap() {
loadText( blackBoxFile("arrays/hashMap.kt");
"fun box() : Int? { val s = java.util.HashMap<String,Int?>(); s[\"239\"] = 239; return s[\"239\"] }\n" +
"fun java.util.HashMap<String,Int?>.set(index: String, elem: Int?) { this.put(index, elem) }");
// System.out.println(generateToText());
Method foo = generateFunction("box");
assertTrue((Integer) foo.invoke(null) == 239);
} }
public void testLongDouble() throws Exception { public void testLongAsIndex() {
loadText( blackBoxFile("arrays/longAsIndex.kt");
"fun box() : Int { var l = IntArray(1); l[0.toLong()] = 4; l[0.toLong()] += 6; return l[0.toLong()];}\n" +
"fun IntArray.set(index: Long, elem: Int) { this[index.toInt()] = elem }\n" +
"fun IntArray.get(index: Long) = this[index.toInt()]");
// System.out.println(generateToText());
Method foo = generateFunction("box");
assertTrue((Integer) foo.invoke(null) == 10);
} }
public void testKt503() { public void testKt503() {
@@ -315,25 +212,21 @@ public class ArrayGenTest extends CodegenTestCase {
public void testKt602() { public void testKt602() {
blackBoxFile("regressions/kt602.kt"); blackBoxFile("regressions/kt602.kt");
// System.out.println(generateToText());
} }
public void testKt950() { public void testKt950() {
blackBoxFile("regressions/kt950.kt"); blackBoxFile("regressions/kt950.kt");
} }
public void testKt594() throws Exception { public void testKt594() {
loadFile("regressions/kt594.kt"); blackBoxFile("regressions/kt594.kt");
// System.out.println(generateToText());
blackBox();
} }
public void testNonNullArray() throws Exception { public void testNonNullArray() {
blackBoxFile("classes/nonnullarray.kt"); blackBoxFile("arrays/nonNullArray.kt");
// System.out.println(generateToText());
} }
public void testArrayCast() throws Exception { public void testArrayCast() {
blackBoxFile("regressions/kt2997.kt"); blackBoxFile("regressions/kt2997.kt");
} }
} }
@@ -19,184 +19,153 @@ package org.jetbrains.jet.codegen;
import org.jetbrains.jet.ConfigurationKind; import org.jetbrains.jet.ConfigurationKind;
public class BridgeMethodGenTest extends CodegenTestCase { public class BridgeMethodGenTest extends CodegenTestCase {
@Override
public void testBridgeMethod () throws Exception { protected void setUp() throws Exception {
super.setUp();
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridge.kt"); }
public void testOverrideReturnType() {
blackBoxFile("bridges/overrideReturnType.kt");
} }
public void testKt1959() { public void testKt1959() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt1959.kt"); blackBoxFile("regressions/kt1959.kt");
} }
public void testDelegation() { public void testDelegation() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/delegation.kt"); blackBoxFile("bridges/delegation.kt");
} }
public void testDelegationProperty() { public void testDelegationProperty() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/delegationProperty.kt"); blackBoxFile("bridges/delegationProperty.kt");
} }
public void testDelegationToTraitImpl() { public void testDelegationToTraitImpl() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/delegationToTraitImpl.kt"); blackBoxFile("bridges/delegationToTraitImpl.kt");
} }
public void testDiamond() { public void testDiamond() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/diamond.kt"); blackBoxFile("bridges/diamond.kt");
} }
public void testLongChainOneBridge() { public void testLongChainOneBridge() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/longChainOneBridge.kt"); blackBoxFile("bridges/longChainOneBridge.kt");
} }
public void testManyTypeArgumentsSubstitutedSuccessively() { public void testManyTypeArgumentsSubstitutedSuccessively() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/manyTypeArgumentsSubstitutedSuccessively.kt"); blackBoxFile("bridges/manyTypeArgumentsSubstitutedSuccessively.kt");
} }
public void testMethodFromTrait() { public void testMethodFromTrait() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/methodFromTrait.kt"); blackBoxFile("bridges/methodFromTrait.kt");
} }
public void testOverrideAbstractProperty() { public void testOverrideAbstractProperty() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/overrideAbstractProperty.kt"); blackBoxFile("bridges/overrideAbstractProperty.kt");
} }
public void testSimple() { public void testSimple() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/simple.kt"); blackBoxFile("bridges/simple.kt");
} }
public void testSimpleEnum() { public void testSimpleEnum() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/simpleEnum.kt"); blackBoxFile("bridges/simpleEnum.kt");
} }
public void testSimpleGenericMethod() { public void testSimpleGenericMethod() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/simpleGenericMethod.kt"); blackBoxFile("bridges/simpleGenericMethod.kt");
} }
public void testSimpleObject() { public void testSimpleObject() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/simpleObject.kt"); blackBoxFile("bridges/simpleObject.kt");
} }
public void testSimpleReturnType() { public void testSimpleReturnType() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/simpleReturnType.kt"); blackBoxFile("bridges/simpleReturnType.kt");
} }
public void testSimpleUpperBound() { public void testSimpleUpperBound() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/simpleUpperBound.kt"); blackBoxFile("bridges/simpleUpperBound.kt");
} }
public void testSubstitutionInSuperClass() { public void testSubstitutionInSuperClass() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/substitutionInSuperClass.kt"); blackBoxFile("bridges/substitutionInSuperClass.kt");
} }
public void testSubstitutionInSuperClassDelegation() { public void testSubstitutionInSuperClassDelegation() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/substitutionInSuperClassDelegation.kt"); blackBoxFile("bridges/substitutionInSuperClassDelegation.kt");
} }
public void testSubstitutionInSuperClassAbstractFun() { public void testSubstitutionInSuperClassAbstractFun() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/substitutionInSuperClassAbstractFun.kt"); blackBoxFile("bridges/substitutionInSuperClassAbstractFun.kt");
} }
public void testSubstitutionInSuperClassBoundedTypeArguments() { public void testSubstitutionInSuperClassBoundedTypeArguments() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/substitutionInSuperClassBoundedTypeArguments.kt"); blackBoxFile("bridges/substitutionInSuperClassBoundedTypeArguments.kt");
} }
public void testSubstitutionInSuperClassEnum() { public void testSubstitutionInSuperClassEnum() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/substitutionInSuperClassEnum.kt"); blackBoxFile("bridges/substitutionInSuperClassEnum.kt");
} }
public void testSubstitutionInSuperClassGenericMethod() { public void testSubstitutionInSuperClassGenericMethod() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/substitutionInSuperClassGenericMethod.kt"); blackBoxFile("bridges/substitutionInSuperClassGenericMethod.kt");
} }
public void testSubstitutionInSuperClassObject() { public void testSubstitutionInSuperClassObject() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/substitutionInSuperClassObject.kt"); blackBoxFile("bridges/substitutionInSuperClassObject.kt");
} }
public void testSubstitutionInSuperClassUpperBound() { public void testSubstitutionInSuperClassUpperBound() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/substitutionInSuperClassUpperBound.kt"); blackBoxFile("bridges/substitutionInSuperClassUpperBound.kt");
} }
public void testTwoParentsWithDifferentMethodsTwoBridges() { public void testTwoParentsWithDifferentMethodsTwoBridges() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/twoParentsWithDifferentMethodsTwoBridges.kt"); blackBoxFile("bridges/twoParentsWithDifferentMethodsTwoBridges.kt");
} }
public void testTwoParentsWithTheSameMethodOneBridge() { public void testTwoParentsWithTheSameMethodOneBridge() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/twoParentsWithTheSameMethodOneBridge.kt"); blackBoxFile("bridges/twoParentsWithTheSameMethodOneBridge.kt");
} }
public void testKt2498() { public void testKt2498() {
createEnvironmentWithFullJdk();
blackBoxFile("regressions/kt2498.kt"); blackBoxFile("regressions/kt2498.kt");
} }
public void testKt1939() { public void testKt1939() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt1939.kt"); blackBoxFile("regressions/kt1939.kt");
} }
public void testKt2702() { public void testKt2702() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt2702.kt"); blackBoxFile("regressions/kt2702.kt");
} }
public void testKt2920() { public void testKt2920() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt2920.kt"); blackBoxFile("regressions/kt2920.kt");
} }
public void testSubstitutionInSuperClassProperty() { public void testSubstitutionInSuperClassProperty() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/substitutionInSuperClassProperty.kt"); blackBoxFile("bridges/substitutionInSuperClassProperty.kt");
} }
public void testPropertySetter() { public void testPropertySetter() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/propertySetter.kt"); blackBoxFile("bridges/propertySetter.kt");
} }
public void testPropertyDiamond() { public void testPropertyDiamond() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/propertyDiamond.kt"); blackBoxFile("bridges/propertyDiamond.kt");
} }
public void testPropertyAccessorsWithoutBody() { public void testPropertyAccessorsWithoutBody() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/propertyAccessorsWithoutBody.kt"); blackBoxFile("bridges/propertyAccessorsWithoutBody.kt");
} }
public void testPropertyInConstructor() { public void testPropertyInConstructor() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("bridges/propertyInConstructor.kt"); blackBoxFile("bridges/propertyInConstructor.kt");
} }
public void testKt2833() { public void testKt2833() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt2833.kt"); blackBoxFile("regressions/kt2833.kt");
} }
} }
@@ -19,44 +19,41 @@ package org.jetbrains.jet.codegen;
import org.jetbrains.jet.ConfigurationKind; import org.jetbrains.jet.ConfigurationKind;
public class ClosuresGenTest extends CodegenTestCase { public class ClosuresGenTest extends CodegenTestCase {
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
} }
public void testSimplestClosure() throws Exception { public void testSimplestClosure() {
blackBoxFile("classes/simplestClosure.kt"); blackBoxFile("classes/simplestClosure.kt");
// System.out.println(generateToText());
} }
public void testSimplestClosureAndBoxing() throws Exception { public void testSimplestClosureAndBoxing() {
blackBoxFile("classes/simplestClosureAndBoxing.kt"); blackBoxFile("classes/simplestClosureAndBoxing.kt");
} }
public void testClosureWithParameter() throws Exception { public void testClosureWithParameter() {
blackBoxFile("classes/closureWithParameter.kt"); blackBoxFile("classes/closureWithParameter.kt");
} }
public void testClosureWithParameterAndBoxing() throws Exception { public void testClosureWithParameterAndBoxing() {
blackBoxFile("classes/closureWithParameterAndBoxing.kt"); blackBoxFile("classes/closureWithParameterAndBoxing.kt");
} }
public void testExtensionClosure() throws Exception { public void testExtensionClosure() {
blackBoxFile("classes/extensionClosure.kt"); blackBoxFile("classes/extensionClosure.kt");
} }
public void testEnclosingLocalVariable() throws Exception { public void testEnclosingLocalVariable() {
blackBoxFile("classes/enclosingLocalVariable.kt"); blackBoxFile("classes/enclosingLocalVariable.kt");
// System.out.println(generateToText());
} }
public void testDoubleEnclosedLocalVariable() throws Exception { public void testDoubleEnclosedLocalVariable() {
blackBoxFile("classes/doubleEnclosedLocalVariable.kt"); blackBoxFile("classes/doubleEnclosedLocalVariable.kt");
} }
public void testEnclosingThis() throws Exception { public void testEnclosingThis() {
blackBoxFile("classes/enclosingThis.kt"); blackBoxFile("classes/enclosingThis.kt");
} }
@@ -18,32 +18,31 @@ package org.jetbrains.jet.codegen;
import org.jetbrains.jet.ConfigurationKind; import org.jetbrains.jet.ConfigurationKind;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
public class ControlStructuresTest extends CodegenTestCase { public class ControlStructuresTest extends CodegenTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
}
@Override @Override
protected String getPrefix() { protected String getPrefix() {
return "controlStructures"; return "controlStructures";
} }
public void testIf() throws Exception { public void testIf() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadFile(); loadFile();
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
assertEquals(15, main.invoke(null, true)); assertEquals(15, main.invoke(null, true));
assertEquals(20, main.invoke(null, false)); assertEquals(20, main.invoke(null, false));
} }
public void testSingleBranchIf() throws Exception { public void testSingleBranchIf() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadFile(); loadFile();
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
assertEquals(15, main.invoke(null, true)); assertEquals(15, main.invoke(null, true));
assertEquals(20, main.invoke(null, false)); assertEquals(20, main.invoke(null, false));
@@ -61,43 +60,32 @@ public class ControlStructuresTest extends CodegenTestCase {
factorialTest("controlStructures/break.kt"); factorialTest("controlStructures/break.kt");
} }
/* public void testInRangeConditionsInWhen() {
public void testInRangeConditionsInWhen() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("controlStructures/inRangeConditionsInWhen.kt"); blackBoxFile("controlStructures/inRangeConditionsInWhen.kt");
} }
*/
private void factorialTest(final String name) throws IllegalAccessException, InvocationTargetException { private void factorialTest(String name) throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadFile(name); loadFile(name);
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
assertEquals(6, main.invoke(null, 3)); assertEquals(6, main.invoke(null, 3));
assertEquals(120, main.invoke(null, 5)); assertEquals(120, main.invoke(null, 5));
} }
public void testContinue() throws Exception { public void testContinue() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadFile(); loadFile();
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
assertEquals(3, main.invoke(null, 4)); assertEquals(3, main.invoke(null, 4));
assertEquals(7, main.invoke(null, 5)); assertEquals(7, main.invoke(null, 5));
} }
public void testIfNoElse() throws Exception { public void testIfNoElse() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadFile(); loadFile();
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
assertEquals(5, main.invoke(null, 5, true)); assertEquals(5, main.invoke(null, 5, true));
assertEquals(10, main.invoke(null, 5, false)); assertEquals(10, main.invoke(null, 5, false));
} }
public void testCondJumpOnStack() throws Exception { public void testCondJumpOnStack() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("import java.lang.Boolean as jlBoolean; fun foo(a: String): Int = if (jlBoolean.parseBoolean(a)) 5 else 10"); loadText("import java.lang.Boolean as jlBoolean; fun foo(a: String): Int = if (jlBoolean.parseBoolean(a)) 5 else 10");
final Method main = generateFunction(); final Method main = generateFunction();
assertEquals(5, main.invoke(null, "true")); assertEquals(5, main.invoke(null, "true"));
@@ -105,18 +93,14 @@ public class ControlStructuresTest extends CodegenTestCase {
} }
public void testFor() throws Exception { public void testFor() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_AND_ANNOTATIONS);
loadFile(); loadFile();
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
List<String> args = Arrays.asList("IntelliJ", " ", "IDEA"); List<String> args = Arrays.asList("IntelliJ", " ", "IDEA");
assertEquals("IntelliJ IDEA", main.invoke(null, args)); assertEquals("IntelliJ IDEA", main.invoke(null, args));
} }
public void testIfBlock() throws Exception { public void testIfBlock() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_AND_ANNOTATIONS);
loadFile(); loadFile();
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
List<String> args = Arrays.asList("IntelliJ", " ", "IDEA"); List<String> args = Arrays.asList("IntelliJ", " ", "IDEA");
assertEquals("TTT", main.invoke(null, args)); assertEquals("TTT", main.invoke(null, args));
@@ -125,16 +109,13 @@ public class ControlStructuresTest extends CodegenTestCase {
} }
public void testForInArray() throws Exception { public void testForInArray() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadFile(); loadFile();
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
String[] args = new String[] { "IntelliJ", " ", "IDEA" }; String[] args = new String[] { "IntelliJ", " ", "IDEA" };
assertEquals("IntelliJ IDEA", main.invoke(null, new Object[] { args })); assertEquals("IntelliJ IDEA", main.invoke(null, new Object[] { args }));
} }
public void testForInRange() throws Exception { public void testForInRange() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("fun foo(sb: StringBuilder) { for(x in 1..4) sb.append(x) }"); loadText("fun foo(sb: StringBuilder) { for(x in 1..4) sb.append(x) }");
final Method main = generateFunction(); final Method main = generateFunction();
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
@@ -143,96 +124,66 @@ public class ControlStructuresTest extends CodegenTestCase {
} }
public void testThrowCheckedException() throws Exception { public void testThrowCheckedException() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("fun foo() { throw Exception(); }"); loadText("fun foo() { throw Exception(); }");
final Method main = generateFunction(); final Method main = generateFunction();
boolean caught = false; assertThrows(main, Exception.class, null);
try {
main.invoke(null);
} catch (InvocationTargetException e) {
if (e.getTargetException().getClass() == Exception.class) {
caught = true;
}
}
assertTrue(caught);
} }
public void testTryCatch() throws Exception { public void testTryCatch() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadFile(); loadFile();
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
assertEquals("no message", main.invoke(null, "0")); assertEquals("no message", main.invoke(null, "0"));
assertEquals("For input string: \"a\"", main.invoke(null, "a")); assertEquals("For input string: \"a\"", main.invoke(null, "a"));
} }
public void testTryFinally() throws Exception { public void testTryFinally() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadFile(); loadFile();
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
main.invoke(null, sb, "9"); main.invoke(null, sb, "9");
assertEquals("foo9bar", sb.toString()); assertEquals("foo9bar", sb.toString());
sb = new StringBuilder(); sb = new StringBuilder();
boolean caught = false; assertThrows(main, NumberFormatException.class, null, sb, "x");
try {
main.invoke(null, sb, "x");
}
catch(InvocationTargetException e) {
caught = e.getTargetException() instanceof NumberFormatException;
}
assertTrue(caught);
assertEquals("foobar", sb.toString()); assertEquals("foobar", sb.toString());
} }
public void testForUserType() throws Exception { public void testForUserType() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("controlStructures/forUserType.kt"); blackBoxFile("controlStructures/forUserType.kt");
} }
public void testForLoopMemberExtensionNext() throws Exception { public void testForLoopMemberExtensionNext() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("controlStructures/forLoopMemberExtensionNext.kt"); blackBoxFile("controlStructures/forLoopMemberExtensionNext.kt");
} }
public void testForLoopMemberExtensionHasNext() throws Exception { public void testForLoopMemberExtensionHasNext() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("controlStructures/forLoopMemberExtensionHasNext.kt"); blackBoxFile("controlStructures/forLoopMemberExtensionHasNext.kt");
} }
public void testForLoopMemberExtensionAll() throws Exception { public void testForLoopMemberExtensionAll() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("controlStructures/forLoopMemberExtensionAll.kt"); blackBoxFile("controlStructures/forLoopMemberExtensionAll.kt");
} }
public void testForIntArray() throws Exception { public void testForIntArray() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("controlStructures/forIntArray.kt"); blackBoxFile("controlStructures/forIntArray.kt");
} }
public void testForPrimitiveIntArray() throws Exception { public void testForPrimitiveIntArray() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("controlStructures/forPrimitiveIntArray.kt"); blackBoxFile("controlStructures/forPrimitiveIntArray.kt");
} }
public void testForNullableIntArray() throws Exception { public void testForNullableIntArray() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("controlStructures/forNullableIntArray.kt"); blackBoxFile("controlStructures/forNullableIntArray.kt");
} }
public void testForIntRange() { public void testForIntRange() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("controlStructures/forIntRange.kt"); blackBoxFile("controlStructures/forIntRange.kt");
} }
public void testKt237() throws Exception { public void testKt237() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt237.kt"); blackBoxFile("regressions/kt237.kt");
} }
public void testCompareToZero() throws Exception { public void testCompareToZero() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("fun foo(a: Int, b: Int): Boolean = a == 0 && b != 0 && 0 == a && 0 != b"); loadText("fun foo(a: Int, b: Int): Boolean = a == 0 && b != 0 && 0 == a && 0 != b");
String text = generateToText(); String text = generateToText();
/* /*
@@ -248,247 +199,171 @@ public class ControlStructuresTest extends CodegenTestCase {
} }
public void testCompareBoxedIntegerToZero() { public void testCompareBoxedIntegerToZero() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("controlStructures/compareBoxedIntegerToZero.kt"); blackBoxFile("controlStructures/compareBoxedIntegerToZero.kt");
} }
public void testCompareToNull() throws Exception { public void testCompareToNull() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("fun foo(a: String?, b: String?): Boolean = a == null && b !== null && null == a && null !== b"); loadText("fun foo(a: String?, b: String?): Boolean = a == null && b !== null && null == a && null !== b");
String text = generateToText(); String text = generateToText();
assertTrue(!text.contains("java/lang/Object.equals")); assertTrue(!text.contains("java/lang/Object.equals"));
//System.out.println(text);
final Method main = generateFunction(); final Method main = generateFunction();
assertEquals(true, main.invoke(null, null, "lala")); assertEquals(true, main.invoke(null, null, "lala"));
assertEquals(false, main.invoke(null, null, null)); assertEquals(false, main.invoke(null, null, null));
} }
public void testCompareToNonnullableEq() throws Exception { public void testCompareToNonnullableEq() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("fun foo(a: String?, b: String): Boolean = a == b || b == a"); loadText("fun foo(a: String?, b: String): Boolean = a == b || b == a");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
assertEquals(false, main.invoke(null, null, "lala")); assertEquals(false, main.invoke(null, null, "lala"));
assertEquals(true, main.invoke(null, "papa", "papa")); assertEquals(true, main.invoke(null, "papa", "papa"));
} }
public void testCompareToNonnullableNotEq() throws Exception { public void testCompareToNonnullableNotEq() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("fun foo(a: String?, b: String): Boolean = a != b"); loadText("fun foo(a: String?, b: String): Boolean = a != b");
String text = generateToText(); String text = generateToText();
// System.out.println(text);
assertTrue(text.contains("IXOR")); assertTrue(text.contains("IXOR"));
final Method main = generateFunction(); final Method main = generateFunction();
assertEquals(true, main.invoke(null, null, "lala")); assertEquals(true, main.invoke(null, null, "lala"));
assertEquals(false, main.invoke(null, "papa", "papa")); assertEquals(false, main.invoke(null, "papa", "papa"));
} }
public void testKt299() throws Exception { public void testKt299() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt299.kt"); blackBoxFile("regressions/kt299.kt");
} }
public void testKt416() throws Exception { public void testKt416() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt416.kt"); blackBoxFile("regressions/kt416.kt");
// System.out.println(generateToText());
} }
public void testKt513() throws Exception { public void testKt513() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt513.kt"); blackBoxFile("regressions/kt513.kt");
} }
public void testKt434() throws Exception { public void testKt769() {
createEnvironmentWithFullJdk();
blackBoxFile("regressions/kt434.kt");
}
public void testKt769() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt769.kt"); blackBoxFile("regressions/kt769.kt");
// System.out.println(generateToText());
} }
public void testKt773() throws Exception { public void testKt773() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt773.kt"); blackBoxFile("regressions/kt773.kt");
// System.out.println(generateToText());
} }
public void testKt772() throws Exception { public void testKt772() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt772.kt"); blackBoxFile("regressions/kt772.kt");
// System.out.println(generateToText());
} }
public void testKt870() throws Exception { public void testKt870() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt870.kt"); blackBoxFile("regressions/kt870.kt");
// System.out.println(generateToText());
} }
public void testKt958() throws Exception { public void testKt958() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt958.kt"); blackBoxFile("regressions/kt958.kt");
// System.out.println(generateToText());
} }
public void testQuicksort() throws Exception { public void testQuicksort() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("controlStructures/quicksort.kt"); blackBoxFile("controlStructures/quicksort.kt");
// System.out.println(generateToText());
} }
public void testSynchronized() throws Exception { public void testKt998() {
createEnvironmentWithFullJdk();
blackBoxFile("controlStructures/sync.kt");
// System.out.println(generateToText());
}
public void testIfInWhile() throws Exception {
createEnvironmentWithFullJdk();
blackBoxFile("controlStructures/ifInWhile.kt");
// System.out.println(generateToText());
}
public void testKt1076() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.ALL);
blackBoxFile("regressions/kt1076.kt");
}
public void testKt998() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt998.kt"); blackBoxFile("regressions/kt998.kt");
} }
public void testContinueInFor() throws Exception { public void testContinueInFor() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_AND_ANNOTATIONS);
blackBoxFile("controlStructures/continueInFor.kt"); blackBoxFile("controlStructures/continueInFor.kt");
} }
public void testContinueToLabelInFor() throws Exception { public void testContinueToLabelInFor() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_AND_ANNOTATIONS);
blackBoxFile("controlStructures/continueToLabelInFor.kt"); blackBoxFile("controlStructures/continueToLabelInFor.kt");
} }
public void testKt628() throws Exception { public void testKt628() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt628.kt"); blackBoxFile("regressions/kt628.kt");
} }
public void testKt1441() throws Exception { public void testKt1441() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt1441.kt"); blackBoxFile("regressions/kt1441.kt");
} }
public void testKt2147() throws Exception { public void testKt2147() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt2147.kt"); blackBoxFile("regressions/kt2147.kt");
} }
public void testIfDummy() { public void testIfDummy() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt1899.kt"); blackBoxFile("regressions/kt1899.kt");
} }
public void testKt1742() { public void testKt1742() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt1742.kt"); blackBoxFile("regressions/kt1742.kt");
} }
public void testKt2062() { public void testKt2062() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt2062.kt"); blackBoxFile("regressions/kt2062.kt");
} }
public void testKt910() { public void testKt910() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt910.kt"); blackBoxFile("regressions/kt910.kt");
} }
public void testKt1688() { public void testKt1688() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt1688.kt"); blackBoxFile("regressions/kt1688.kt");
} }
public void testKt2423() {
createEnvironmentWithFullJdk();
blackBoxFile("regressions/kt2423.kt");
}
public void testKt2416() { public void testKt2416() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt2416.kt"); blackBoxFile("regressions/kt2416.kt");
} }
public void testKt2291() { public void testKt2291() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt2291.kt"); blackBoxFile("regressions/kt2291.kt");
} }
public void testKt2259() { public void testKt2259() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt2259.kt"); blackBoxFile("regressions/kt2259.kt");
} }
public void testKt2577() { public void testKt2577() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt2577.kt"); blackBoxFile("regressions/kt2577.kt");
} }
public void testTryCatchFinallyChain() { public void testTryCatchFinallyChain() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("controlStructures/tryCatchFinallyChain.kt"); blackBoxFile("controlStructures/tryCatchFinallyChain.kt");
} }
public void testKt2597() { public void testKt2597() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt2597.kt"); blackBoxFile("regressions/kt2597.kt");
} }
public void testKt2598() { public void testKt2598() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt2598.kt"); blackBoxFile("regressions/kt2598.kt");
} }
public void testLongRange() { public void testLongRange() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("controlStructures/longRange.kt"); blackBoxFile("controlStructures/longRange.kt");
} }
public void testForInSmartCastedToArray() { public void testForInSmartCastedToArray() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("controlStructures/forInSmartCastedToArray.kt"); blackBoxFile("controlStructures/forInSmartCastedToArray.kt");
} }
public void testConditionOfEmptyIf() { public void testConditionOfEmptyIf() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("controlStructures/conditionOfEmptyIf.kt"); blackBoxFile("controlStructures/conditionOfEmptyIf.kt");
} }
public void testFinallyOnEmptyReturn() { public void testFinallyOnEmptyReturn() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("controlStructures/finallyOnEmptyReturn.kt"); blackBoxFile("controlStructures/finallyOnEmptyReturn.kt");
} }
public void testKt3087() { public void testKt3087() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt3087.kt"); blackBoxFile("regressions/kt3087.kt");
} }
public void testKt3203_1() { public void testKt3203_1() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt3203_1.kt"); blackBoxFile("regressions/kt3203_1.kt");
} }
public void testKt3203_2() { public void testKt3203_2() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt3203_2.kt"); blackBoxFile("regressions/kt3203_2.kt");
} }
public void testKt3273() { public void testKt3273() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt3273.kt"); blackBoxFile("regressions/kt3273.kt");
} }
} }
@@ -65,11 +65,11 @@ public class EnumGenTest extends CodegenTestCase {
assertEquals(0xFF0000, rgbMethod.invoke(redValue)); assertEquals(0xFF0000, rgbMethod.invoke(redValue));
} }
public void testSimple() throws NoSuchFieldException, IllegalAccessException { public void testSimple() {
blackBoxFile("enum/simple.kt"); blackBoxFile("enum/simple.kt");
} }
public void testSimpleEnumInPackage() throws NoSuchFieldException, IllegalAccessException { public void testSimpleEnumInPackage() {
blackBoxFile("enum/inPackage.kt"); blackBoxFile("enum/inPackage.kt");
} }
@@ -89,16 +89,15 @@ public class EnumGenTest extends CodegenTestCase {
blackBoxFile("enum/ordinal.kt"); blackBoxFile("enum/ordinal.kt");
} }
public void testValues() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { public void testValues() {
blackBoxFile("enum/valueof.kt"); blackBoxFile("enum/valueof.kt");
} }
public void testInClassObj() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException { public void testInClassObj() {
blackBoxFile("enum/inclassobj.kt"); blackBoxFile("enum/inclassobj.kt");
} }
public void testAbstractMethod() public void testAbstractMethod() {
throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
blackBoxFile("enum/abstractmethod.kt"); blackBoxFile("enum/abstractmethod.kt");
} }
@@ -21,13 +21,18 @@ import org.jetbrains.jet.ConfigurationKind;
import java.lang.reflect.Method; import java.lang.reflect.Method;
public class ExtensionFunctionsTest extends CodegenTestCase { public class ExtensionFunctionsTest extends CodegenTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
}
@Override @Override
protected String getPrefix() { protected String getPrefix() {
return "extensionFunctions"; return "extensionFunctions";
} }
public void testSimple() throws Exception { public void testSimple() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadFile(); loadFile();
final Method foo = generateFunction("foo"); final Method foo = generateFunction("foo");
final Character c = (Character) foo.invoke(null); final Character c = (Character) foo.invoke(null);
@@ -35,71 +40,52 @@ public class ExtensionFunctionsTest extends CodegenTestCase {
} }
public void testWhenFail() throws Exception { public void testWhenFail() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadFile(); loadFile();
// System.out.println(generateToText());
Method foo = generateFunction("foo"); Method foo = generateFunction("foo");
assertThrows(foo, Exception.class, null, new StringBuilder()); assertThrows(foo, Exception.class, null, new StringBuilder());
} }
public void testVirtual() throws Exception { public void testVirtual() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("extensionFunctions/virtual.kt"); blackBoxFile("extensionFunctions/virtual.kt");
} }
public void testShared() throws Exception { public void testShared() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("extensionFunctions/shared.kt"); blackBoxFile("extensionFunctions/shared.kt");
// System.out.println(generateToText());
} }
public void testKt475() throws Exception { public void testKt475() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt475.kt"); blackBoxFile("regressions/kt475.kt");
} }
public void testKtNested() throws Exception { public void testKt865() {
createEnvironmentWithFullJdk();
blackBoxFile("extensionFunctions/nested.kt");
}
public void testKt865() throws Exception {
createEnvironmentWithFullJdk();
blackBoxFile("regressions/kt865.kt"); blackBoxFile("regressions/kt865.kt");
} }
public void testKtNested2() throws Exception { public void testKtNested2() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("extensionFunctions/nested2.kt"); blackBoxFile("extensionFunctions/nested2.kt");
} }
public void testKt606() throws Exception { public void testKt606() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt606.kt"); blackBoxFile("regressions/kt606.kt");
} }
public void testKt1061() throws Exception { public void testKt1061() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt1061.kt"); blackBoxFile("regressions/kt1061.kt");
} }
public void testKt1249() throws Exception { public void testKt1249() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt1249.kt"); blackBoxFile("regressions/kt1249.kt");
} }
public void testKt1290() throws Exception { public void testKt1290() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt1290.kt"); blackBoxFile("regressions/kt1290.kt");
} }
public void testKt1953() throws Exception { public void testKt1953() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt1953.kt"); blackBoxFile("regressions/kt1953.kt");
} }
public void testKt1953Class() throws Exception { public void testKt1953Class() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt1953_class.kt"); blackBoxFile("regressions/kt1953_class.kt");
} }
} }
@@ -0,0 +1,49 @@
/*
* Copyright 2010-2013 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;
public class FullJdkCodegenTest extends CodegenTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
createEnvironmentWithFullJdk();
}
public void testKt434() {
blackBoxFile("regressions/kt434.kt");
}
public void testSynchronized() {
blackBoxFile("controlStructures/sync.kt");
}
public void testIfInWhile() {
blackBoxFile("controlStructures/ifInWhile.kt");
}
public void testKt2423() {
blackBoxFile("regressions/kt2423.kt");
}
public void testKt2509() {
blackBoxFile("regressions/kt2509.kt");
}
public void testIntCountDownLatchExtension() {
blackBoxFile("extensionFunctions/intCountDownLatchExtension.kt");
}
}
@@ -29,39 +29,32 @@ public class FunctionGenTest extends CodegenTestCase {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
} }
public void testKt2716() throws Exception { public void testKt2716() {
blackBoxFile("regressions/kt2716.kt"); blackBoxFile("regressions/kt2716.kt");
// System.out.println(generateToText());
} }
public void testDefaultArgs() throws Exception { public void testDefaultArgs() {
blackBoxFile("functions/defaultargs.kt"); blackBoxFile("functions/defaultargs.kt");
// System.out.println(generateToText());
} }
public void testDefaultArgs1() throws Exception { public void testDefaultArgs1() {
blackBoxFile("functions/defaultargs1.kt"); blackBoxFile("functions/defaultargs1.kt");
// System.out.println(generateToText());
} }
public void testDefaultArgs2() throws Exception { public void testDefaultArgs2() {
blackBoxFile("functions/defaultargs2.kt"); blackBoxFile("functions/defaultargs2.kt");
// System.out.println(generateToText());
} }
public void testDefaultArgs3() throws Exception { public void testDefaultArgs3() {
blackBoxFile("functions/defaultargs3.kt"); blackBoxFile("functions/defaultargs3.kt");
// System.out.println(generateToText());
} }
public void testDefaultArgs4() throws Exception { public void testDefaultArgs4() {
blackBoxFile("functions/defaultargs4.kt"); blackBoxFile("functions/defaultargs4.kt");
// System.out.println(generateToText());
} }
public void testDefaultArgs5() throws Exception { public void testDefaultArgs5() {
blackBoxFile("functions/defaultargs5.kt"); blackBoxFile("functions/defaultargs5.kt");
// System.out.println(generateToText());
} }
public void testDefaultArgs6() { public void testDefaultArgs6() {
@@ -72,14 +65,12 @@ public class FunctionGenTest extends CodegenTestCase {
blackBoxFile("functions/defaultargs7.kt"); blackBoxFile("functions/defaultargs7.kt");
} }
public void testNoThisNoClosure() throws Exception { public void testNoThisNoClosure() {
blackBoxFile("functions/nothisnoclosure.kt"); blackBoxFile("functions/nothisnoclosure.kt");
// System.out.println(generateToText());
} }
public void testAnyEqualsNullable() throws InvocationTargetException, IllegalAccessException { public void testAnyEqualsNullable() throws InvocationTargetException, IllegalAccessException {
loadText("fun foo(x: Any?) = x.equals(\"lala\")"); loadText("fun foo(x: Any?) = x.equals(\"lala\")");
// System.out.println(generateToText());
Method foo = generateFunction(); Method foo = generateFunction();
assertTrue((Boolean) foo.invoke(null, "lala")); assertTrue((Boolean) foo.invoke(null, "lala"));
assertFalse((Boolean) foo.invoke(null, "mama")); assertFalse((Boolean) foo.invoke(null, "mama"));
@@ -87,7 +78,6 @@ public class FunctionGenTest extends CodegenTestCase {
public void testNoRefToOuter() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException { public void testNoRefToOuter() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException {
loadText("class A() { fun f() : ()->String { val s = \"OK\"; return { -> s } } }"); loadText("class A() { fun f() : ()->String { val s = \"OK\"; return { -> s } } }");
// System.out.println(generateToText());
Class foo = generateClass("A"); Class foo = generateClass("A");
final Object obj = foo.newInstance(); final Object obj = foo.newInstance();
final Method f = foo.getMethod("f"); final Method f = foo.getMethod("f");
@@ -100,7 +90,6 @@ public class FunctionGenTest extends CodegenTestCase {
public void testAnyEquals() throws InvocationTargetException, IllegalAccessException { public void testAnyEquals() throws InvocationTargetException, IllegalAccessException {
loadText("fun foo(x: Any) = x.equals(\"lala\")"); loadText("fun foo(x: Any) = x.equals(\"lala\")");
// System.out.println(generateToText());
Method foo = generateFunction(); Method foo = generateFunction();
assertTrue((Boolean) foo.invoke(null, "lala")); assertTrue((Boolean) foo.invoke(null, "lala"));
assertFalse((Boolean) foo.invoke(null, "mama")); assertFalse((Boolean) foo.invoke(null, "mama"));
@@ -124,14 +113,13 @@ public class FunctionGenTest extends CodegenTestCase {
public void testKt1199() { public void testKt1199() {
blackBoxFile("regressions/kt1199.kt"); blackBoxFile("regressions/kt1199.kt");
//System.out.println(generateToText());
} }
public void testFunction() throws InvocationTargetException, IllegalAccessException { public void testFunction() {
blackBoxFile("functions/functionExpression.kt"); blackBoxFile("functions/functionExpression.kt");
} }
public void testLocalFunction() throws InvocationTargetException, IllegalAccessException { public void testLocalFunction() {
blackBoxFile("functions/localFunction.kt"); blackBoxFile("functions/localFunction.kt");
} }
@@ -160,13 +148,11 @@ public class FunctionGenTest extends CodegenTestCase {
} }
public void testK1649_1() { public void testK1649_1() {
loadFile("regressions/kt1649_1.kt"); blackBoxFile("regressions/kt1649_1.kt");
generateToText();
} }
public void testK1649_2() { public void testK1649_2() {
loadFile("regressions/kt1649_2.kt"); blackBoxFile("regressions/kt1649_2.kt");
generateToText();
} }
public void testKt1038() { public void testKt1038() {
@@ -34,7 +34,7 @@ public class LocalClassGenTest extends CodegenTestCase {
} }
public void testEnum() { public void testEnum() {
//blackBoxFile("localcls/enum.kt"); blackBoxFile("localcls/enum.kt");
} }
public void testObject() { public void testObject() {
@@ -22,12 +22,11 @@ public class MultiFileGenTest extends CodegenTestCase {
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.ALL); createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
} }
public void testSimple() { public void testSimple() {
blackBoxMultiFile("/multi/simple/box.kt", "/multi/simple/ok.kt"); blackBoxMultiFile("/multi/simple/box.kt", "/multi/simple/ok.kt");
//System.out.println(generateToText());
} }
public void testInternalVisibility() { public void testInternalVisibility() {
@@ -41,8 +40,4 @@ public class MultiFileGenTest extends CodegenTestCase {
public void testSameNames() { public void testSameNames() {
blackBoxMultiFile("/multi/same/1/box.kt", "/multi/same/2/box.kt"); blackBoxMultiFile("/multi/same/1/box.kt", "/multi/same/2/box.kt");
} }
public void testKt1515() {
blackBoxMultiFile("/multi/kt1515/thisPackage.kt", "/multi/kt1515/otherPackage.kt");
}
} }
@@ -17,7 +17,6 @@
package org.jetbrains.jet.codegen; package org.jetbrains.jet.codegen;
import jet.IntRange; import jet.IntRange;
import org.jetbrains.jet.ConfigurationKind;
import java.awt.*; import java.awt.*;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@@ -34,8 +33,6 @@ public class NamespaceGenTest extends CodegenTestCase {
public void testPSVM() throws Exception { public void testPSVM() throws Exception {
loadFile("PSVM.kt"); loadFile("PSVM.kt");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
Object[] args = new Object[] { new String[0] }; Object[] args = new Object[] { new String[0] };
main.invoke(null, args); main.invoke(null, args);
@@ -43,8 +40,6 @@ public class NamespaceGenTest extends CodegenTestCase {
public void testReturnOne() throws Exception { public void testReturnOne() throws Exception {
loadText("fun f() : Int { return 42; }"); loadText("fun f() : Int { return 42; }");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
final Object returnValue = main.invoke(null, new Object[0]); final Object returnValue = main.invoke(null, new Object[0]);
assertEquals(new Integer(42), returnValue); assertEquals(new Integer(42), returnValue);
@@ -52,8 +47,6 @@ public class NamespaceGenTest extends CodegenTestCase {
public void testReturnA() throws Exception { public void testReturnA() throws Exception {
loadText("fun foo(a : Int) = a"); loadText("fun foo(a : Int) = a");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
final Object returnValue = main.invoke(null, 50); final Object returnValue = main.invoke(null, 50);
assertEquals(new Integer(50), returnValue); assertEquals(new Integer(50), returnValue);
@@ -61,8 +54,6 @@ public class NamespaceGenTest extends CodegenTestCase {
public void testLocalProperty() throws Exception { public void testLocalProperty() throws Exception {
loadFile("localProperty.kt"); loadFile("localProperty.kt");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
final Object returnValue = main.invoke(null, 76); final Object returnValue = main.invoke(null, 76);
assertEquals(new Integer(50), returnValue); assertEquals(new Integer(50), returnValue);
@@ -70,7 +61,6 @@ public class NamespaceGenTest extends CodegenTestCase {
public void testCurrentTime() throws Exception { public void testCurrentTime() throws Exception {
loadText("fun f() : Long { return System.currentTimeMillis(); }"); loadText("fun f() : Long { return System.currentTimeMillis(); }");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
final long returnValue = (Long) main.invoke(null); final long returnValue = (Long) main.invoke(null);
assertIsCurrentTime(returnValue); assertIsCurrentTime(returnValue);
@@ -78,7 +68,6 @@ public class NamespaceGenTest extends CodegenTestCase {
public void testIdentityHashCode() throws Exception { public void testIdentityHashCode() throws Exception {
loadText("fun f(o: Any) : Int { return System.identityHashCode(o); }"); loadText("fun f(o: Any) : Int { return System.identityHashCode(o); }");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
Object o = new Object(); Object o = new Object();
final int returnValue = (Integer) main.invoke(null, o); final int returnValue = (Integer) main.invoke(null, o);
@@ -94,16 +83,12 @@ public class NamespaceGenTest extends CodegenTestCase {
public void testHelloWorld() throws Exception { public void testHelloWorld() throws Exception {
loadFile("helloWorld.kt"); loadFile("helloWorld.kt");
// System.out.println(generateToText());
generateFunction(); // assert that it can be verified generateFunction(); // assert that it can be verified
} }
public void testAssign() throws Exception { public void testAssign() throws Exception {
loadFile("assign.kt"); loadFile("assign.kt");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
assertEquals(2, main.invoke(null)); assertEquals(2, main.invoke(null));
} }
@@ -129,7 +114,6 @@ public class NamespaceGenTest extends CodegenTestCase {
public void testBoxVariable() throws Exception { public void testBoxVariable() throws Exception {
loadText("fun foo(): Int? { var x = 239; return x; }"); loadText("fun foo(): Int? { var x = 239; return x; }");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
assertEquals(239, main.invoke(null)); assertEquals(239, main.invoke(null));
} }
@@ -186,14 +170,12 @@ public class NamespaceGenTest extends CodegenTestCase {
public void testBottles2() throws Exception { public void testBottles2() throws Exception {
loadFile("bottles2.kt"); loadFile("bottles2.kt");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
main.invoke(null); // ensure no exception main.invoke(null); // ensure no exception
} }
public void testJavaConstructor() throws Exception { public void testJavaConstructor() throws Exception {
loadText("fun foo(): StringBuilder = StringBuilder()"); loadText("fun foo(): StringBuilder = StringBuilder()");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
final Object result = main.invoke(null); final Object result = main.invoke(null);
assertTrue(result instanceof StringBuilder); assertTrue(result instanceof StringBuilder);
@@ -208,7 +190,6 @@ public class NamespaceGenTest extends CodegenTestCase {
public void testJavaEquals() throws Exception { public void testJavaEquals() throws Exception {
loadText("fun foo(s1: String, s2: String) = s1 == s2"); loadText("fun foo(s1: String, s2: String) = s1 == s2");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
assertEquals(Boolean.TRUE, main.invoke(null, new String("jet"), new String("jet"))); assertEquals(Boolean.TRUE, main.invoke(null, new String("jet"), new String("jet")));
assertEquals(Boolean.FALSE, main.invoke(null, new String("jet"), new String("ceylon"))); assertEquals(Boolean.FALSE, main.invoke(null, new String("jet"), new String("ceylon")));
@@ -224,7 +205,6 @@ public class NamespaceGenTest extends CodegenTestCase {
public void testJavaEqualsNull() throws Exception { public void testJavaEqualsNull() throws Exception {
loadText("fun foo(s1: String?, s2: String?) = s1 == s2"); loadText("fun foo(s1: String?, s2: String?) = s1 == s2");
final Method main = generateFunction(); final Method main = generateFunction();
// System.out.println(generateToText());
assertEquals(Boolean.TRUE, main.invoke(null, null, null)); assertEquals(Boolean.TRUE, main.invoke(null, null, null));
assertEquals(Boolean.FALSE, main.invoke(null, "jet", null)); assertEquals(Boolean.FALSE, main.invoke(null, "jet", null));
assertEquals(Boolean.FALSE, main.invoke(null, null, "jet")); assertEquals(Boolean.FALSE, main.invoke(null, null, "jet"));
@@ -233,7 +213,6 @@ public class NamespaceGenTest extends CodegenTestCase {
public void testEqualsNullLiteral() throws Exception { public void testEqualsNullLiteral() throws Exception {
loadText("fun foo(s: String?) = s == null"); loadText("fun foo(s: String?) = s == null");
final Method main = generateFunction(); final Method main = generateFunction();
// System.out.println(generateToText());
assertEquals(Boolean.TRUE, main.invoke(null, new Object[] { null })); assertEquals(Boolean.TRUE, main.invoke(null, new Object[] { null }));
assertEquals(Boolean.FALSE, main.invoke(null, "jet")); assertEquals(Boolean.FALSE, main.invoke(null, "jet"));
} }
@@ -258,7 +237,6 @@ public class NamespaceGenTest extends CodegenTestCase {
public void testFunctionCall() throws Exception { public void testFunctionCall() throws Exception {
loadFile("functionCall.kt"); loadFile("functionCall.kt");
// System.out.println(generateToText());
final Method main = generateFunction("f"); final Method main = generateFunction("f");
assertEquals("foo", main.invoke(null)); assertEquals("foo", main.invoke(null));
} }
@@ -280,14 +258,12 @@ public class NamespaceGenTest extends CodegenTestCase {
public void testStringPlusEq() throws Exception { public void testStringPlusEq() throws Exception {
loadText("fun foo(s: String) : String { var result = s; result += s; return result; } "); loadText("fun foo(s: String) : String { var result = s; result += s; return result; } ");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
assertEquals("JarJar", main.invoke(null, "Jar")); assertEquals("JarJar", main.invoke(null, "Jar"));
} }
public void testStringCompare() throws Exception { public void testStringCompare() throws Exception {
loadText("fun foo(s1: String, s2: String) = s1 < s2"); loadText("fun foo(s1: String, s2: String) = s1 < s2");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
assertEquals(Boolean.TRUE, main.invoke(null, "Ceylon", "Java")); assertEquals(Boolean.TRUE, main.invoke(null, "Ceylon", "Java"));
assertEquals(Boolean.FALSE, main.invoke(null, "Jet", "Java")); assertEquals(Boolean.FALSE, main.invoke(null, "Jet", "Java"));
@@ -315,7 +291,6 @@ public class NamespaceGenTest extends CodegenTestCase {
public void testFieldRead() throws Exception { public void testFieldRead() throws Exception {
loadText("import java.awt.*; fun foo(c: GridBagConstraints) = c.gridx"); loadText("import java.awt.*; fun foo(c: GridBagConstraints) = c.gridx");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
GridBagConstraints c = new GridBagConstraints(); GridBagConstraints c = new GridBagConstraints();
c.gridx = 239; c.gridx = 239;
@@ -332,7 +307,6 @@ public class NamespaceGenTest extends CodegenTestCase {
public void testFieldIncrement() throws Exception { public void testFieldIncrement() throws Exception {
loadText("import java.awt.*; fun foo(c: GridBagConstraints) { c.gridx++; return; }"); loadText("import java.awt.*; fun foo(c: GridBagConstraints) { c.gridx++; return; }");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
GridBagConstraints c = new GridBagConstraints(); GridBagConstraints c = new GridBagConstraints();
c.gridx = 609; c.gridx = 609;
@@ -342,7 +316,6 @@ public class NamespaceGenTest extends CodegenTestCase {
public void testFieldAugAssign() throws Exception { public void testFieldAugAssign() throws Exception {
loadText("import java.awt.*; fun foo(c: GridBagConstraints) { c.gridx *= 2; return; }"); loadText("import java.awt.*; fun foo(c: GridBagConstraints) { c.gridx *= 2; return; }");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
GridBagConstraints c = new GridBagConstraints(); GridBagConstraints c = new GridBagConstraints();
c.gridx = 305; c.gridx = 305;
@@ -371,7 +344,6 @@ public class NamespaceGenTest extends CodegenTestCase {
public void testArrayAugAssign() throws Exception { public void testArrayAugAssign() throws Exception {
loadText("fun foo(c: Array<Int>) { c[0] *= 2 }"); loadText("fun foo(c: Array<Int>) { c[0] *= 2 }");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
Integer[] data = new Integer[] { 5 }; Integer[] data = new Integer[] { 5 };
main.invoke(null, new Object[] { data }); main.invoke(null, new Object[] { data });
@@ -380,7 +352,6 @@ public class NamespaceGenTest extends CodegenTestCase {
public void testArrayAugAssignLong() throws Exception { public void testArrayAugAssignLong() throws Exception {
loadText("fun foo(c: LongArray) { c[0] *= 2.toLong() }"); loadText("fun foo(c: LongArray) { c[0] *= 2.toLong() }");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
long[] data = new long[] { 5 }; long[] data = new long[] { 5 };
main.invoke(null, new Object[] { data }); main.invoke(null, new Object[] { data });
@@ -389,7 +360,6 @@ public class NamespaceGenTest extends CodegenTestCase {
public void testArrayNew() throws Exception { public void testArrayNew() throws Exception {
loadText("fun foo() = Array<Int>(4, { it })"); loadText("fun foo() = Array<Int>(4, { it })");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
Integer[] result = (Integer[]) main.invoke(null); Integer[] result = (Integer[]) main.invoke(null);
assertEquals(4, result.length); assertEquals(4, result.length);
@@ -401,14 +371,12 @@ public class NamespaceGenTest extends CodegenTestCase {
public void testArrayNewNullable() throws Exception { public void testArrayNewNullable() throws Exception {
loadText("fun foo() = arrayOfNulls<Int>(4)"); loadText("fun foo() = arrayOfNulls<Int>(4)");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
Integer[] result = (Integer[]) main.invoke(null); Integer[] result = (Integer[]) main.invoke(null);
assertEquals(4, result.length); assertEquals(4, result.length);
} }
public void testFloatArrayNew() throws Exception { public void testFloatArrayNew() throws Exception {
loadText("fun foo() = FloatArray(4)"); loadText("fun foo() = FloatArray(4)");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
float[] result = (float[]) main.invoke(null); float[] result = (float[]) main.invoke(null);
assertEquals(4, result.length); assertEquals(4, result.length);
@@ -416,7 +384,6 @@ public class NamespaceGenTest extends CodegenTestCase {
public void testFloatArrayArrayNew() throws Exception { public void testFloatArrayArrayNew() throws Exception {
loadText("fun foo() = Array<FloatArray>(4, { FloatArray(5-it) })"); loadText("fun foo() = Array<FloatArray>(4, { FloatArray(5-it) })");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
float[][] result = (float[][]) main.invoke(null); float[][] result = (float[][]) main.invoke(null);
assertEquals(4, result.length); assertEquals(4, result.length);
@@ -425,17 +392,14 @@ public class NamespaceGenTest extends CodegenTestCase {
public void testArraySize() throws Exception { public void testArraySize() throws Exception {
loadText("fun foo(a: Array<Int>) = a.size"); loadText("fun foo(a: Array<Int>) = a.size");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
Object[] args = new Object[] { new Integer[4] }; Object[] args = new Object[] { new Integer[4] };
int result = (Integer) main.invoke(null, args); int result = (Integer) main.invoke(null, args);
System.out.println(result);
assertEquals(4, result); assertEquals(4, result);
} }
public void testIntArraySize() throws Exception { public void testIntArraySize() throws Exception {
loadText("fun foo(a: IntArray) = a.size"); loadText("fun foo(a: IntArray) = a.size");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
Object[] args = new Object[] { new int[4] }; Object[] args = new Object[] { new int[4] };
int result = (Integer) main.invoke(null, args); int result = (Integer) main.invoke(null, args);
@@ -27,17 +27,14 @@ public class ObjectGenTest extends CodegenTestCase {
public void testSimpleObject() { public void testSimpleObject() {
blackBoxFile("objects/simpleObject.kt"); blackBoxFile("objects/simpleObject.kt");
// System.out.println(generateToText());
} }
public void testObjectLiteral() { public void testObjectLiteral() {
blackBoxFile("objects/objectLiteral.kt"); blackBoxFile("objects/objectLiteral.kt");
// System.out.println(generateToText());
} }
public void testObjectLiteralInClosure() { public void testObjectLiteralInClosure() {
blackBoxFile("objects/objectLiteralInClosure.kt"); blackBoxFile("objects/objectLiteralInClosure.kt");
// System.out.println(generateToText());
} }
public void testMethodOnObject() { public void testMethodOnObject() {
@@ -21,7 +21,6 @@ import org.jetbrains.jet.ConfigurationKind;
import java.lang.reflect.Method; import java.lang.reflect.Method;
public class PatternMatchingTest extends CodegenTestCase { public class PatternMatchingTest extends CodegenTestCase {
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
@@ -56,7 +55,6 @@ public class PatternMatchingTest extends CodegenTestCase {
public void testInrange() throws Exception { public void testInrange() throws Exception {
loadFile(); loadFile();
// System.out.println(generateToText());
Method foo = generateFunction(); Method foo = generateFunction();
assertEquals("array list", foo.invoke(null, 239)); assertEquals("array list", foo.invoke(null, 239));
assertEquals("digit", foo.invoke(null, 0)); assertEquals("digit", foo.invoke(null, 0));
@@ -66,27 +64,24 @@ public class PatternMatchingTest extends CodegenTestCase {
assertEquals("something", foo.invoke(null, 19)); assertEquals("something", foo.invoke(null, 19));
} }
public void testIs() throws Exception { public void testIs() {
loadFile(); blackBoxFile("patternMatching/is.kt");
// System.out.println(generateToText());
blackBox();
} }
public void testRange() throws Exception { public void testRange() {
blackBoxFile("patternMatching/range.kt"); blackBoxFile("patternMatching/range.kt");
} }
public void testLongInRange() throws Exception { public void testLongInRange() {
blackBoxFile("patternMatching/longInRange.kt"); blackBoxFile("patternMatching/longInRange.kt");
} }
public void testWhenArgumentIsEvaluatedOnlyOnce() throws Exception { public void testWhenArgumentIsEvaluatedOnlyOnce() {
blackBoxFile("patternMatching/whenArgumentIsEvaluatedOnlyOnce.kt"); blackBoxFile("patternMatching/whenArgumentIsEvaluatedOnlyOnce.kt");
} }
public void testRangeChar() throws Exception { public void testRangeChar() throws Exception {
loadFile(); loadFile();
// System.out.println(generateToText());
Method foo = generateFunction(); Method foo = generateFunction();
assertEquals("digit", foo.invoke(null, '0')); assertEquals("digit", foo.invoke(null, '0'));
assertEquals("something", foo.invoke(null, 'A')); assertEquals("something", foo.invoke(null, 'A'));
@@ -111,7 +106,7 @@ public class PatternMatchingTest extends CodegenTestCase {
assertEquals("something", foo.invoke(null, "C#")); assertEquals("something", foo.invoke(null, "C#"));
} }
public void testCallProperty() throws Exception { public void testCallProperty() {
blackBoxFile("patternMatching/callProperty.kt"); blackBoxFile("patternMatching/callProperty.kt");
} }
@@ -123,19 +118,19 @@ public class PatternMatchingTest extends CodegenTestCase {
assertEquals("something", foo.invoke(null, 2)); assertEquals("something", foo.invoke(null, 2));
} }
public void testNullableWhen() throws Exception { // KT-2148 public void testNullableWhen() {
blackBoxFile("patternMatching/nullableWhen.kt"); blackBoxFile("patternMatching/nullableWhen.kt");
} }
public void testKt2466() throws Exception { public void testKt2466() {
blackBoxFile("patternMatching/kt2466.kt"); blackBoxFile("patternMatching/kt2466.kt");
} }
public void testMatchNotNullAgainstNullable() throws Exception { public void testMatchNotNullAgainstNullable() {
blackBoxFile("patternMatching/matchNotNullAgainstNullable.kt"); blackBoxFile("patternMatching/matchNotNullAgainstNullable.kt");
} }
public void testKt2457() throws Exception { public void testKt2457() {
blackBoxFile("regressions/kt2457.kt"); blackBoxFile("regressions/kt2457.kt");
} }
} }
@@ -30,9 +30,6 @@ public class PrimitiveTypesTest extends CodegenTestCase {
public void testPlus() throws Exception { public void testPlus() throws Exception {
loadText("fun f(a: Int, b: Int): Int { return a + b }"); loadText("fun f(a: Int, b: Int): Int { return a + b }");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
final int returnValue = (Integer) main.invoke(null, 37, 5); final int returnValue = (Integer) main.invoke(null, 37, 5);
assertEquals(42, returnValue); assertEquals(42, returnValue);
@@ -41,7 +38,6 @@ public class PrimitiveTypesTest extends CodegenTestCase {
public void testGt() throws Exception { public void testGt() throws Exception {
loadText("fun foo(f: Int): Boolean { if (f > 0) return true; return false; }"); loadText("fun foo(f: Int): Boolean { if (f > 0) return true; return false; }");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
assertEquals(true, main.invoke(null, 1)); assertEquals(true, main.invoke(null, 1));
assertEquals(false, main.invoke(null, 0)); assertEquals(false, main.invoke(null, 0));
@@ -78,7 +74,6 @@ public class PrimitiveTypesTest extends CodegenTestCase {
public void testLong() throws Exception { public void testLong() throws Exception {
loadText("fun foo(a: Long, b: Long): Long = a + b"); loadText("fun foo(a: Long, b: Long): Long = a + b");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
long arg = (long) Integer.MAX_VALUE; long arg = (long) Integer.MAX_VALUE;
long expected = 2 * (long) Integer.MAX_VALUE; long expected = 2 * (long) Integer.MAX_VALUE;
@@ -87,7 +82,6 @@ public class PrimitiveTypesTest extends CodegenTestCase {
public void testLongCmp() throws Exception { public void testLongCmp() throws Exception {
loadText("fun foo(a: Long, b: Long): Long = if (a == b) 0xffffffff else 0xfffffffe"); loadText("fun foo(a: Long, b: Long): Long = if (a == b) 0xffffffff else 0xfffffffe");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
assertEquals(0xffffffffL, main.invoke(null, 1, 1)); assertEquals(0xffffffffL, main.invoke(null, 1, 1));
assertEquals(0xfffffffeL, main.invoke(null, 1, 0)); assertEquals(0xfffffffeL, main.invoke(null, 1, 0));
@@ -153,7 +147,6 @@ public class PrimitiveTypesTest extends CodegenTestCase {
public void testDoubleToInt() throws Exception { public void testDoubleToInt() throws Exception {
loadText("fun foo(a: Double): Int = a.toInt()"); loadText("fun foo(a: Double): Int = a.toInt()");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
assertEquals(1, main.invoke(null, 1.0)); assertEquals(1, main.invoke(null, 1.0));
} }
@@ -237,7 +230,6 @@ public class PrimitiveTypesTest extends CodegenTestCase {
public void testBitInv() throws Exception { public void testBitInv() throws Exception {
loadText("fun foo(a: Int): Int = a.inv()"); loadText("fun foo(a: Int): Int = a.inv()");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
assertEquals(0xffff0000, main.invoke(null, 0x0000ffff)); assertEquals(0xffff0000, main.invoke(null, 0x0000ffff));
} }
@@ -270,14 +262,12 @@ public class PrimitiveTypesTest extends CodegenTestCase {
public void testDecrementAsStatement() throws Exception { public void testDecrementAsStatement() throws Exception {
loadFile("bottles.kt"); loadFile("bottles.kt");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
main.invoke(null); // ensure no exception main.invoke(null); // ensure no exception
} }
private void binOpTest(final String text, final Object arg1, final Object arg2, final Object expected) throws Exception { private void binOpTest(final String text, final Object arg1, final Object arg2, final Object expected) throws Exception {
loadText(text); loadText(text);
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
assertEquals(expected, main.invoke(null, arg1, arg2)); assertEquals(expected, main.invoke(null, arg1, arg2));
} }
@@ -370,7 +360,6 @@ public class PrimitiveTypesTest extends CodegenTestCase {
public void testKt756 () { public void testKt756 () {
blackBoxFile("regressions/kt756.kt"); blackBoxFile("regressions/kt756.kt");
//System.out.println(generateToText());
} }
public void testKt757 () { public void testKt757 () {
@@ -22,13 +22,18 @@ import org.jetbrains.jet.ConfigurationKind;
import java.lang.reflect.*; import java.lang.reflect.*;
public class PropertyGenTest extends CodegenTestCase { public class PropertyGenTest extends CodegenTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
}
@Override @Override
protected String getPrefix() { protected String getPrefix() {
return "properties"; return "properties";
} }
public void testPrivateVal() throws Exception { public void testPrivateVal() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadFile(); loadFile();
final Class aClass = loadImplementationClass(generateClassesInFile(), "PrivateVal"); final Class aClass = loadImplementationClass(generateClassesInFile(), "PrivateVal");
final Field[] fields = aClass.getDeclaredFields(); final Field[] fields = aClass.getDeclaredFields();
@@ -38,7 +43,6 @@ public class PropertyGenTest extends CodegenTestCase {
} }
public void testPrivateVar() throws Exception { public void testPrivateVar() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadFile(); loadFile();
final Class aClass = loadImplementationClass(generateClassesInFile(), "PrivateVar"); final Class aClass = loadImplementationClass(generateClassesInFile(), "PrivateVar");
final Object instance = aClass.newInstance(); final Object instance = aClass.newInstance();
@@ -49,7 +53,6 @@ public class PropertyGenTest extends CodegenTestCase {
} }
public void testPublicVar() throws Exception { public void testPublicVar() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("class PublicVar() { public var foo : Int = 0; }"); loadText("class PublicVar() { public var foo : Int = 0; }");
final Class aClass = loadImplementationClass(generateClassesInFile(), "PublicVar"); final Class aClass = loadImplementationClass(generateClassesInFile(), "PublicVar");
final Object instance = aClass.newInstance(); final Object instance = aClass.newInstance();
@@ -60,7 +63,6 @@ public class PropertyGenTest extends CodegenTestCase {
} }
public void testAccessorsInInterface() { public void testAccessorsInInterface() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("class AccessorsInInterface() { public var foo : Int = 0; }"); loadText("class AccessorsInInterface() { public var foo : Int = 0; }");
final Class aClass = loadClass("AccessorsInInterface", generateClassesInFile()); final Class aClass = loadClass("AccessorsInInterface", generateClassesInFile());
assertNotNull(findMethodByName(aClass, "getFoo")); assertNotNull(findMethodByName(aClass, "getFoo"));
@@ -68,7 +70,6 @@ public class PropertyGenTest extends CodegenTestCase {
} }
public void testPrivatePropertyInNamespace() throws Exception { public void testPrivatePropertyInNamespace() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("private val x = 239"); loadText("private val x = 239");
final Class nsClass = generateNamespaceClass(); final Class nsClass = generateNamespaceClass();
final Field[] fields = nsClass.getDeclaredFields(); final Field[] fields = nsClass.getDeclaredFields();
@@ -81,35 +82,31 @@ public class PropertyGenTest extends CodegenTestCase {
} }
public void testFieldPropertyAccess() throws Exception { public void testFieldPropertyAccess() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadFile("properties/fieldPropertyAccess.kt"); loadFile("properties/fieldPropertyAccess.kt");
// System.out.println(generateToText());
final Method method = generateFunction("increment"); final Method method = generateFunction("increment");
assertEquals(1, method.invoke(null)); assertEquals(1, method.invoke(null));
assertEquals(2, method.invoke(null)); assertEquals(2, method.invoke(null));
} }
public void testFieldGetter() throws Exception { public void testFieldGetter() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("val now: Long get() = System.currentTimeMillis(); fun foo() = now"); loadText("val now: Long get() = System.currentTimeMillis(); fun foo() = now");
final Method method = generateFunction("foo"); final Method method = generateFunction("foo");
assertIsCurrentTime((Long) method.invoke(null)); assertIsCurrentTime((Long) method.invoke(null));
} }
public void testFieldSetter() throws Exception { public void testFieldSetter() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadFile(); loadFile();
final Method method = generateFunction("append"); final Method method = generateFunction("append");
method.invoke(null, "IntelliJ "); method.invoke(null, "IntelliJ ");
String value = (String) method.invoke(null, "IDEA"); String value = (String) method.invoke(null, "IDEA");
if (!value.equals("IntelliJ IDEA")) { if (!value.equals("IntelliJ IDEA")) {
System.out.println(generateToText()); System.out.println(generateToText());
throw new AssertionError(value);
} }
assertEquals("IntelliJ IDEA", value); assertEquals("IntelliJ IDEA", value);
} }
public void testFieldSetterPlusEq() throws Exception { public void testFieldSetterPlusEq() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadFile(); loadFile();
final Method method = generateFunction("append"); final Method method = generateFunction("append");
method.invoke(null, "IntelliJ "); method.invoke(null, "IntelliJ ");
@@ -118,9 +115,7 @@ public class PropertyGenTest extends CodegenTestCase {
} }
public void testAccessorsWithoutBody() throws Exception { public void testAccessorsWithoutBody() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("class AccessorsWithoutBody() { protected var foo: Int = 349\n get\n private set\n fun setter() { foo = 610; } } "); loadText("class AccessorsWithoutBody() { protected var foo: Int = 349\n get\n private set\n fun setter() { foo = 610; } } ");
// System.out.println(generateToText());
final Class aClass = loadImplementationClass(generateClassesInFile(), "AccessorsWithoutBody"); final Class aClass = loadImplementationClass(generateClassesInFile(), "AccessorsWithoutBody");
final Object instance = aClass.newInstance(); final Object instance = aClass.newInstance();
final Method getFoo = findMethodByName(aClass, "getFoo"); final Method getFoo = findMethodByName(aClass, "getFoo");
@@ -136,7 +131,6 @@ public class PropertyGenTest extends CodegenTestCase {
} }
public void testInitializersForNamespaceProperties() throws Exception { public void testInitializersForNamespaceProperties() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("val x = System.currentTimeMillis()"); loadText("val x = System.currentTimeMillis()");
final Method method = generateFunction("getX"); final Method method = generateFunction("getX");
method.setAccessible(true); method.setAccessible(true);
@@ -144,7 +138,6 @@ public class PropertyGenTest extends CodegenTestCase {
} }
public void testPropertyReceiverOnStack() throws Exception { public void testPropertyReceiverOnStack() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadFile(); loadFile();
final Class aClass = loadImplementationClass(generateClassesInFile(), "Evaluator"); final Class aClass = loadImplementationClass(generateClassesInFile(), "Evaluator");
final Constructor constructor = aClass.getConstructor(StringBuilder.class); final Constructor constructor = aClass.getConstructor(StringBuilder.class);
@@ -156,7 +149,6 @@ public class PropertyGenTest extends CodegenTestCase {
} }
public void testAbstractVal() throws Exception { public void testAbstractVal() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("abstract class Foo { public abstract val x: String }"); loadText("abstract class Foo { public abstract val x: String }");
final ClassFileFactory codegens = generateClassesInFile(); final ClassFileFactory codegens = generateClassesInFile();
final Class aClass = loadClass("Foo", codegens); final Class aClass = loadClass("Foo", codegens);
@@ -164,77 +156,61 @@ public class PropertyGenTest extends CodegenTestCase {
} }
public void testVolatileProperty() throws Exception { public void testVolatileProperty() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("abstract class Foo { public volatile var x: String = \"\"; }"); loadText("abstract class Foo { public volatile var x: String = \"\"; }");
// System.out.println(generateToText());
final ClassFileFactory codegens = generateClassesInFile(); final ClassFileFactory codegens = generateClassesInFile();
final Class aClass = loadClass("Foo", codegens); final Class aClass = loadClass("Foo", codegens);
Field x = aClass.getDeclaredField("x"); Field x = aClass.getDeclaredField("x");
assertTrue((x.getModifiers() & Modifier.VOLATILE) != 0); assertTrue((x.getModifiers() & Modifier.VOLATILE) != 0);
} }
public void testKt257 () throws Exception { public void testKt257() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt257.kt"); blackBoxFile("regressions/kt257.kt");
// System.out.println(generateToText());
} }
public void testKt613 () throws Exception { public void testKt613() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt613.kt"); blackBoxFile("regressions/kt613.kt");
} }
public void testKt160() throws Exception { public void testKt160() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("internal val s = java.lang.Double.toString(1.0)"); loadText("internal val s = java.lang.Double.toString(1.0)");
final Method method = generateFunction("getS"); final Method method = generateFunction("getS");
method.setAccessible(true); method.setAccessible(true);
assertEquals(method.invoke(null), "1.0"); assertEquals(method.invoke(null), "1.0");
} }
public void testKt1165() throws Exception { public void testKt1165() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt1165.kt"); blackBoxFile("regressions/kt1165.kt");
} }
public void testKt1168() throws Exception { public void testKt1168() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt1168.kt"); blackBoxFile("regressions/kt1168.kt");
} }
public void testKt1170() throws Exception { public void testKt1170() {
createEnvironmentWithFullJdk();
blackBoxFile("regressions/kt1170.kt"); blackBoxFile("regressions/kt1170.kt");
} }
public void testKt1159() throws Exception { public void testKt1159() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt1159.kt"); blackBoxFile("regressions/kt1159.kt");
} }
public void testKt1417() throws Exception { public void testKt1417() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt1417.kt"); blackBoxFile("regressions/kt1417.kt");
} }
public void testKt1398() throws Exception { public void testKt1398() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt1398.kt"); blackBoxFile("regressions/kt1398.kt");
} }
public void testKt2331() throws Exception { public void testKt2331() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt2331.kt"); blackBoxFile("regressions/kt2331.kt");
} }
public void testKt1892() throws Exception { public void testKt1892() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt1892.kt"); blackBoxFile("regressions/kt1892.kt");
//System.out.println(generateToText());
} }
public void testKt1846() throws Exception { public void testKt1846() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadFile("regressions/kt1846.kt"); loadFile("regressions/kt1846.kt");
final Class aClass = loadImplementationClass(generateClassesInFile(), "A"); final Class aClass = loadImplementationClass(generateClassesInFile(), "A");
try { try {
@@ -254,43 +230,31 @@ public class PropertyGenTest extends CodegenTestCase {
} }
} }
public void testKt1482_2279() throws Exception { public void testKt1482_2279() {
createEnvironmentWithFullJdk();
blackBoxFile("regressions/kt1482_2279.kt"); blackBoxFile("regressions/kt1482_2279.kt");
} }
public void testKt1714() throws Exception { public void testKt1714() {
createEnvironmentWithFullJdk();
blackBoxFile("regressions/kt1714.kt"); blackBoxFile("regressions/kt1714.kt");
} }
public void testKt1714_minimal() throws Exception { public void testKt1714_minimal() {
createEnvironmentWithFullJdk();
blackBoxFile("regressions/kt1714_minimal.kt"); blackBoxFile("regressions/kt1714_minimal.kt");
} }
public void testKt2509() throws Exception { public void testKt2786() {
createEnvironmentWithFullJdk();
blackBoxFile("regressions/kt2509.kt");
}
public void testKt2786() throws Exception {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt2786.kt"); blackBoxFile("regressions/kt2786.kt");
} }
public void testKt2655() throws Exception { public void testKt2655() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt2655.kt"); blackBoxFile("regressions/kt2655.kt");
} }
public void testKt1528() throws Exception { public void testKt1528() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxMultiFile("regressions/kt1528_1.kt", "regressions/kt1528_3.kt"); blackBoxMultiFile("regressions/kt1528_1.kt", "regressions/kt1528_3.kt");
} }
public void testKt2589() throws Exception { public void testKt2589() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadFile("regressions/kt2589.kt"); loadFile("regressions/kt2589.kt");
final Class aClass = loadImplementationClass(generateClassesInFile(), "Foo"); final Class aClass = loadImplementationClass(generateClassesInFile(), "Foo");
assertTrue((aClass.getModifiers() & Opcodes.ACC_FINAL) == 0); assertTrue((aClass.getModifiers() & Opcodes.ACC_FINAL) == 0);
@@ -318,8 +282,7 @@ public class PropertyGenTest extends CodegenTestCase {
} }
} }
public void testKt2677() throws Exception { public void testKt2677() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadFile("regressions/kt2677.kt"); loadFile("regressions/kt2677.kt");
final Class aClass = loadImplementationClass(generateClassesInFile(), "DerivedWeatherReport"); final Class aClass = loadImplementationClass(generateClassesInFile(), "DerivedWeatherReport");
final Class bClass = aClass.getSuperclass(); final Class bClass = aClass.getSuperclass();
@@ -358,23 +321,19 @@ public class PropertyGenTest extends CodegenTestCase {
} }
} }
public void testKt2892() throws Exception { public void testKt2892() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("properties/kt2892.kt"); blackBoxFile("properties/kt2892.kt");
} }
public void testAccessToPrivateProperty() throws Exception { public void testAccessToPrivateProperty() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("properties/accessToPrivateProperty.kt"); blackBoxFile("properties/accessToPrivateProperty.kt");
} }
public void testAccessToPrivateSetter() throws Exception { public void testAccessToPrivateSetter() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("properties/accessToPrivateSetter.kt"); blackBoxFile("properties/accessToPrivateSetter.kt");
} }
public void testKt2202() throws Exception { public void testKt2202() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadFile("properties/kt2202.kt"); loadFile("properties/kt2202.kt");
String text = generateToText(); String text = generateToText();
assertFalse(text.contains("INVOKEVIRTUAL")); assertFalse(text.contains("INVOKEVIRTUAL"));
@@ -22,22 +22,22 @@ public class SafeRefTest extends CodegenTestCase {
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_AND_ANNOTATIONS); createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
} }
public void test247 () throws Exception { public void test247() {
blackBoxFile("regressions/kt247.kt"); blackBoxFile("regressions/kt247.kt");
} }
public void test245 () throws Exception { public void test245() {
blackBoxFile("regressions/kt245.kt"); blackBoxFile("regressions/kt245.kt");
} }
public void test232 () throws Exception { public void test232() {
blackBoxFile("regressions/kt232.kt"); blackBoxFile("regressions/kt232.kt");
} }
public void test1572 () throws Exception { public void test1572() {
blackBoxFile("regressions/kt1572.kt"); blackBoxFile("regressions/kt1572.kt");
} }
} }
@@ -96,7 +96,6 @@ public class StdlibTest extends CodegenTestCase {
//from ClassGenTest //from ClassGenTest
public void testKt344 () throws Exception { public void testKt344 () throws Exception {
loadFile("regressions/kt344.kt"); loadFile("regressions/kt344.kt");
// System.out.println(generateToText());
blackBox(); blackBox();
} }
@@ -339,7 +338,6 @@ public class StdlibTest extends CodegenTestCase {
public void testKt2210() throws Exception { public void testKt2210() throws Exception {
blackBoxFile("regressions/kt2210.kt"); blackBoxFile("regressions/kt2210.kt");
// System.out.println(generateToText());
} }
public void testKt2593() { public void testKt2593() {
@@ -369,4 +367,12 @@ public class StdlibTest extends CodegenTestCase {
public void testNoClassObjectForJavaClass() throws Exception { public void testNoClassObjectForJavaClass() throws Exception {
blackBoxFileWithJava("stdlib/noClassObjectForJavaClass.kt"); blackBoxFileWithJava("stdlib/noClassObjectForJavaClass.kt");
} }
public void testKt1076() {
blackBoxFile("regressions/kt1076.kt");
}
public void testKt1515() {
blackBoxMultiFile("/multi/kt1515/thisPackage.kt", "/multi/kt1515/otherPackage.kt");
}
} }
@@ -31,14 +31,12 @@ public class StringsTest extends CodegenTestCase {
public void testAnyToString () throws InvocationTargetException, IllegalAccessException { public void testAnyToString () throws InvocationTargetException, IllegalAccessException {
loadText("fun foo(x: Any) = x.toString()"); loadText("fun foo(x: Any) = x.toString()");
// System.out.println(generateToText());
Method foo = generateFunction(); Method foo = generateFunction();
assertEquals("something", foo.invoke(null, "something")); assertEquals("something", foo.invoke(null, "something"));
} }
public void testNullableAnyToString () throws InvocationTargetException, IllegalAccessException { public void testNullableAnyToString () throws InvocationTargetException, IllegalAccessException {
loadText("fun foo(x: Any?) = x.toString()"); loadText("fun foo(x: Any?) = x.toString()");
// System.out.println(generateToText());
Method foo = generateFunction(); Method foo = generateFunction();
assertEquals("something", foo.invoke(null, "something")); assertEquals("something", foo.invoke(null, "something"));
assertEquals("null", foo.invoke(null, new Object[]{null})); assertEquals("null", foo.invoke(null, new Object[]{null}));
@@ -49,7 +47,6 @@ public class StringsTest extends CodegenTestCase {
loadText("fun foo(x: String?, y: Any?) = x + y"); loadText("fun foo(x: String?, y: Any?) = x + y");
String text = generateToText(); String text = generateToText();
assertTrue(text.contains(".stringPlus")); assertTrue(text.contains(".stringPlus"));
// System.out.println(text);
Method foo = generateFunction(); Method foo = generateFunction();
assertEquals("something239", foo.invoke(null, "something", 239)); assertEquals("something239", foo.invoke(null, "something", 239));
assertEquals("null239", foo.invoke(null, null, 239)); assertEquals("null239", foo.invoke(null, null, 239));
@@ -62,7 +59,6 @@ public class StringsTest extends CodegenTestCase {
loadText("fun foo(x: String, y: Any?) = x + y + 120"); loadText("fun foo(x: String, y: Any?) = x + y + 120");
String text = generateToText(); String text = generateToText();
assertFalse(text.contains(".stringPlus")); assertFalse(text.contains(".stringPlus"));
// System.out.println(text);
Method foo = generateFunction(); Method foo = generateFunction();
assertEquals("something239120", foo.invoke(null, "something", 239)); assertEquals("something239120", foo.invoke(null, "something", 239));
assertEquals("239null120", foo.invoke(null, "239", null)); assertEquals("239null120", foo.invoke(null, "239", null));
@@ -24,7 +24,7 @@ public class SuperGenTest extends CodegenTestCase {
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_AND_ANNOTATIONS); createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
} }
public void testBasicProperty () { public void testBasicProperty () {
@@ -33,12 +33,10 @@ public class TraitsTest extends CodegenTestCase {
public void testSimple () { public void testSimple () {
blackBoxFile("traits/simple.kt"); blackBoxFile("traits/simple.kt");
// System.out.println(generateToText());
} }
public void testWithRequired () { public void testWithRequired () {
blackBoxFile("traits/withRequired.kt"); blackBoxFile("traits/withRequired.kt");
// System.out.println(generateToText());
} }
public void testMultiple () { public void testMultiple () {
@@ -23,6 +23,5 @@ public class TupleGenTest extends CodegenTestCase {
public void testUnitValue() { public void testUnitValue() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("/tuples/UnitValue.kt"); blackBoxFile("/tuples/UnitValue.kt");
// System.out.println(generateToText());
} }
} }
@@ -21,7 +21,6 @@ import org.jetbrains.jet.ConfigurationKind;
import java.lang.reflect.Method; import java.lang.reflect.Method;
public class TypeInfoTest extends CodegenTestCase { public class TypeInfoTest extends CodegenTestCase {
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
@@ -23,37 +23,35 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
public class VarArgTest extends CodegenTestCase { public class VarArgTest extends CodegenTestCase {
public void testStringArray () throws InvocationTargetException, IllegalAccessException { @Override
protected void setUp() throws Exception {
super.setUp();
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY); createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
}
public void testStringArray() throws InvocationTargetException, IllegalAccessException {
loadText("fun test(vararg ts: String) = ts"); loadText("fun test(vararg ts: String) = ts");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
String[] args = {"mama", "papa"}; String[] args = {"mama", "papa"};
assertTrue(args == main.invoke(null, new Object[]{ args } )); assertTrue(args == main.invoke(null, new Object[]{ args } ));
} }
public void testIntArray () throws InvocationTargetException, IllegalAccessException { public void testIntArray() throws InvocationTargetException, IllegalAccessException {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("fun test(vararg ts: Int) = ts"); loadText("fun test(vararg ts: Int) = ts");
// System.out.println(generateToText());
final Method main = generateFunction(); final Method main = generateFunction();
int[] args = {3, 4}; int[] args = {3, 4};
assertTrue(args == main.invoke(null, new Object[]{ args })); assertTrue(args == main.invoke(null, new Object[]{ args }));
} }
public void testIntArrayKotlinNoArgs () throws InvocationTargetException, IllegalAccessException { public void testIntArrayKotlinNoArgs() throws InvocationTargetException, IllegalAccessException {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("fun test() = testf(); fun testf(vararg ts: Int) = ts"); loadText("fun test() = testf(); fun testf(vararg ts: Int) = ts");
// System.out.println(generateToText());
final Method main = generateFunction("test"); final Method main = generateFunction("test");
Object res = main.invoke(null); Object res = main.invoke(null);
assertTrue(((int[])res).length == 0); assertTrue(((int[])res).length == 0);
} }
public void testIntArrayKotlin () throws InvocationTargetException, IllegalAccessException { public void testIntArrayKotlin() throws InvocationTargetException, IllegalAccessException {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("fun test() = testf(239, 7); fun testf(vararg ts: Int) = ts"); loadText("fun test() = testf(239, 7); fun testf(vararg ts: Int) = ts");
// System.out.println(generateToText());
final Method main = generateFunction("test"); final Method main = generateFunction("test");
Object res = main.invoke(null); Object res = main.invoke(null);
assertTrue(((int[])res).length == 2); assertTrue(((int[])res).length == 2);
@@ -61,10 +59,8 @@ public class VarArgTest extends CodegenTestCase {
assertTrue(((int[])res)[1] == 7); assertTrue(((int[])res)[1] == 7);
} }
public void testNullableIntArrayKotlin () throws InvocationTargetException, IllegalAccessException { public void testNullableIntArrayKotlin() throws InvocationTargetException, IllegalAccessException {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("fun test() = testf(239.toByte(), 7.toByte()); fun testf(vararg ts: Byte?) = ts"); loadText("fun test() = testf(239.toByte(), 7.toByte()); fun testf(vararg ts: Byte?) = ts");
// System.out.println(generateToText());
final Method main = generateFunction("test"); final Method main = generateFunction("test");
Object res = main.invoke(null); Object res = main.invoke(null);
assertTrue(((Byte[])res).length == 2); assertTrue(((Byte[])res).length == 2);
@@ -72,20 +68,16 @@ public class VarArgTest extends CodegenTestCase {
assertTrue(((Byte[])res)[1] == 7); assertTrue(((Byte[])res)[1] == 7);
} }
public void testIntArrayKotlinObj () throws InvocationTargetException, IllegalAccessException { public void testIntArrayKotlinObj() throws InvocationTargetException, IllegalAccessException {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("fun test() = testf(\"239\"); fun testf(vararg ts: String) = ts"); loadText("fun test() = testf(\"239\"); fun testf(vararg ts: String) = ts");
// System.out.println(generateToText());
final Method main = generateFunction("test"); final Method main = generateFunction("test");
Object res = main.invoke(null); Object res = main.invoke(null);
assertTrue(((String[])res).length == 1); assertTrue(((String[])res).length == 1);
assertTrue(((String[])res)[0].equals("239")); assertTrue(((String[])res)[0].equals("239"));
} }
public void testArrayT () throws InvocationTargetException, IllegalAccessException { public void testArrayT() throws InvocationTargetException, IllegalAccessException {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("fun test() = _array(2, 4); fun <T> _array(vararg elements : T) = elements"); loadText("fun test() = _array(2, 4); fun <T> _array(vararg elements : T) = elements");
// System.out.println(generateToText());
final Method main = generateFunction("test"); final Method main = generateFunction("test");
Object res = main.invoke(null); Object res = main.invoke(null);
assertTrue(((Integer[])res).length == 2); assertTrue(((Integer[])res).length == 2);
@@ -94,28 +86,22 @@ public class VarArgTest extends CodegenTestCase {
} }
public void testKt581() { public void testKt581() {
createEnvironmentWithFullJdk();
blackBoxFile("regressions/kt581.kt"); blackBoxFile("regressions/kt581.kt");
} }
public void testKt797() { public void testKt797() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt796_797.kt"); blackBoxFile("regressions/kt796_797.kt");
} }
public void testArrayAsVararg () throws InvocationTargetException, IllegalAccessException { public void testArrayAsVararg() throws InvocationTargetException, IllegalAccessException {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("private fun asList(vararg elems: String) = elems; fun test(ts: Array<String>) = asList(*ts); "); loadText("private fun asList(vararg elems: String) = elems; fun test(ts: Array<String>) = asList(*ts); ");
//System.out.println(generateToText());
final Method main = generateFunction("test"); final Method main = generateFunction("test");
String[] args = {"mama", "papa"}; String[] args = {"mama", "papa"};
assertTrue(args == main.invoke(null, new Object[]{ args } )); assertTrue(args == main.invoke(null, new Object[]{ args } ));
} }
public void testArrayAsVararg2 () throws InvocationTargetException, IllegalAccessException { public void testArrayAsVararg2() throws InvocationTargetException, IllegalAccessException {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
loadText("private fun asList(vararg elems: String) = elems; fun test(ts1: Array<String>, ts2: String) = asList(*ts1, ts2); "); loadText("private fun asList(vararg elems: String) = elems; fun test(ts1: Array<String>, ts2: String) = asList(*ts1, ts2); ");
//System.out.println(generateToText());
final Method main = generateFunction("test"); final Method main = generateFunction("test");
Object invoke = main.invoke(null, new Object[] {new String[] {"mama"}, "papa" }); Object invoke = main.invoke(null, new Object[] {new String[] {"mama"}, "papa" });
assertInstanceOf(invoke, String[].class); assertInstanceOf(invoke, String[].class);
@@ -125,7 +111,6 @@ public class VarArgTest extends CodegenTestCase {
} }
public void testKt1978() { public void testKt1978() {
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
blackBoxFile("regressions/kt1978.kt"); blackBoxFile("regressions/kt1978.kt");
} }
} }