From 412d0485e4e6491a1ff02e6556199902056ebebb Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Mon, 25 Sep 2017 13:29:28 +0300 Subject: [PATCH] box-tests: Remove duplicating assertions from testUtils.kt The testUtils.kt contains some assertions which are now implemented in stdlib. This patch removes them from testUtils.kt --- backend.native/tests/testUtils.kt | 80 +------------------ .../org/jetbrains/kotlin/KonanTest.groovy | 2 +- 2 files changed, 2 insertions(+), 80 deletions(-) diff --git a/backend.native/tests/testUtils.kt b/backend.native/tests/testUtils.kt index 60342ae43d7..83269481ad3 100644 --- a/backend.native/tests/testUtils.kt +++ b/backend.native/tests/testUtils.kt @@ -1,56 +1,6 @@ package kotlin.test -annotation class Test() - -class TestFailedException(val msg:String):RuntimeException(msg) - -class Assert { - companion object { - fun assertEquals(a:T, b:T, msg:String? = null) { if (a != b) throw TestFailedException(msg ?: "") } - } -} - -fun assertEquals(a:T, b:T, msg:String? = null) = Assert.assertEquals(a, b, msg) - -/** Asserts that the expression is `true` with an optional [message]. */ -fun assertTrue(actual: Boolean, message: String? = null) { - if (actual != true) { - throw TestFailedException(message ?: "Expected value to be true.") - } -} - -/** Asserts that the expression is `false` with an optional [message]. */ -fun assertFalse(actual: Boolean, message: String? = null) { - assertTrue(!actual, message ?: "Expected value to be false.") -} - -/** Fails the current test with the specified [message]. */ -fun fail(message: String? = null): Nothing = throw TestFailedException(message ?: "Expected value to be true.") - - -/** Asserts that given function [block] returns the given [expected] value. */ -fun expect(expected: T, block: () -> T) { - assertEquals(expected, block()) -} - -/** Asserts that given function [block] returns the given [expected] value and use the given [message] if it fails. */ -fun expect(expected: T, message: String?, block: () -> T) { - assertEquals(expected, block(), message) -} - -/** Asserts that given function [block] fails by throwing an exception. */ -fun assertFails(block: () -> Unit): Throwable = assertFails(null, block) - -/** Asserts that given function [block] fails by throwing an exception. */ -fun assertFails(message: String?, block: () -> Unit): Throwable { - try { - block() - } catch (e: Throwable) { - return e - } - fail(message + ". Expected an exception to be thrown, but was completed successfully.") -} - +// TODO: Remove it when such method from library is available. /** Asserts that a [block] fails with a specific exception of type [exceptionClass] being thrown. */ inline fun assertFailsWith(message: String? = null, block: () -> Unit): T { try { @@ -75,14 +25,6 @@ public fun assertTypeEquals(expected: Any?, actual: Any?) { //assertEquals(expected?.javaClass, actual?.javaClass) } -/** Asserts that the given [block] returns `true`. */ -fun assertTrue(message: String? = null, block: () -> Boolean): Unit = assertTrue(block(), message) - -/** Asserts that the [actual] value is not equal to the illegal value, with an optional [message]. */ -fun assertNotEquals(illegal: T, actual: T, message: String? = null) { - assertFalse(illegal == actual, message) -} - fun Iterable.assertSorted(isInOrder: (T, T) -> Boolean): Unit { this.iterator().assertSorted(isInOrder) } fun Iterator.assertSorted(isInOrder: (T, T) -> Boolean) { if (!hasNext()) return @@ -96,23 +38,3 @@ fun Iterator.assertSorted(isInOrder: (T, T) -> Boolean) { } return } - -/** Asserts that the [actual] value is not `null`, with an optional [message]. */ -fun assertNotNull(actual: T?, message: String? = null): T { - assertTrue(actual != null, message) - return actual!! -} - -/** Asserts that the [actual] value is not `null`, with an optional [message] and a function [block] to process the not-null value. */ -fun assertNotNull(actual: T?, message: String? = null, block: (T) -> R) { - assertTrue(actual != null, message) - if (actual != null) { - block(actual) - } -} - -/** Asserts that the [actual] value is `null`, with an optional [message]. */ -fun assertNull(actual: Any?, message: String? = null) { - assertTrue(actual == null, message) -} - diff --git a/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy b/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy index 2201e7603d9..44e318e433b 100644 --- a/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy +++ b/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy @@ -470,7 +470,7 @@ class RunExternalTestGroup extends RunKonanTest { * There are tests that require non-trivial 'package foo' in test launcher. */ void createLauncherFile(String file, List imports) { - StringBuilder text = new StringBuilder("import kotlin.test.TestFailedException\n") + StringBuilder text = new StringBuilder() for (v in imports) { text.append("import ").append(v).append('\n') }