diff --git a/compiler/testData/codegen/box/bridges/complexTraitImpl.kt b/compiler/testData/codegen/box/bridges/complexTraitImpl.kt index dafbf0a5961..ff5edc8750b 100644 --- a/compiler/testData/codegen/box/bridges/complexTraitImpl.kt +++ b/compiler/testData/codegen/box/bridges/complexTraitImpl.kt @@ -1,14 +1,11 @@ -// TODO: muted automatically, investigate should it be ran for JS or not -// IGNORE_BACKEND: JS -import java.util.Arrays - +// WITH_RUNTIME abstract class A { abstract fun foo(): List } interface B { - fun foo(): ArrayList = ArrayList(Arrays.asList("B")) + fun foo(): ArrayList = ArrayList(listOf("B")) } open class C : A(), B { diff --git a/compiler/testData/codegen/box/bridges/noBridgeOnMutableCollectionInheritance.kt b/compiler/testData/codegen/box/bridges/noBridgeOnMutableCollectionInheritance.kt index 9b1cf547db0..59e364fe37f 100644 --- a/compiler/testData/codegen/box/bridges/noBridgeOnMutableCollectionInheritance.kt +++ b/compiler/testData/codegen/box/bridges/noBridgeOnMutableCollectionInheritance.kt @@ -1,6 +1,4 @@ -// TODO: muted automatically, investigate should it be ran for JS or not -// IGNORE_BACKEND: JS -import java.util.Arrays +// WITH_RUNTIME interface A { fun foo(): Collection @@ -11,7 +9,7 @@ interface B : A { } class C : B { - override fun foo(): MutableList = ArrayList(Arrays.asList("C")) + override fun foo(): MutableList = ArrayList(listOf("C")) } fun box(): String { diff --git a/compiler/testData/codegen/box/callableReference/function/sortListOfStrings.kt b/compiler/testData/codegen/box/callableReference/function/sortListOfStrings.kt index 917ace76a62..5672692f9a8 100644 --- a/compiler/testData/codegen/box/callableReference/function/sortListOfStrings.kt +++ b/compiler/testData/codegen/box/callableReference/function/sortListOfStrings.kt @@ -1,22 +1,14 @@ -// TODO: muted automatically, investigate should it be ran for JS or not -// IGNORE_BACKEND: JS - -import java.util.ArrayList -import java.util.Arrays -import java.util.Collections -import java.util.Comparator +// WITH_RUNTIME fun sort(list: MutableList, comparator: (String, String) -> Int) { - Collections.sort(list, object : Comparator { - override fun compare(p0: String, p1: String) = comparator(p0, p1) - }) + list.sortWith(Comparator(comparator)) } fun compare(s1: String, s2: String) = s1.compareTo(s2) fun box(): String { - val l = ArrayList(Arrays.asList("d", "b", "c", "e", "a")) + val l = mutableListOf("d", "b", "c", "e", "a") sort(l, ::compare) - if (l != Arrays.asList("a", "b", "c", "d", "e")) return "Fail: $l" + if (l != listOf("a", "b", "c", "d", "e")) return "Fail: $l" return "OK" } diff --git a/compiler/testData/codegen/box/casts/mutableCollections/asWithMutable.kt b/compiler/testData/codegen/box/casts/mutableCollections/asWithMutable.kt index b896ab5ea3b..093fae25b18 100644 --- a/compiler/testData/codegen/box/casts/mutableCollections/asWithMutable.kt +++ b/compiler/testData/codegen/box/casts/mutableCollections/asWithMutable.kt @@ -1,10 +1,5 @@ -// TODO: muted automatically, investigate should it be ran for JS or not -// IGNORE_BACKEND: JS - // WITH_RUNTIME -import java.util.* - class Itr : Iterator by ArrayList().iterator() class MItr : MutableIterator by ArrayList().iterator() class LItr : ListIterator by ArrayList().listIterator() @@ -37,7 +32,7 @@ inline fun asFailsWithCCE(operation: String, block: () -> Unit) { try { block() } - catch (e: java.lang.ClassCastException) { + catch (e: ClassCastException) { return } catch (e: Throwable) { diff --git a/compiler/testData/codegen/box/casts/mutableCollections/isWithMutable.kt b/compiler/testData/codegen/box/casts/mutableCollections/isWithMutable.kt index 2ec5791c1c1..56e8fb846c8 100644 --- a/compiler/testData/codegen/box/casts/mutableCollections/isWithMutable.kt +++ b/compiler/testData/codegen/box/casts/mutableCollections/isWithMutable.kt @@ -1,10 +1,5 @@ -// TODO: muted automatically, investigate should it be ran for JS or not -// IGNORE_BACKEND: JS - // WITH_RUNTIME -import java.util.* - class Itr : Iterator by ArrayList().iterator() class MItr : MutableIterator by ArrayList().iterator() class LItr : ListIterator by ArrayList().listIterator() @@ -33,6 +28,8 @@ class MME : MutableMap.MutableEntry { override fun setValue(value: String): String = throw UnsupportedOperationException() } +fun assert(condition: Boolean, message: () -> String) { if (!condition) throw AssertionError(message())} + fun box(): String { val itr = Itr() as Any val mitr = MItr() diff --git a/compiler/testData/codegen/box/casts/mutableCollections/reifiedAsWithMutable.kt b/compiler/testData/codegen/box/casts/mutableCollections/reifiedAsWithMutable.kt index 488b33be755..77d2d3b8683 100644 --- a/compiler/testData/codegen/box/casts/mutableCollections/reifiedAsWithMutable.kt +++ b/compiler/testData/codegen/box/casts/mutableCollections/reifiedAsWithMutable.kt @@ -1,10 +1,5 @@ -// TODO: muted automatically, investigate should it be ran for JS or not -// IGNORE_BACKEND: JS - // WITH_RUNTIME -import java.util.* - class Itr : Iterator by ArrayList().iterator() class MItr : MutableIterator by ArrayList().iterator() class LItr : ListIterator by ArrayList().listIterator() @@ -46,7 +41,7 @@ inline fun reifiedAsFailsWithCCE(x: Any, operation: String) { try { x as T } - catch (e: java.lang.ClassCastException) { + catch (e: ClassCastException) { return } catch (e: Throwable) { diff --git a/compiler/testData/codegen/box/casts/mutableCollections/reifiedIsWithMutable.kt b/compiler/testData/codegen/box/casts/mutableCollections/reifiedIsWithMutable.kt index 4266d12d25d..df6e233f20a 100644 --- a/compiler/testData/codegen/box/casts/mutableCollections/reifiedIsWithMutable.kt +++ b/compiler/testData/codegen/box/casts/mutableCollections/reifiedIsWithMutable.kt @@ -1,10 +1,5 @@ -// TODO: muted automatically, investigate should it be ran for JS or not -// IGNORE_BACKEND: JS - // WITH_RUNTIME -import java.util.* - class Itr : Iterator by ArrayList().iterator() class MItr : MutableIterator by ArrayList().iterator() class LItr : ListIterator by ArrayList().listIterator() @@ -36,6 +31,8 @@ class MME : MutableMap.MutableEntry { inline fun reifiedIs(x: Any): Boolean = x is T inline fun reifiedIsNot(x: Any): Boolean = x !is T +fun assert(condition: Boolean, message: () -> String) { if (!condition) throw AssertionError(message())} + fun box(): String { val itr = Itr() as Any val mitr = MItr() diff --git a/compiler/testData/codegen/box/casts/mutableCollections/safeAsWithMutable.kt b/compiler/testData/codegen/box/casts/mutableCollections/safeAsWithMutable.kt index 60cf1cd8860..58113095c09 100644 --- a/compiler/testData/codegen/box/casts/mutableCollections/safeAsWithMutable.kt +++ b/compiler/testData/codegen/box/casts/mutableCollections/safeAsWithMutable.kt @@ -1,10 +1,5 @@ -// TODO: muted automatically, investigate should it be ran for JS or not -// IGNORE_BACKEND: JS - // WITH_RUNTIME -import java.util.* - class Itr : Iterator by ArrayList().iterator() class MItr : MutableIterator by ArrayList().iterator() class LItr : ListIterator by ArrayList().listIterator() @@ -33,6 +28,9 @@ class MME : MutableMap.MutableEntry { override fun setValue(value: String): String = throw UnsupportedOperationException() } +fun assert(condition: Boolean, message: () -> String) { if (!condition) throw AssertionError(message())} + + inline fun safeAsReturnsNull(operation: String, cast: () -> Any?) { try { val x = cast() diff --git a/compiler/testData/codegen/box/controlStructures/continueInForCondition.kt b/compiler/testData/codegen/box/controlStructures/continueInForCondition.kt index e0d08a601ef..3ebace16102 100644 --- a/compiler/testData/codegen/box/controlStructures/continueInForCondition.kt +++ b/compiler/testData/codegen/box/controlStructures/continueInForCondition.kt @@ -1,9 +1,6 @@ -// TODO: muted automatically, investigate should it be ran for JS or not -// IGNORE_BACKEND: JS +// WITH_RUNTIME -import java.util.Arrays - -fun foo(): List? = Arrays.asList("abcde") +fun foo(): List? = listOf("abcde") fun box(): String { for (i in 1..3) { diff --git a/compiler/testData/codegen/box/controlStructures/kt513.kt b/compiler/testData/codegen/box/controlStructures/kt513.kt index 72fb0578b7b..74092c47aed 100644 --- a/compiler/testData/codegen/box/controlStructures/kt513.kt +++ b/compiler/testData/codegen/box/controlStructures/kt513.kt @@ -1,7 +1,4 @@ -// TODO: muted automatically, investigate should it be ran for JS or not -// IGNORE_BACKEND: JS - -import java.util.* +// WITH_RUNTIME class A() { infix fun ArrayList.add3(el: T) = add(el) @@ -22,6 +19,6 @@ fun box() : String{ list add2 i } A().test(list) - System.out?.println(list) + println(list) return "OK" } diff --git a/compiler/testData/codegen/box/extensionFunctions/kt475.kt b/compiler/testData/codegen/box/extensionFunctions/kt475.kt index 07b528353c9..f81998986f4 100644 --- a/compiler/testData/codegen/box/extensionFunctions/kt475.kt +++ b/compiler/testData/codegen/box/extensionFunctions/kt475.kt @@ -1,7 +1,3 @@ -// TODO: muted automatically, investigate should it be ran for JS or not -// IGNORE_BACKEND: JS - -import java.util.ArrayList fun box() : String { val array = ArrayList() @@ -14,7 +10,7 @@ fun box() : String { var ArrayList.length : Int get() = size - set(value: Int) = throw java.lang.Error() + set(value: Int) = throw Error() var ArrayList.last : T get() = get(size-1)!! diff --git a/compiler/testData/codegen/box/sam/constructors/comparator.kt b/compiler/testData/codegen/box/sam/constructors/comparator.kt index 46f45a6be59..894b52dfe03 100644 --- a/compiler/testData/codegen/box/sam/constructors/comparator.kt +++ b/compiler/testData/codegen/box/sam/constructors/comparator.kt @@ -1,11 +1,8 @@ -// TODO: muted automatically, investigate should it be ran for JS or not -// IGNORE_BACKEND: JS - -import java.util.* +// WITH_RUNTIME fun box(): String { - val list = ArrayList(Arrays.asList(3, 2, 4, 8, 1, 5)) - val expected = ArrayList(Arrays.asList(8, 5, 4, 3, 2, 1)) - Collections.sort(list, Comparator { a, b -> b - a }) + val list = mutableListOf(3, 2, 4, 8, 1, 5) + val expected = listOf(8, 5, 4, 3, 2, 1) + list.sortWith(Comparator { a, b -> b - a }) return if (list == expected) "OK" else list.toString() } \ No newline at end of file diff --git a/compiler/testData/codegen/box/sam/constructors/nonLiteralComparator.kt b/compiler/testData/codegen/box/sam/constructors/nonLiteralComparator.kt index b2e281a30ae..5dfa3b5926f 100644 --- a/compiler/testData/codegen/box/sam/constructors/nonLiteralComparator.kt +++ b/compiler/testData/codegen/box/sam/constructors/nonLiteralComparator.kt @@ -1,12 +1,9 @@ -// TODO: muted automatically, investigate should it be ran for JS or not -// IGNORE_BACKEND: JS - -import java.util.* +// WITH_RUNTIME fun box(): String { - val list = ArrayList(Arrays.asList(3, 2, 4, 8, 1, 5)) - val expected = ArrayList(Arrays.asList(8, 5, 4, 3, 2, 1)) + val list = mutableListOf(3, 2, 4, 8, 1, 5) + val expected = listOf(8, 5, 4, 3, 2, 1) val comparatorFun: (Int, Int) -> Int = { a, b -> b - a } - Collections.sort(list, Comparator(comparatorFun)) + list.sortWith(Comparator(comparatorFun)) return if (list == expected) "OK" else list.toString() } diff --git a/compiler/testData/codegen/box/toArray/kt3177-toTypedArray.kt b/compiler/testData/codegen/box/toArray/kt3177-toTypedArray.kt index 3b53b80a28e..6d941babc19 100644 --- a/compiler/testData/codegen/box/toArray/kt3177-toTypedArray.kt +++ b/compiler/testData/codegen/box/toArray/kt3177-toTypedArray.kt @@ -1,11 +1,5 @@ -// TODO: muted automatically, investigate should it be ran for JS or not -// IGNORE_BACKEND: JS - // WITH_RUNTIME -import java.util.ArrayList -import java.util.Arrays - fun box(): String { val list = ArrayList>() list.add(Pair("Sample", "http://cyber.law.harvard.edu/rss/examples/rss2sample.xml")) @@ -13,7 +7,7 @@ fun box(): String { val keys = list.map { it.first }.toTypedArray() - val keysToString = Arrays.toString(keys) + val keysToString = keys.contentToString() if (keysToString != "[Sample, Scripting]") return keysToString return "OK" diff --git a/compiler/testData/codegen/box/toArray/returnToTypedArray.kt b/compiler/testData/codegen/box/toArray/returnToTypedArray.kt index 41c2f7fad44..5986dbe5bf4 100644 --- a/compiler/testData/codegen/box/toArray/returnToTypedArray.kt +++ b/compiler/testData/codegen/box/toArray/returnToTypedArray.kt @@ -1,14 +1,9 @@ -// TODO: muted automatically, investigate should it be ran for JS or not -// IGNORE_BACKEND: JS - // WITH_RUNTIME -import java.util.Arrays - -fun getCopyToArray(): Array = Arrays.asList(2, 3, 9).toTypedArray() +fun getCopyToArray(): Array = listOf(2, 3, 9).toTypedArray() fun box(): String { - val str = Arrays.toString(getCopyToArray()) + val str = getCopyToArray().contentToString() if (str != "[2, 3, 9]") return str return "OK" diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 1a71b851458..cd354d7af7a 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -1226,13 +1226,7 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { @TestMetadata("complexTraitImpl.kt") public void testComplexTraitImpl() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/bridges/complexTraitImpl.kt"); - try { - doTest(fileName); - } - catch (Throwable ignore) { - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + doTest(fileName); } @TestMetadata("delegation.kt") @@ -1388,13 +1382,7 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { @TestMetadata("noBridgeOnMutableCollectionInheritance.kt") public void testNoBridgeOnMutableCollectionInheritance() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/bridges/noBridgeOnMutableCollectionInheritance.kt"); - try { - doTest(fileName); - } - catch (Throwable ignore) { - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + doTest(fileName); } @TestMetadata("overrideAbstractProperty.kt") @@ -2237,13 +2225,7 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { @TestMetadata("sortListOfStrings.kt") public void testSortListOfStrings() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/function/sortListOfStrings.kt"); - try { - doTest(fileName); - } - catch (Throwable ignore) { - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + doTest(fileName); } @TestMetadata("topLevelFromClass.kt") @@ -2999,25 +2981,13 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { @TestMetadata("asWithMutable.kt") public void testAsWithMutable() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/casts/mutableCollections/asWithMutable.kt"); - try { - doTest(fileName); - } - catch (Throwable ignore) { - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + doTest(fileName); } @TestMetadata("isWithMutable.kt") public void testIsWithMutable() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/casts/mutableCollections/isWithMutable.kt"); - try { - doTest(fileName); - } - catch (Throwable ignore) { - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + doTest(fileName); } @TestMetadata("mutabilityMarkerInterfaces.kt") @@ -3035,25 +3005,13 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { @TestMetadata("reifiedAsWithMutable.kt") public void testReifiedAsWithMutable() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/casts/mutableCollections/reifiedAsWithMutable.kt"); - try { - doTest(fileName); - } - catch (Throwable ignore) { - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + doTest(fileName); } @TestMetadata("reifiedIsWithMutable.kt") public void testReifiedIsWithMutable() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/casts/mutableCollections/reifiedIsWithMutable.kt"); - try { - doTest(fileName); - } - catch (Throwable ignore) { - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + doTest(fileName); } @TestMetadata("reifiedSafeAsWithMutable.kt") @@ -3065,13 +3023,7 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { @TestMetadata("safeAsWithMutable.kt") public void testSafeAsWithMutable() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/casts/mutableCollections/safeAsWithMutable.kt"); - try { - doTest(fileName); - } - catch (Throwable ignore) { - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + doTest(fileName); } @TestMetadata("weirdMutableCasts.kt") @@ -4578,13 +4530,7 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { @TestMetadata("continueInForCondition.kt") public void testContinueInForCondition() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/continueInForCondition.kt"); - try { - doTest(fileName); - } - catch (Throwable ignore) { - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + doTest(fileName); } @TestMetadata("continueInWhile.kt") @@ -4872,13 +4818,7 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { @TestMetadata("kt513.kt") public void testKt513() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/kt513.kt"); - try { - doTest(fileName); - } - catch (Throwable ignore) { - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + doTest(fileName); } @TestMetadata("kt628.kt") @@ -7809,13 +7749,7 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { @TestMetadata("kt475.kt") public void testKt475() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/extensionFunctions/kt475.kt"); - try { - doTest(fileName); - } - catch (Throwable ignore) { - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + doTest(fileName); } @TestMetadata("kt5467.kt") @@ -18935,13 +18869,7 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { @TestMetadata("comparator.kt") public void testComparator() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/sam/constructors/comparator.kt"); - try { - doTest(fileName); - } - catch (Throwable ignore) { - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + doTest(fileName); } @TestMetadata("filenameFilter.kt") @@ -18959,13 +18887,7 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { @TestMetadata("nonLiteralComparator.kt") public void testNonLiteralComparator() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/sam/constructors/nonLiteralComparator.kt"); - try { - doTest(fileName); - } - catch (Throwable ignore) { - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + doTest(fileName); } @TestMetadata("nonLiteralFilenameFilter.kt") @@ -20175,25 +20097,13 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { @TestMetadata("kt3177-toTypedArray.kt") public void testKt3177_toTypedArray() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/toArray/kt3177-toTypedArray.kt"); - try { - doTest(fileName); - } - catch (Throwable ignore) { - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + doTest(fileName); } @TestMetadata("returnToTypedArray.kt") public void testReturnToTypedArray() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/toArray/returnToTypedArray.kt"); - try { - doTest(fileName); - } - catch (Throwable ignore) { - return; - } - throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + doTest(fileName); } @TestMetadata("toTypedArray.kt")