diff --git a/js/js.libraries/test/core/testUtils.kt b/js/js.libraries/test/core/testUtils.kt index 016af2ec2c9..0d8ec1aefd1 100644 --- a/js/js.libraries/test/core/testUtils.kt +++ b/js/js.libraries/test/core/testUtils.kt @@ -17,8 +17,7 @@ package kotlin.test public fun assertTypeEquals(expected: Any?, actual: Any?) { - //TODO: find analogue - //assertEquals(expected?.javaClass, actual?.javaClass) + assertEquals(expected?.let { it::class.js }, actual?.let { it::class.js }) } internal inline fun String.removeLeadingPlusOnJava6(): String = this diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsUnitTestBase.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsUnitTestBase.java index c4dc0692e50..5df55874153 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsUnitTestBase.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsUnitTestBase.java @@ -61,6 +61,7 @@ public abstract class JsUnitTestBase extends MultipleFilesTranslationTest { protected List additionalKotlinFiles() { List result = StdLibTestBase.removeAdHocAssertions(super.additionalKotlinFiles()); result.add(JS_TESTS_KT); + result.add("libraries/stdlib/test/testUtils.kt"); return result; } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/StdLibTestToJSTest.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/StdLibTestToJSTest.java index dbbffe52d21..d1cc0620173 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/StdLibTestToJSTest.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/StdLibTestToJSTest.java @@ -31,6 +31,7 @@ public class StdLibTestToJSTest extends StdLibQUnitTestSupport { "collections/IteratorsTest.kt", "collections/CollectionBehaviors.kt", "collections/ComparisonDSL.kt", + "testUtils.kt", "../../../js/js.libraries/test/core/testUtils.kt", "text/StringTest.kt", "OrderingTest.kt", diff --git a/libraries/stdlib/jre7/test/TryWithResourcesAutoCloseableTest.kt b/libraries/stdlib/jre7/test/TryWithResourcesAutoCloseableTest.kt index a98d6193ec7..7a09d34ac50 100644 --- a/libraries/stdlib/jre7/test/TryWithResourcesAutoCloseableTest.kt +++ b/libraries/stdlib/jre7/test/TryWithResourcesAutoCloseableTest.kt @@ -55,8 +55,8 @@ class TryWithResourcesAutoCloseableTest { @Test fun opFailsCloseFailsTwice() { val e = assertFails { - Resource(faultyClose = true).use { res1 -> - Resource(faultyClose = true).use { res2 -> + Resource(faultyClose = true).use { _ -> + Resource(faultyClose = true).use { _ -> error("op fail") } } diff --git a/libraries/stdlib/jre7/test/TryWithResourcesCloseableTest.kt b/libraries/stdlib/jre7/test/TryWithResourcesCloseableTest.kt index d67583cc202..fe612dafb89 100644 --- a/libraries/stdlib/jre7/test/TryWithResourcesCloseableTest.kt +++ b/libraries/stdlib/jre7/test/TryWithResourcesCloseableTest.kt @@ -56,8 +56,8 @@ class TryWithResourcesCloseableTest { @Ignore @Test fun opFailsCloseFailsTwice() { val e = assertFails { - Resource(faultyClose = true).use { res1 -> - Resource(faultyClose = true).use { res2 -> + Resource(faultyClose = true).use { _ -> + Resource(faultyClose = true).use { _ -> error("op fail") } } diff --git a/libraries/stdlib/jre8/test/collections/MapTest.kt b/libraries/stdlib/jre8/test/collections/MapTest.kt index e3afaadcdda..25ef2317005 100644 --- a/libraries/stdlib/jre8/test/collections/MapTest.kt +++ b/libraries/stdlib/jre8/test/collections/MapTest.kt @@ -89,27 +89,27 @@ class MapTest { val map = mutableMapOf(2 to "x") assertEquals("2x", map.computeIfPresent(2) { k, v -> k.toString() + v }) assertEquals(null, map.computeIfPresent(3) { k, v -> k.toString() + v }) - assertEquals(null, map.computeIfPresent(2) { k, v -> null }) + assertEquals(null, map.computeIfPresent(2) { _, _ -> null }) assertFalse(2 in map) val map2 = mutableMapOf(2 to "x") assertEquals("2x", map2.computeIfPresent(2) { k, v -> k.toString() + v }) assertEquals(null, map2.computeIfPresent(3) { k, v -> k.toString() + v }) - assertEquals(null, map2.computeIfPresent(2) { k, v -> null }) + assertEquals(null, map2.computeIfPresent(2) { _, _ -> null }) assertFalse(2 in map2) } @Test fun compute() { val map = mutableMapOf(2 to "x") assertEquals("2x", map.compute(2) { k, v -> k.toString() + v }) - assertEquals(null, map.compute(2) { k, v -> null }) + assertEquals(null, map.compute(2) { _, _ -> null }) assertFalse { 2 in map } assertEquals("1null", map.compute(1) { k, v -> k.toString() + v }) } @Test fun merge() { val map = mutableMapOf(2 to "x") - assertEquals("y", map.merge(3, "y") { old, new -> null }) + assertEquals("y", map.merge(3, "y") { _, _ -> null }) assertEquals(null, map.merge(3, "z") { old, new -> assertEquals("y", old) assertEquals("z", new) @@ -122,7 +122,7 @@ class MapTest { // new value must be V&Any assertEquals("e", map2.merge(1, "e") { old, new -> (old.length + new.length).toString() ?: null }) assertEquals("3", map2.merge(1, "fg") { old, new -> (old.length + new.length).toString() ?: null }) - assertEquals(null, map2.merge(1, "3") { old, new -> null }) + assertEquals(null, map2.merge(1, "3") { _, _ -> null }) assertFalse(1 in map) } } \ No newline at end of file diff --git a/libraries/stdlib/test/collections/ArraysTest.kt b/libraries/stdlib/test/collections/ArraysTest.kt index f04d4867af3..0f7be9c6921 100644 --- a/libraries/stdlib/test/collections/ArraysTest.kt +++ b/libraries/stdlib/test/collections/ArraysTest.kt @@ -760,7 +760,7 @@ class ArraysTest { expect(1.toShort()) { shortArrayOf(3, 2, 1).reduceIndexed { index, a, b -> if (index != 2) (a - b).toShort() else a.toShort() } } assertFailsWith { - intArrayOf().reduceIndexed { index, a, b -> a + b } + intArrayOf().reduceIndexed { index, a, b -> index + a + b } } } @@ -776,7 +776,7 @@ class ArraysTest { expect(1.toShort()) { shortArrayOf(3, 2, 1).reduceRightIndexed { index, a, b -> if (index != 1) (a - b).toShort() else a.toShort() } } assertFailsWith { - intArrayOf().reduceRightIndexed { index, a, b -> a + b } + intArrayOf().reduceRightIndexed { index, a, b -> index + a + b } } } @@ -1056,6 +1056,7 @@ class ArraysTest { val arr1: Array> = arrayOf(arrayOf(1, 2, 3), arrayOf(4, 5, 6)) val arr2: Array> = arr1 val arr3: Array> = arr1 + @Suppress("UNCHECKED_CAST") val arr4: Array> = arr1 as Array> val expected = listOf(1, 2, 3, 4, 5, 6) diff --git a/libraries/stdlib/test/collections/CollectionJVMTest.kt b/libraries/stdlib/test/collections/CollectionJVMTest.kt index 532b59689e3..0c641dc479a 100644 --- a/libraries/stdlib/test/collections/CollectionJVMTest.kt +++ b/libraries/stdlib/test/collections/CollectionJVMTest.kt @@ -215,8 +215,3 @@ class CollectionJVMTest { assertEquals(expected, actual) } } - - -public fun assertTypeEquals(expected: Any?, actual: Any?) { - assertEquals(expected?.javaClass, actual?.javaClass) -} diff --git a/libraries/stdlib/test/collections/CollectionTest.kt b/libraries/stdlib/test/collections/CollectionTest.kt index 040f49c7e24..2d035aee8b8 100644 --- a/libraries/stdlib/test/collections/CollectionTest.kt +++ b/libraries/stdlib/test/collections/CollectionTest.kt @@ -295,7 +295,7 @@ class CollectionTest { } assertFailsWith { - arrayListOf().reduceIndexed { index, a, b -> a + b } + arrayListOf().reduceIndexed { index, a, b -> index + a + b } } } @@ -315,7 +315,7 @@ class CollectionTest { } assertFailsWith { - arrayListOf().reduceRightIndexed { index, a, b -> a + b } + arrayListOf().reduceRightIndexed { index, a, b -> index + a + b } } } @@ -626,6 +626,7 @@ class CollectionTest { // lists throw an exception if out of range assertFails { + @Suppress("UNUSED_VARIABLE") val outOfBounds = list[2] } diff --git a/libraries/stdlib/test/collections/ComparisonDSL.kt b/libraries/stdlib/test/collections/ComparisonDSL.kt index d0298812d60..d50b70503af 100644 --- a/libraries/stdlib/test/collections/ComparisonDSL.kt +++ b/libraries/stdlib/test/collections/ComparisonDSL.kt @@ -1,5 +1,6 @@ package test.collections +import test.* import kotlin.test.* public fun compare(expected: T, actual: T, block:CompareContext.() -> Unit) { diff --git a/libraries/stdlib/test/collections/GroupingTest.kt b/libraries/stdlib/test/collections/GroupingTest.kt index 57db6b9c4ba..d6fba98d6fc 100644 --- a/libraries/stdlib/test/collections/GroupingTest.kt +++ b/libraries/stdlib/test/collections/GroupingTest.kt @@ -54,7 +54,7 @@ class GroupingTest { val elements = listOf("foo", "bar", "flea", "zoo", "biscuit") val result = elements.groupingBy { it.first() } - .fold({ k, e -> Collector(k)}, { k, acc, e -> acc.accumulateIfEven(e) }) + .fold({ k, _ -> Collector(k)}, { _, acc, e -> acc.accumulateIfEven(e) }) val ordered = result.values.sortedBy { it.key }.map { it.toPair() } assertEquals(listOf('b' to emptyList(), 'f' to listOf("flea"), 'z' to emptyList()), ordered) @@ -62,8 +62,8 @@ class GroupingTest { val moreElements = listOf("fire", "zero") val result2 = moreElements.groupingBy { it.first() } .foldTo(HashMap(result), - { k, e -> error("should not be called for $k") }, - { k, acc, e -> acc.accumulateIfEven(e) }) + { k, _ -> error("should not be called for $k") }, + { _, acc, e -> acc.accumulateIfEven(e) }) val ordered2 = result2.values.sortedBy { it.key }.map { it.toPair() } assertEquals(listOf('b' to emptyList(), 'f' to listOf("flea", "fire"), 'z' to listOf("zero")), ordered2) @@ -75,12 +75,12 @@ class GroupingTest { val elements = listOf("foo", "bar", "flea", "zoo", "biscuit") fun Char.isVowel() = this in "aeiou" fun String.countVowels() = count(Char::isVowel) - val maxVowels = elements.groupingBy { it.first() }.reduce { k, a, b -> maxOfBy(a, b, String::countVowels) } + val maxVowels = elements.groupingBy { it.first() }.reduce { _, a, b -> maxOfBy(a, b, String::countVowels) } assertEquals(mapOf('f' to "foo", 'b' to "biscuit", 'z' to "zoo"), maxVowels) val elements2 = listOf("bar", "z", "fork") - val concats = elements2.groupingBy { it.first() }.reduceTo(HashMap(maxVowels)) { k, acc, e -> acc + e } + val concats = elements2.groupingBy { it.first() }.reduceTo(HashMap(maxVowels)) { _, acc, e -> acc + e } assertEquals(mapOf('f' to "foofork", 'b' to "biscuitbar", 'z' to "zooz"), concats) } diff --git a/libraries/stdlib/test/collections/IterableTests.kt b/libraries/stdlib/test/collections/IterableTests.kt index 729ed8358af..10b9d31b15e 100644 --- a/libraries/stdlib/test/collections/IterableTests.kt +++ b/libraries/stdlib/test/collections/IterableTests.kt @@ -17,6 +17,7 @@ package test.collections import org.junit.Test +import test.* import kotlin.test.* fun iterableOf(vararg items: T): Iterable = Iterable { items.iterator() } @@ -200,7 +201,7 @@ abstract class IterableTests>(val data: T, val empty: T) { assertTrue(data === newData) // static types test - val list: ArrayList = arrayListOf(1, 2, 3).onEach { } + assertStaticTypeIs>(arrayListOf(1, 2, 3).onEach { }) } @Test diff --git a/libraries/stdlib/test/collections/MapTest.kt b/libraries/stdlib/test/collections/MapTest.kt index 2c995d37381..913edb14a42 100644 --- a/libraries/stdlib/test/collections/MapTest.kt +++ b/libraries/stdlib/test/collections/MapTest.kt @@ -1,13 +1,11 @@ package test.collections import kotlin.test.* +import test.* import org.junit.Test class MapTest { - // just a static type check - fun assertStaticTypeIs(value: T) {} - @Test fun getOrElse() { val data = mapOf() val a = data.getOrElse("foo") { 2 } @@ -109,7 +107,9 @@ class MapTest { assertTrue(map === newMap) // static types test - val m: HashMap = hashMapOf("a" to "b").onEach { } + assertStaticTypeIs>( + hashMapOf("a" to "b").onEach { } + ) } @Test fun stream() { diff --git a/libraries/stdlib/test/collections/SequenceTest.kt b/libraries/stdlib/test/collections/SequenceTest.kt index e838c19fb0c..82f645ac506 100644 --- a/libraries/stdlib/test/collections/SequenceTest.kt +++ b/libraries/stdlib/test/collections/SequenceTest.kt @@ -39,7 +39,7 @@ public class SequenceTest { } @Test fun filterIndexed() { - assertEquals(listOf(1, 2, 5, 13, 34), fibonacci().filterIndexed { index, value -> index % 2 == 1 }.take(5).toList()) + assertEquals(listOf(1, 2, 5, 13, 34), fibonacci().filterIndexed { index, _ -> index % 2 == 1 }.take(5).toList()) } @Test fun filterNullable() { diff --git a/libraries/stdlib/test/concurrent/TimerTest.kt b/libraries/stdlib/test/concurrent/TimerTest.kt index 3c746af20a9..e24d59300e7 100644 --- a/libraries/stdlib/test/concurrent/TimerTest.kt +++ b/libraries/stdlib/test/concurrent/TimerTest.kt @@ -16,7 +16,7 @@ class TimerTest { val task = timer.scheduleAtFixedRate(1000, 100) { val current = counter.incrementAndGet() - // println("Timer fired at $current") + if (false) println("Timer fired at $current") } Thread.sleep(1500) task.cancel() diff --git a/libraries/stdlib/test/io/FileTreeWalks.kt b/libraries/stdlib/test/io/FileTreeWalks.kt index 872cd1b5941..98271e4a6e7 100644 --- a/libraries/stdlib/test/io/FileTreeWalks.kt +++ b/libraries/stdlib/test/io/FileTreeWalks.kt @@ -229,10 +229,10 @@ class FileTreeWalkTest { val basedir = createTestFiles() try { var i = 0 - basedir.walkTopDown().forEach { it -> i++ } + basedir.walkTopDown().forEach { _ -> i++ } assertEquals(10, i); i = 0 - basedir.walkBottomUp().forEach { it -> i++ } + basedir.walkBottomUp().forEach { _ -> i++ } assertEquals(10, i); } finally { basedir.deleteRecursively() @@ -282,7 +282,7 @@ class FileTreeWalkTest { files.add(file.relativeToOrSelf(basedir)) } - fun visitDirectoryFailed(dir: File, e: IOException) { + fun visitDirectoryFailed(dir: File, @Suppress("UNUSED_PARAMETER") e: IOException) { assertEquals(stack.last(), dir) //stack.removeAt(stack.lastIndex) failed.add(dir.name) @@ -405,7 +405,7 @@ class FileTreeWalkTest { try { File(basedir, "8/4.txt").createNewFile() var count = 0 - basedir.walkTopDown().takeWhile { it -> count == 0 }.forEach { + basedir.walkTopDown().takeWhile { _ -> count == 0 }.forEach { if (it.name == "4.txt") { count++ } diff --git a/libraries/stdlib/test/io/Files.kt b/libraries/stdlib/test/io/Files.kt index 7f6e6e027ab..eeffcde32ab 100644 --- a/libraries/stdlib/test/io/Files.kt +++ b/libraries/stdlib/test/io/Files.kt @@ -141,6 +141,7 @@ class FilesTest { assertEquals("", file.toRelativeString(file), "file should have empty path relative to itself: $file") for (file in files) { + @Suppress("NAME_SHADOWING") for (base in bases) { val rootedFile = root.resolve(file) val rootedBase = root.resolve(base) @@ -158,7 +159,9 @@ class FilesTest { fun assertFailsRelativeTo(file: File, base: File) { val e = assertFailsWith("file: $file, base: $base") { file.relativeTo(base) } -// println(e.message) + val message = assertNotNull(e.message) + assert(file.toString() in message) + assert(base.toString() in message) } val allFiles = listOf(absolute, relative) + if (isBackslashSeparator) listOf(networkShare1, networkShare2) else emptyList() @@ -220,7 +223,7 @@ class FilesTest { if (isBackslashSeparator) { val diskRooted = File("""C:\foo\bar""") - assertTrue(rooted.isRooted) + assertTrue(diskRooted.isRooted) // assertEquals("""C:\""", diskRooted.rootName) val networkRooted = File("""\\network\share\""") @@ -516,7 +519,7 @@ class FilesTest { var conflicts = 0 src.copyRecursively(dst) { - file: File, e: IOException -> + _: File, e: IOException -> if (e is FileAlreadyExistsException) { conflicts++ OnErrorAction.SKIP @@ -531,7 +534,7 @@ class FilesTest { dst.deleteRecursively() var caught = false assertTrue(src.copyRecursively(dst) { - file: File, e: IOException -> + _: File, e: IOException -> if (e is AccessDeniedException) { caught = true OnErrorAction.SKIP @@ -552,10 +555,7 @@ class FilesTest { src.copyRecursively(dst) } - assertFalse(src.copyRecursively(dst) { - file: File, e: IOException -> - OnErrorAction.TERMINATE - }) + assertFalse(src.copyRecursively(dst) { _, _ -> OnErrorAction.TERMINATE }) } finally { src.deleteRecursively() dst.deleteRecursively() diff --git a/libraries/stdlib/test/io/ReadWrite.kt b/libraries/stdlib/test/io/ReadWrite.kt index c39c967ef85..4ac64f703a3 100644 --- a/libraries/stdlib/test/io/ReadWrite.kt +++ b/libraries/stdlib/test/io/ReadWrite.kt @@ -143,7 +143,7 @@ class ReadWriteTest { } @Test fun testPlatformNullUse() { - fun platformNull() = java.util.Collections.singleton(null as T).first() + fun platformNull() = @Suppress("UNCHECKED_CAST") java.util.Collections.singleton(null as T).first() val resource = platformNull() val result = resource.use { "ok" diff --git a/libraries/stdlib/test/js/MapJsTest.kt b/libraries/stdlib/test/js/MapJsTest.kt index 65b730b1125..dfbe22e5f7d 100644 --- a/libraries/stdlib/test/js/MapJsTest.kt +++ b/libraries/stdlib/test/js/MapJsTest.kt @@ -11,6 +11,7 @@ class ComplexMapJsTest : MapJsTest() { HashMap() HashMap(3) HashMap(3, 0.5f) + @Suppress("UNCHECKED_CAST") val map = HashMap(createTestMap() as HashMap) assertEquals(KEYS.toNormalizedList(), map.keys.toNormalizedList() as List) diff --git a/libraries/stdlib/test/js/SetJsTest.kt b/libraries/stdlib/test/js/SetJsTest.kt index 48f2c8e5cc3..f05efe7de33 100644 --- a/libraries/stdlib/test/js/SetJsTest.kt +++ b/libraries/stdlib/test/js/SetJsTest.kt @@ -12,6 +12,7 @@ class ComplexSetJsTest : SetJsTest() { HashSet(3) HashSet(3, 0.5f) + @Suppress("UNCHECKED_CAST") val set = HashSet(data as HashSet) assertEquals(data, set) diff --git a/libraries/stdlib/test/numbers/CompanionIntrinsicObjectsJVMTest.kt b/libraries/stdlib/test/numbers/CompanionIntrinsicObjectsJVMTest.kt index 8d94efea36b..d540edd6544 100644 --- a/libraries/stdlib/test/numbers/CompanionIntrinsicObjectsJVMTest.kt +++ b/libraries/stdlib/test/numbers/CompanionIntrinsicObjectsJVMTest.kt @@ -24,6 +24,7 @@ import org.junit.Test class CompanionIntrinsicObjectsJVMTest { @Test fun intTest() { val i = Int + i.MAX_VALUE assertEquals(java.lang.Integer.MAX_VALUE, Int.MAX_VALUE) assertEquals(java.lang.Integer.MIN_VALUE, Int.MIN_VALUE) @@ -31,6 +32,7 @@ class CompanionIntrinsicObjectsJVMTest { @Test fun doubleTest() { val d = Double + d.NaN assertEquals(java.lang.Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY) assertEquals(java.lang.Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY) @@ -42,6 +44,7 @@ class CompanionIntrinsicObjectsJVMTest { @Test fun floatTest() { val f = Float + f.NEGATIVE_INFINITY assertEquals(java.lang.Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY) assertEquals(java.lang.Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY) @@ -53,6 +56,7 @@ class CompanionIntrinsicObjectsJVMTest { @Test fun longTest() { val l = Long + l.MAX_VALUE assertEquals(java.lang.Long.MAX_VALUE, Long.MAX_VALUE) assertEquals(java.lang.Long.MIN_VALUE, Long.MIN_VALUE) @@ -60,6 +64,7 @@ class CompanionIntrinsicObjectsJVMTest { @Test fun shortTest() { val s = Short + s.MIN_VALUE assertEquals(java.lang.Short.MAX_VALUE, Short.MAX_VALUE) assertEquals(java.lang.Short.MIN_VALUE, Short.MIN_VALUE) @@ -67,6 +72,7 @@ class CompanionIntrinsicObjectsJVMTest { @Test fun byteTest() { val b = Byte + b.MAX_VALUE assertEquals(java.lang.Byte.MAX_VALUE, Byte.MAX_VALUE) assertEquals(java.lang.Byte.MIN_VALUE, Byte.MIN_VALUE) @@ -74,12 +80,14 @@ class CompanionIntrinsicObjectsJVMTest { @Test fun charTest() { val ch = Char + ch.MIN_SURROGATE assertEquals(ch, Char) } @Test fun stringTest() { val s = String + s.CASE_INSENSITIVE_ORDER assertEquals(s, String) } diff --git a/libraries/stdlib/test/properties/delegation/DelegationTest.kt b/libraries/stdlib/test/properties/delegation/DelegationTest.kt index 449cffbb8eb..97538bec34b 100644 --- a/libraries/stdlib/test/properties/delegation/DelegationTest.kt +++ b/libraries/stdlib/test/properties/delegation/DelegationTest.kt @@ -27,6 +27,7 @@ class ObservablePropertyTest { var b: Int by Delegates.observable(1, { property, old, new -> assertEquals("b", property.name) + if (!result) assertEquals(1, old) result = true assertEquals(new, b, "New value has already been set") }) diff --git a/libraries/stdlib/test/ranges/CoercionTest.kt b/libraries/stdlib/test/ranges/CoercionTest.kt index 0c2d43ff983..1813be922f1 100644 --- a/libraries/stdlib/test/ranges/CoercionTest.kt +++ b/libraries/stdlib/test/ranges/CoercionTest.kt @@ -5,17 +5,6 @@ import kotlin.test.* class CoercionTest { - fun usage() { - val n = 1 - // infix usage - val n1 = n.coerceAtLeast(2) - // function usage - val n2 = n.coerceAtLeast(2) - - // infix with range - val n3 = n.coerceIn(2..5) - } - @Test fun coercionsInt() { expect(5) { 5.coerceAtLeast(1) } diff --git a/libraries/stdlib/test/ranges/RangeJVMTest.kt b/libraries/stdlib/test/ranges/RangeJVMTest.kt deleted file mode 100644 index b70634b3020..00000000000 --- a/libraries/stdlib/test/ranges/RangeJVMTest.kt +++ /dev/null @@ -1,60 +0,0 @@ -@file:kotlin.jvm.JvmVersion -package test.ranges - -import java.lang.Double as jDouble -import java.lang.Float as jFloat -import org.junit.Test -import kotlin.test.* - -public class RangeJVMTest { - - @Test fun doubleRange() { - val range = -1.0..3.14159265358979 - assertFalse(jDouble.NEGATIVE_INFINITY in range) - assertFalse(jDouble.POSITIVE_INFINITY in range) - assertFalse(jDouble.NaN in range) - } - - @Test fun floatRange() { - val range = -1.0f..3.14159f - assertFalse(jFloat.NEGATIVE_INFINITY in range) - assertFalse(jFloat.POSITIVE_INFINITY in range) - - assertFalse(jFloat.NaN in range) - } - - @Test fun illegalProgressionCreation() { - fun assertFailsWithIllegalArgument(f: () -> Unit) = assertFailsWith(IllegalArgumentException::class, block = f) - // create Progression explicitly with increment = 0 - assertFailsWithIllegalArgument { IntProgression.fromClosedRange(0, 5, 0) } - assertFailsWithIllegalArgument { LongProgression.fromClosedRange(0, 5, 0) } - assertFailsWithIllegalArgument { CharProgression.fromClosedRange('a', 'z', 0) } - - - assertFailsWithIllegalArgument { 0..5 step 0 } - assertFailsWithIllegalArgument { 0.toByte()..5.toByte() step 0 } - assertFailsWithIllegalArgument { 0.toShort()..5.toShort() step 0 } - assertFailsWithIllegalArgument { 0L..5L step 0L } - assertFailsWithIllegalArgument { 'a'..'z' step 0 } - - assertFailsWithIllegalArgument { 0 downTo -5 step 0 } - assertFailsWithIllegalArgument { 0.toByte() downTo -5.toByte() step 0 } - assertFailsWithIllegalArgument { 0.toShort() downTo -5.toShort() step 0 } - assertFailsWithIllegalArgument { 0L downTo -5L step 0L } - assertFailsWithIllegalArgument { 'z' downTo 'a' step 0 } - - assertFailsWithIllegalArgument { 0..5 step -2 } - assertFailsWithIllegalArgument { 0.toByte()..5.toByte() step -2 } - assertFailsWithIllegalArgument { 0.toShort()..5.toShort() step -2 } - assertFailsWithIllegalArgument { 0L..5L step -2L } - assertFailsWithIllegalArgument { 'a'..'z' step -2 } - - - assertFailsWithIllegalArgument { 0 downTo -5 step -2 } - assertFailsWithIllegalArgument { 0.toByte() downTo -5.toByte() step -2 } - assertFailsWithIllegalArgument { 0.toShort() downTo -5.toShort() step -2 } - assertFailsWithIllegalArgument { 0L downTo -5L step -2L } - assertFailsWithIllegalArgument { 'z' downTo 'a' step -2 } - - } -} \ No newline at end of file diff --git a/libraries/stdlib/test/ranges/RangeTest.kt b/libraries/stdlib/test/ranges/RangeTest.kt index b9ae43af126..d2586782677 100644 --- a/libraries/stdlib/test/ranges/RangeTest.kt +++ b/libraries/stdlib/test/ranges/RangeTest.kt @@ -341,4 +341,39 @@ public class RangeTest { assertFalse(range.isEmpty()) } + + private fun assertFailsWithIllegalArgument(f: () -> Unit) = assertFailsWith { f() } + + @Test fun illegalProgressionCreation() { + // create Progression explicitly with increment = 0 + assertFailsWithIllegalArgument { IntProgression.fromClosedRange(0, 5, 0) } + assertFailsWithIllegalArgument { LongProgression.fromClosedRange(0, 5, 0) } + assertFailsWithIllegalArgument { CharProgression.fromClosedRange('a', 'z', 0) } + + + assertFailsWithIllegalArgument { 0..5 step 0 } + assertFailsWithIllegalArgument { 0.toByte()..5.toByte() step 0 } + assertFailsWithIllegalArgument { 0.toShort()..5.toShort() step 0 } + assertFailsWithIllegalArgument { 0L..5L step 0L } + assertFailsWithIllegalArgument { 'a'..'z' step 0 } + + assertFailsWithIllegalArgument { 0 downTo -5 step 0 } + assertFailsWithIllegalArgument { 0.toByte() downTo -5.toByte() step 0 } + assertFailsWithIllegalArgument { 0.toShort() downTo -5.toShort() step 0 } + assertFailsWithIllegalArgument { 0L downTo -5L step 0L } + assertFailsWithIllegalArgument { 'z' downTo 'a' step 0 } + + assertFailsWithIllegalArgument { 0..5 step -2 } + assertFailsWithIllegalArgument { 0.toByte()..5.toByte() step -2 } + assertFailsWithIllegalArgument { 0.toShort()..5.toShort() step -2 } + assertFailsWithIllegalArgument { 0L..5L step -2L } + assertFailsWithIllegalArgument { 'a'..'z' step -2 } + + + assertFailsWithIllegalArgument { 0 downTo -5 step -2 } + assertFailsWithIllegalArgument { 0.toByte() downTo -5.toByte() step -2 } + assertFailsWithIllegalArgument { 0.toShort() downTo -5.toShort() step -2 } + assertFailsWithIllegalArgument { 0L downTo -5L step -2L } + assertFailsWithIllegalArgument { 'z' downTo 'a' step -2 } + } } \ No newline at end of file diff --git a/libraries/stdlib/test/reflection/AnnotationsTest.kt b/libraries/stdlib/test/reflection/AnnotationsTest.kt index 0278d446af4..b1e9214241a 100644 --- a/libraries/stdlib/test/reflection/AnnotationsTest.kt +++ b/libraries/stdlib/test/reflection/AnnotationsTest.kt @@ -1,4 +1,5 @@ @file:kotlin.jvm.JvmVersion +@file:Suppress("DEPRECATION", "DEPRECATED_JAVA_ANNOTATION") package test.reflection import kotlin.test.* diff --git a/libraries/stdlib/test/testUtils.kt b/libraries/stdlib/test/testUtils.kt new file mode 100644 index 00000000000..c4c80180195 --- /dev/null +++ b/libraries/stdlib/test/testUtils.kt @@ -0,0 +1,4 @@ +package test + +// just a static type check +fun assertStaticTypeIs(@Suppress("UNUSED_PARAMETER") value: T) {} diff --git a/libraries/stdlib/test/testUtilsJVM.kt b/libraries/stdlib/test/testUtilsJVM.kt new file mode 100644 index 00000000000..0a95a247ac1 --- /dev/null +++ b/libraries/stdlib/test/testUtilsJVM.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2010-2017 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 test + +import kotlin.test.assertEquals + +@JvmVersion +public fun assertTypeEquals(expected: Any?, actual: Any?) { + assertEquals(expected?.javaClass, actual?.javaClass) +} \ No newline at end of file diff --git a/libraries/stdlib/test/text/StringBuilderJVMTest.kt b/libraries/stdlib/test/text/StringBuilderJVMTest.kt index e55faca9fa0..97ff2b553b5 100644 --- a/libraries/stdlib/test/text/StringBuilderJVMTest.kt +++ b/libraries/stdlib/test/text/StringBuilderJVMTest.kt @@ -10,6 +10,7 @@ class StringBuilderJVMTest() { val s = buildString(123) { assertEquals(123, capacity()) } + assertEquals("", s) } @Test fun getAndSetChar() { diff --git a/libraries/stdlib/test/text/StringTest.kt b/libraries/stdlib/test/text/StringTest.kt index 4d09e2b385f..74246583554 100644 --- a/libraries/stdlib/test/text/StringTest.kt +++ b/libraries/stdlib/test/text/StringTest.kt @@ -17,6 +17,7 @@ package test.text import kotlin.test.* +import test.* import org.junit.Test @@ -761,8 +762,8 @@ class StringTest { assertTrue(data === newData) // static types test - val s: String = "x".onEach { } - val sb: StringBuilder = result.onEach { } + assertStaticTypeIs("x".onEach { }) + assertStaticTypeIs(result.onEach { }) } @@ -913,7 +914,7 @@ class StringTest { } assertFailsWith { - arg1("").reduceIndexed { index, a, b -> '\n' } + arg1("").reduceIndexed { _, _, _ -> '\n' } } } @@ -931,7 +932,7 @@ class StringTest { } assertFailsWith { - arg1("").reduceRightIndexed { index, a, b -> '\n' } + arg1("").reduceRightIndexed { _, _, _ -> '\n' } } } @@ -940,7 +941,7 @@ class StringTest { assertEquals('a', arg1("bacfd").reduce { v, c -> if (v > c) c else v }) assertFailsWith { - arg1("").reduce { a, b -> '\n' } + arg1("").reduce { _, _ -> '\n' } } } @@ -949,7 +950,7 @@ class StringTest { assertEquals('a', arg1("bacfd").reduceRight { c, v -> if (v > c) c else v }) assertFailsWith { - arg1("").reduceRight { a, b -> '\n' } + arg1("").reduceRight { _, _ -> '\n' } } } @@ -1067,7 +1068,7 @@ class StringTest { } @Test fun testReplaceAllClosureEmpty() = withOneCharSequenceArg("") { s -> - val result = s.replace("\\d+".toRegex()) { mr -> + val result = s.replace("\\d+".toRegex()) { _ -> "x" } assertEquals("", result) diff --git a/libraries/stdlib/test/utils/LazyJVMTest.kt b/libraries/stdlib/test/utils/LazyJVMTest.kt index cd852f421a0..c758669b233 100644 --- a/libraries/stdlib/test/utils/LazyJVMTest.kt +++ b/libraries/stdlib/test/utils/LazyJVMTest.kt @@ -47,6 +47,7 @@ class LazyJVMTest { accessThreads.forEach { it.join() } assertEquals(2, counter.get()) + @Suppress("NAME_SHADOWING") for ((counter, initialized) in runs) { assertEquals(initialized, counter == 2, "Expected uninitialized on first, initialized on second call: initialized=$initialized, counter=$counter") } @@ -71,7 +72,8 @@ class LazyJVMTest { assertEquals(2, counter.get()) assertEquals(2, lazy.value) - for ((counter, initialized) in runs) { + @Suppress("NAME_SHADOWING") + for ((_, initialized) in runs) { assertFalse(initialized, "Expected uninitialized on first and second run") } } diff --git a/libraries/stdlib/test/utils/TODOTest.kt b/libraries/stdlib/test/utils/TODOTest.kt index cc34ac25d85..d6d14ea246a 100644 --- a/libraries/stdlib/test/utils/TODOTest.kt +++ b/libraries/stdlib/test/utils/TODOTest.kt @@ -23,6 +23,7 @@ import org.junit.Test class TODOTest { private class PartiallyImplementedClass { public val prop: String get() = TODO() + @Suppress("UNREACHABLE_CODE", "CAST_NEVER_SUCCEEDS") fun method1() = TODO() as String public fun method2(): Int = TODO()