[kotlin-test] Explicit public visibility and return types

This commit is contained in:
Ilya Gorbunov
2023-11-13 00:37:48 +01:00
committed by Space Team
parent 3a5276f4d3
commit 66639d37ec
11 changed files with 110 additions and 110 deletions
@@ -23,7 +23,7 @@ import kotlin.reflect.typeOf
/**
* Current adapter providing assertion implementations
*/
val asserter: Asserter
public val asserter: Asserter
get() = _asserter ?: lookupAsserter()
/** Used to override current asserter internally */
@@ -33,13 +33,13 @@ internal var _asserter: Asserter? = null
/** Asserts that the given [block] returns `true`. */
@JvmName("assertTrueInline")
@InlineOnly
inline fun assertTrue(message: String? = null, block: () -> Boolean) {
public inline fun assertTrue(message: String? = null, block: () -> Boolean) {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
assertTrue(block(), message)
}
/** Asserts that the expression is `true` with an optional [message]. */
fun assertTrue(actual: Boolean, message: String? = null) {
public fun assertTrue(actual: Boolean, message: String? = null) {
contract { returns() implies actual }
return asserter.assertTrue(message ?: "Expected value to be true.", actual)
}
@@ -47,58 +47,58 @@ fun assertTrue(actual: Boolean, message: String? = null) {
/** Asserts that the given [block] returns `false`. */
@JvmName("assertFalseInline")
@InlineOnly
inline fun assertFalse(message: String? = null, block: () -> Boolean) {
public inline fun assertFalse(message: String? = null, block: () -> Boolean) {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
assertFalse(block(), message)
}
/** Asserts that the expression is `false` with an optional [message]. */
fun assertFalse(actual: Boolean, message: String? = null) {
public fun assertFalse(actual: Boolean, message: String? = null) {
contract { returns() implies (!actual) }
return asserter.assertTrue(message ?: "Expected value to be false.", !actual)
}
/** Asserts that the [expected] value is equal to the [actual] value, with an optional [message]. */
fun <@OnlyInputTypes T> assertEquals(expected: T, actual: T, message: String? = null) {
public fun <@OnlyInputTypes T> assertEquals(expected: T, actual: T, message: String? = null) {
asserter.assertEquals(message, expected, actual)
}
/** Asserts that the difference between the [actual] and the [expected] is within an [absoluteTolerance], with an optional [message]. */
@SinceKotlin("1.5")
fun assertEquals(expected: Double, actual: Double, absoluteTolerance: Double, message: String? = null) {
public fun assertEquals(expected: Double, actual: Double, absoluteTolerance: Double, message: String? = null) {
checkDoublesAreEqual(expected, actual, absoluteTolerance, message)
}
/** Asserts that the difference between the [actual] and the [expected] is within an [absoluteTolerance], with an optional [message]. */
@SinceKotlin("1.5")
fun assertEquals(expected: Float, actual: Float, absoluteTolerance: Float, message: String? = null) {
public fun assertEquals(expected: Float, actual: Float, absoluteTolerance: Float, message: String? = null) {
checkFloatsAreEqual(expected, actual, absoluteTolerance, message)
}
/** Asserts that the [actual] value is not equal to the illegal value, with an optional [message]. */
fun <@OnlyInputTypes T> assertNotEquals(illegal: T, actual: T, message: String? = null) {
public fun <@OnlyInputTypes T> assertNotEquals(illegal: T, actual: T, message: String? = null) {
asserter.assertNotEquals(message, illegal, actual)
}
/** Asserts that the difference between the [actual] and the [illegal] is not within an [absoluteTolerance], with an optional [message]. */
@SinceKotlin("1.5")
fun assertNotEquals(illegal: Double, actual: Double, absoluteTolerance: Double, message: String? = null) {
public fun assertNotEquals(illegal: Double, actual: Double, absoluteTolerance: Double, message: String? = null) {
checkDoublesAreEqual(illegal, actual, absoluteTolerance, message, shouldFail = true)
}
/** Asserts that the difference between the [actual] and the [illegal] is not within an [absoluteTolerance], with an optional [message]. */
@SinceKotlin("1.5")
fun assertNotEquals(illegal: Float, actual: Float, absoluteTolerance: Float, message: String? = null) {
public fun assertNotEquals(illegal: Float, actual: Float, absoluteTolerance: Float, message: String? = null) {
checkFloatsAreEqual(illegal, actual, absoluteTolerance, message, shouldFail = true)
}
/** Asserts that [expected] is the same instance as [actual], with an optional [message]. */
fun <@OnlyInputTypes T> assertSame(expected: T, actual: T, message: String? = null) {
public fun <@OnlyInputTypes T> assertSame(expected: T, actual: T, message: String? = null) {
asserter.assertSame(message, expected, actual)
}
/** Asserts that [actual] is not the same instance as [illegal], with an optional [message]. */
fun <@OnlyInputTypes T> assertNotSame(illegal: T, actual: T, message: String? = null) {
public fun <@OnlyInputTypes T> assertNotSame(illegal: T, actual: T, message: String? = null) {
asserter.assertNotSame(message, illegal, actual)
}
@@ -111,7 +111,7 @@ fun <@OnlyInputTypes T> assertNotSame(illegal: T, actual: T, message: String? =
@SinceKotlin("1.5")
@InlineOnly
@OptIn(ExperimentalStdlibApi::class)
inline fun <reified T> assertIs(value: Any?, message: String? = null): T {
public inline fun <reified T> assertIs(value: Any?, message: String? = null): T {
contract { returns() implies (value is T) }
assertIsOfType(value, typeOf<T>(), value is T, message)
return value as T
@@ -130,7 +130,7 @@ internal fun assertIsOfType(value: Any?, type: KType, result: Boolean, message:
*/
@SinceKotlin("1.5")
@InlineOnly
inline fun <reified T> assertIsNot(value: Any?, message: String? = null) {
public inline fun <reified T> assertIsNot(value: Any?, message: String? = null) {
assertIsNotOfType(value, typeOf<T>(), value !is T, message)
}
@@ -140,7 +140,7 @@ internal fun assertIsNotOfType(@Suppress("UNUSED_PARAMETER") value: Any?, type:
}
/** Asserts that the [actual] value is not `null`, with an optional [message]. */
fun <T : Any> assertNotNull(actual: T?, message: String? = null): T {
public fun <T : Any> assertNotNull(actual: T?, message: String? = null): T {
contract { returns() implies (actual != null) }
asserter.assertNotNull(message, actual)
return actual!!
@@ -149,19 +149,19 @@ fun <T : Any> assertNotNull(actual: T?, message: String? = null): T {
/** Asserts that the [actual] value is not `null`, with an optional [message] and a function [block] to process the not-null value. */
@JvmName("assertNotNullInline")
@InlineOnly
inline fun <T : Any, R> assertNotNull(actual: T?, message: String? = null, block: (T) -> R) {
public inline fun <T : Any, R> assertNotNull(actual: T?, message: String? = null, block: (T) -> R) {
contract { returns() implies (actual != null) }
block(assertNotNull(actual, message))
}
/** Asserts that the [actual] value is `null`, with an optional [message]. */
fun assertNull(actual: Any?, message: String? = null) {
public fun assertNull(actual: Any?, message: String? = null) {
asserter.assertNull(message, actual)
}
/** Asserts that the [iterable] contains the specified [element], with an optional [message]. */
@SinceKotlin("1.5")
fun <@OnlyInputTypes T> assertContains(iterable: Iterable<T>, element: T, message: String? = null) {
public fun <@OnlyInputTypes T> assertContains(iterable: Iterable<T>, element: T, message: String? = null) {
asserter.assertTrue(
{ messagePrefix(message) + "Expected the collection to contain the element.\nCollection <$iterable>, element <$element>." },
iterable.contains(element)
@@ -170,7 +170,7 @@ fun <@OnlyInputTypes T> assertContains(iterable: Iterable<T>, element: T, messag
/** Asserts that the [sequence] contains the specified [element], with an optional [message]. */
@SinceKotlin("1.5")
fun <@OnlyInputTypes T> assertContains(sequence: Sequence<T>, element: T, message: String? = null) {
public fun <@OnlyInputTypes T> assertContains(sequence: Sequence<T>, element: T, message: String? = null) {
asserter.assertTrue(
{ messagePrefix(message) + "Expected the sequence to contain the element.\nSequence <$sequence>, element <$element>." },
sequence.contains(element)
@@ -179,71 +179,71 @@ fun <@OnlyInputTypes T> assertContains(sequence: Sequence<T>, element: T, messag
/** Asserts that the [array] contains the specified [element], with an optional [message]. */
@SinceKotlin("1.5")
fun <@OnlyInputTypes T> assertContains(array: Array<T>, element: T, message: String? = null) {
public fun <@OnlyInputTypes T> assertContains(array: Array<T>, element: T, message: String? = null) {
assertArrayContains(array, element, message, Array<T>::contains, Array<T>::contentToString)
}
/** Asserts that the [array] contains the specified [element], with an optional [message]. */
@SinceKotlin("1.5")
fun assertContains(array: ByteArray, element: Byte, message: String? = null) {
public fun assertContains(array: ByteArray, element: Byte, message: String? = null) {
assertArrayContains(array, element, message, ByteArray::contains, ByteArray::contentToString)
}
/** Asserts that the [array] contains the specified [element], with an optional [message]. */
@SinceKotlin("1.5")
fun assertContains(array: ShortArray, element: Short, message: String? = null) {
public fun assertContains(array: ShortArray, element: Short, message: String? = null) {
assertArrayContains(array, element, message, ShortArray::contains, ShortArray::contentToString)
}
/** Asserts that the [array] contains the specified [element], with an optional [message]. */
@SinceKotlin("1.5")
fun assertContains(array: IntArray, element: Int, message: String? = null) {
public fun assertContains(array: IntArray, element: Int, message: String? = null) {
assertArrayContains(array, element, message, IntArray::contains, IntArray::contentToString)
}
/** Asserts that the [array] contains the specified [element], with an optional [message]. */
@SinceKotlin("1.5")
fun assertContains(array: LongArray, element: Long, message: String? = null) {
public fun assertContains(array: LongArray, element: Long, message: String? = null) {
assertArrayContains(array, element, message, LongArray::contains, LongArray::contentToString)
}
/** Asserts that the [array] contains the specified [element], with an optional [message]. */
@SinceKotlin("1.5")
fun assertContains(array: BooleanArray, element: Boolean, message: String? = null) {
public fun assertContains(array: BooleanArray, element: Boolean, message: String? = null) {
assertArrayContains(array, element, message, BooleanArray::contains, BooleanArray::contentToString)
}
/** Asserts that the [array] contains the specified [element], with an optional [message]. */
@SinceKotlin("1.5")
fun assertContains(array: CharArray, element: Char, message: String? = null) {
public fun assertContains(array: CharArray, element: Char, message: String? = null) {
assertArrayContains(array, element, message, CharArray::contains, CharArray::contentToString)
}
/** Asserts that the [array] contains the specified [element], with an optional [message]. */
@SinceKotlin("1.5")
@OptIn(ExperimentalUnsignedTypes::class)
fun assertContains(array: UByteArray, element: UByte, message: String? = null) {
public fun assertContains(array: UByteArray, element: UByte, message: String? = null) {
assertArrayContains(array, element, message, UByteArray::contains, UByteArray::contentToString)
}
/** Asserts that the [array] contains the specified [element], with an optional [message]. */
@SinceKotlin("1.5")
@OptIn(ExperimentalUnsignedTypes::class)
fun assertContains(array: UShortArray, element: UShort, message: String? = null) {
public fun assertContains(array: UShortArray, element: UShort, message: String? = null) {
assertArrayContains(array, element, message, UShortArray::contains, UShortArray::contentToString)
}
/** Asserts that the [array] contains the specified [element], with an optional [message]. */
@SinceKotlin("1.5")
@OptIn(ExperimentalUnsignedTypes::class)
fun assertContains(array: UIntArray, element: UInt, message: String? = null) {
public fun assertContains(array: UIntArray, element: UInt, message: String? = null) {
assertArrayContains(array, element, message, UIntArray::contains, UIntArray::contentToString)
}
/** Asserts that the [array] contains the specified [element], with an optional [message]. */
@SinceKotlin("1.5")
@OptIn(ExperimentalUnsignedTypes::class)
fun assertContains(array: ULongArray, element: ULong, message: String? = null) {
public fun assertContains(array: ULongArray, element: ULong, message: String? = null) {
assertArrayContains(array, element, message, ULongArray::contains, ULongArray::contentToString)
}
@@ -263,44 +263,44 @@ private inline fun <@OnlyInputTypes A, E> assertArrayContains(
/** Asserts that the [range] contains the specified [value], with an optional [message]. */
@SinceKotlin("1.5")
fun assertContains(range: IntRange, value: Int, message: String? = null) {
public fun assertContains(range: IntRange, value: Int, message: String? = null) {
assertRangeContains(range, value, message, IntRange::contains)
}
/** Asserts that the [range] contains the specified [value], with an optional [message]. */
@SinceKotlin("1.5")
fun assertContains(range: LongRange, value: Long, message: String? = null) {
public fun assertContains(range: LongRange, value: Long, message: String? = null) {
assertRangeContains(range, value, message, LongRange::contains)
}
/** Asserts that the [range] contains the specified [value], with an optional [message]. */
@SinceKotlin("1.5")
fun <T : Comparable<T>> assertContains(range: ClosedRange<T>, value: T, message: String? = null) {
public fun <T : Comparable<T>> assertContains(range: ClosedRange<T>, value: T, message: String? = null) {
assertRangeContains(range, value, message, ClosedRange<T>::contains)
}
/** Asserts that the [range] contains the specified [value], with an optional [message]. */
@SinceKotlin("1.7")
@ExperimentalStdlibApi
fun <T : Comparable<T>> assertContains(range: OpenEndRange<T>, value: T, message: String? = null) {
public fun <T : Comparable<T>> assertContains(range: OpenEndRange<T>, value: T, message: String? = null) {
assertRangeContains(range, value, message, OpenEndRange<T>::contains)
}
/** Asserts that the [range] contains the specified [value], with an optional [message]. */
@SinceKotlin("1.5")
fun assertContains(range: CharRange, value: Char, message: String? = null) {
public fun assertContains(range: CharRange, value: Char, message: String? = null) {
assertRangeContains(range, value, message, CharRange::contains)
}
/** Asserts that the [range] contains the specified [value], with an optional [message]. */
@SinceKotlin("1.5")
fun assertContains(range: UIntRange, value: UInt, message: String? = null) {
public fun assertContains(range: UIntRange, value: UInt, message: String? = null) {
assertRangeContains(range, value, message, UIntRange::contains)
}
/** Asserts that the [range] contains the specified [value], with an optional [message]. */
@SinceKotlin("1.5")
fun assertContains(range: ULongRange, value: ULong, message: String? = null) {
public fun assertContains(range: ULongRange, value: ULong, message: String? = null) {
assertRangeContains(range, value, message, ULongRange::contains)
}
@@ -314,7 +314,7 @@ private inline fun <R, V> assertRangeContains(range: R, value: V, message: Strin
/** Asserts that the [map] contains the specified [key], with an optional [message]. */
@SinceKotlin("1.5")
fun <@OnlyInputTypes K, V> assertContains(map: Map<K, V>, key: K, message: String? = null) {
public fun <@OnlyInputTypes K, V> assertContains(map: Map<K, V>, key: K, message: String? = null) {
asserter.assertTrue({ messagePrefix(message) + "Expected the map to contain the key.\nMap <$map>, key <$key>." }, map.containsKey(key))
}
@@ -324,7 +324,7 @@ fun <@OnlyInputTypes K, V> assertContains(map: Map<K, V>, key: K, message: Strin
* @param ignoreCase `true` to ignore character case when comparing characters. By default `false`.
*/
@SinceKotlin("1.5")
fun assertContains(charSequence: CharSequence, char: Char, ignoreCase: Boolean = false, message: String? = null) {
public fun assertContains(charSequence: CharSequence, char: Char, ignoreCase: Boolean = false, message: String? = null) {
asserter.assertTrue(
{ messagePrefix(message) + "Expected the char sequence to contain the char.\nCharSequence <$charSequence>, char <$char>, ignoreCase <$ignoreCase>." },
charSequence.contains(char, ignoreCase)
@@ -337,7 +337,7 @@ fun assertContains(charSequence: CharSequence, char: Char, ignoreCase: Boolean =
* @param ignoreCase `true` to ignore character case when comparing strings. By default `false`.
*/
@SinceKotlin("1.5")
fun assertContains(charSequence: CharSequence, other: CharSequence, ignoreCase: Boolean = false, message: String? = null) {
public fun assertContains(charSequence: CharSequence, other: CharSequence, ignoreCase: Boolean = false, message: String? = null) {
asserter.assertTrue(
{ messagePrefix(message) + "Expected the char sequence to contain the substring.\nCharSequence <$charSequence>, substring <$other>, ignoreCase <$ignoreCase>." },
charSequence.contains(other, ignoreCase)
@@ -346,7 +346,7 @@ fun assertContains(charSequence: CharSequence, other: CharSequence, ignoreCase:
/** Asserts that the [charSequence] contains at least one match of the specified regular expression [regex], with an optional [message]. */
@SinceKotlin("1.5")
fun assertContains(charSequence: CharSequence, regex: Regex, message: String? = null) {
public fun assertContains(charSequence: CharSequence, regex: Regex, message: String? = null) {
asserter.assertTrue(
{ messagePrefix(message) + "Expected the char sequence to contain the regular expression.\nCharSequence <$charSequence>, regex <$regex>." },
charSequence.contains(regex)
@@ -361,7 +361,7 @@ fun assertContains(charSequence: CharSequence, regex: Regex, message: String? =
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.5")
fun <@OnlyInputTypes T> assertContentEquals(expected: Iterable<T>?, actual: Iterable<T>?, message: String? = null) {
public fun <@OnlyInputTypes T> assertContentEquals(expected: Iterable<T>?, actual: Iterable<T>?, message: String? = null) {
assertIterableContentEquals("Iterable", message, expected, actual, Iterable<*>::iterator)
}
@@ -370,7 +370,7 @@ fun <@OnlyInputTypes T> assertContentEquals(expected: Iterable<T>?, actual: Iter
@Deprecated("'assertContentEquals' for Set arguments is ambiguous. Use 'assertEquals' to compare content with the unordered set equality, or cast one of arguments to Iterable to compare the set elements in order of iteration.",
level = DeprecationLevel.ERROR,
replaceWith = ReplaceWith("assertContentEquals(expected, actual?.asIterable(), message)"))
fun <@OnlyInputTypes T> assertContentEquals(expected: Set<T>?, actual: Set<T>?, message: String? = null): Unit =
public fun <@OnlyInputTypes T> assertContentEquals(expected: Set<T>?, actual: Set<T>?, message: String? = null): Unit =
assertContentEquals(expected, actual?.asIterable(), message)
/**
@@ -381,7 +381,7 @@ fun <@OnlyInputTypes T> assertContentEquals(expected: Set<T>?, actual: Set<T>?,
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.5")
fun <@OnlyInputTypes T> assertContentEquals(expected: Sequence<T>?, actual: Sequence<T>?, message: String? = null) {
public fun <@OnlyInputTypes T> assertContentEquals(expected: Sequence<T>?, actual: Sequence<T>?, message: String? = null) {
assertIterableContentEquals("Sequence", message, expected, actual, Sequence<*>::iterator)
}
@@ -393,7 +393,7 @@ fun <@OnlyInputTypes T> assertContentEquals(expected: Sequence<T>?, actual: Sequ
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.5")
fun <@OnlyInputTypes T> assertContentEquals(expected: Array<T>?, actual: Array<T>?, message: String? = null) {
public fun <@OnlyInputTypes T> assertContentEquals(expected: Array<T>?, actual: Array<T>?, message: String? = null) {
assertArrayContentEquals(message, expected, actual, { it.size }, Array<*>::get, Array<*>?::contentToString, Array<*>?::contentEquals)
}
@@ -402,7 +402,7 @@ fun <@OnlyInputTypes T> assertContentEquals(expected: Array<T>?, actual: Array<T
* i.e. contains the same number of the same elements in the same order, with an optional [message].
*/
@SinceKotlin("1.5")
fun assertContentEquals(expected: ByteArray?, actual: ByteArray?, message: String? = null) {
public fun assertContentEquals(expected: ByteArray?, actual: ByteArray?, message: String? = null) {
assertArrayContentEquals(message, expected, actual, { it.size }, ByteArray::get, ByteArray?::contentToString, ByteArray?::contentEquals)
}
@@ -411,7 +411,7 @@ fun assertContentEquals(expected: ByteArray?, actual: ByteArray?, message: Strin
* i.e. contains the same number of the same elements in the same order, with an optional [message].
*/
@SinceKotlin("1.5")
fun assertContentEquals(expected: ShortArray?, actual: ShortArray?, message: String? = null) {
public fun assertContentEquals(expected: ShortArray?, actual: ShortArray?, message: String? = null) {
assertArrayContentEquals(message, expected, actual, { it.size }, ShortArray::get, ShortArray?::contentToString, ShortArray?::contentEquals)
}
@@ -420,7 +420,7 @@ fun assertContentEquals(expected: ShortArray?, actual: ShortArray?, message: Str
* i.e. contains the same number of the same elements in the same order, with an optional [message].
*/
@SinceKotlin("1.5")
fun assertContentEquals(expected: IntArray?, actual: IntArray?, message: String? = null) {
public fun assertContentEquals(expected: IntArray?, actual: IntArray?, message: String? = null) {
assertArrayContentEquals(message, expected, actual, { it.size }, IntArray::get, IntArray?::contentToString, IntArray?::contentEquals)
}
@@ -429,7 +429,7 @@ fun assertContentEquals(expected: IntArray?, actual: IntArray?, message: String?
* i.e. contains the same number of the same elements in the same order, with an optional [message].
*/
@SinceKotlin("1.5")
fun assertContentEquals(expected: LongArray?, actual: LongArray?, message: String? = null) {
public fun assertContentEquals(expected: LongArray?, actual: LongArray?, message: String? = null) {
assertArrayContentEquals(message, expected, actual, { it.size }, LongArray::get, LongArray?::contentToString, LongArray?::contentEquals)
}
@@ -441,7 +441,7 @@ fun assertContentEquals(expected: LongArray?, actual: LongArray?, message: Strin
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.5")
fun assertContentEquals(expected: FloatArray?, actual: FloatArray?, message: String? = null) {
public fun assertContentEquals(expected: FloatArray?, actual: FloatArray?, message: String? = null) {
assertArrayContentEquals(message, expected, actual, { it.size }, FloatArray::get, FloatArray?::contentToString, FloatArray?::contentEquals)
}
@@ -453,7 +453,7 @@ fun assertContentEquals(expected: FloatArray?, actual: FloatArray?, message: Str
* For floating point numbers it means that `NaN` is equal to itself and `-0.0` is not equal to `0.0`.
*/
@SinceKotlin("1.5")
fun assertContentEquals(expected: DoubleArray?, actual: DoubleArray?, message: String? = null) {
public fun assertContentEquals(expected: DoubleArray?, actual: DoubleArray?, message: String? = null) {
assertArrayContentEquals(message, expected, actual, { it.size }, DoubleArray::get, DoubleArray?::contentToString, DoubleArray?::contentEquals)
}
@@ -462,7 +462,7 @@ fun assertContentEquals(expected: DoubleArray?, actual: DoubleArray?, message: S
* i.e. contains the same number of the same elements in the same order, with an optional [message].
*/
@SinceKotlin("1.5")
fun assertContentEquals(expected: BooleanArray?, actual: BooleanArray?, message: String? = null) {
public fun assertContentEquals(expected: BooleanArray?, actual: BooleanArray?, message: String? = null) {
assertArrayContentEquals(message, expected, actual, { it.size }, BooleanArray::get, BooleanArray?::contentToString, BooleanArray?::contentEquals)
}
@@ -471,7 +471,7 @@ fun assertContentEquals(expected: BooleanArray?, actual: BooleanArray?, message:
* i.e. contains the same number of the same elements in the same order, with an optional [message].
*/
@SinceKotlin("1.5")
fun assertContentEquals(expected: CharArray?, actual: CharArray?, message: String? = null) {
public fun assertContentEquals(expected: CharArray?, actual: CharArray?, message: String? = null) {
assertArrayContentEquals(message, expected, actual, { it.size }, CharArray::get, CharArray?::contentToString, CharArray?::contentEquals)
}
@@ -481,7 +481,7 @@ fun assertContentEquals(expected: CharArray?, actual: CharArray?, message: Strin
*/
@SinceKotlin("1.5")
@OptIn(ExperimentalUnsignedTypes::class)
fun assertContentEquals(expected: UByteArray?, actual: UByteArray?, message: String? = null) {
public fun assertContentEquals(expected: UByteArray?, actual: UByteArray?, message: String? = null) {
assertArrayContentEquals(message, expected, actual, { it.size }, UByteArray::get, UByteArray?::contentToString, UByteArray?::contentEquals)
}
@@ -491,7 +491,7 @@ fun assertContentEquals(expected: UByteArray?, actual: UByteArray?, message: Str
*/
@SinceKotlin("1.5")
@OptIn(ExperimentalUnsignedTypes::class)
fun assertContentEquals(expected: UShortArray?, actual: UShortArray?, message: String? = null) {
public fun assertContentEquals(expected: UShortArray?, actual: UShortArray?, message: String? = null) {
assertArrayContentEquals(message, expected, actual, { it.size }, UShortArray::get, UShortArray?::contentToString, UShortArray?::contentEquals)
}
@@ -501,7 +501,7 @@ fun assertContentEquals(expected: UShortArray?, actual: UShortArray?, message: S
*/
@SinceKotlin("1.5")
@OptIn(ExperimentalUnsignedTypes::class)
fun assertContentEquals(expected: UIntArray?, actual: UIntArray?, message: String? = null) {
public fun assertContentEquals(expected: UIntArray?, actual: UIntArray?, message: String? = null) {
assertArrayContentEquals(message, expected, actual, { it.size }, UIntArray::get, UIntArray?::contentToString, UIntArray?::contentEquals)
}
@@ -511,12 +511,12 @@ fun assertContentEquals(expected: UIntArray?, actual: UIntArray?, message: Strin
*/
@SinceKotlin("1.5")
@OptIn(ExperimentalUnsignedTypes::class)
fun assertContentEquals(expected: ULongArray?, actual: ULongArray?, message: String? = null) {
public fun assertContentEquals(expected: ULongArray?, actual: ULongArray?, message: String? = null) {
assertArrayContentEquals(message, expected, actual, { it.size }, ULongArray::get, ULongArray?::contentToString, ULongArray?::contentEquals)
}
/** Marks a test as having failed if this point in the execution path is reached, with an optional [message]. */
fun fail(message: String? = null): Nothing {
public fun fail(message: String? = null): Nothing {
asserter.fail(message)
}
@@ -527,14 +527,14 @@ fun fail(message: String? = null): Nothing {
* The [cause] exception is set as the root cause of the test failure.
*/
@SinceKotlin("1.4")
fun fail(message: String? = null, cause: Throwable? = null): Nothing {
public fun fail(message: String? = null, cause: Throwable? = null): Nothing {
asserter.fail(message, cause)
}
/** Asserts that given function [block] returns the given [expected] value. */
@JvmName("expectInline")
@InlineOnly
inline fun <@OnlyInputTypes T> expect(expected: T, block: () -> T) {
public inline fun <@OnlyInputTypes T> expect(expected: T, block: () -> T) {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
assertEquals(expected, block())
}
@@ -542,7 +542,7 @@ inline fun <@OnlyInputTypes T> expect(expected: T, block: () -> T) {
/** Asserts that given function [block] returns the given [expected] value and use the given [message] if it fails. */
@JvmName("expectInline")
@InlineOnly
inline fun <@OnlyInputTypes T> expect(expected: T, message: String?, block: () -> T) {
public inline fun <@OnlyInputTypes T> expect(expected: T, message: String?, block: () -> T) {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
assertEquals(expected, block(), message)
}
@@ -555,7 +555,7 @@ inline fun <@OnlyInputTypes T> expect(expected: T, message: String?, block: () -
*/
@InlineOnly
@JvmName("assertFailsInline")
inline fun assertFails(block: () -> Unit): Throwable =
public inline fun assertFails(block: () -> Unit): Throwable =
checkResultIsFailure(null, runCatching(block))
/**
@@ -569,7 +569,7 @@ inline fun assertFails(block: () -> Unit): Throwable =
@SinceKotlin("1.1")
@InlineOnly
@JvmName("assertFailsInline")
inline fun assertFails(message: String?, block: () -> Unit): Throwable =
public inline fun assertFails(message: String?, block: () -> Unit): Throwable =
checkResultIsFailure(message, runCatching(block))
@PublishedApi
@@ -592,7 +592,7 @@ internal fun checkResultIsFailure(message: String?, blockResult: Result<Unit>):
* The returned exception can be inspected further, for example by asserting its property values.
*/
@InlineOnly
inline fun <reified T : Throwable> assertFailsWith(message: String? = null, block: () -> Unit): T =
public inline fun <reified T : Throwable> assertFailsWith(message: String? = null, block: () -> Unit): T =
assertFailsWith(T::class, message, block)
/**
@@ -603,7 +603,7 @@ inline fun <reified T : Throwable> assertFailsWith(message: String? = null, bloc
*/
@InlineOnly
@JvmName("assertFailsWithInline")
inline fun <T : Throwable> assertFailsWith(exceptionClass: KClass<T>, block: () -> Unit): T = assertFailsWith(exceptionClass, null, block)
public inline fun <T : Throwable> assertFailsWith(exceptionClass: KClass<T>, block: () -> Unit): T = assertFailsWith(exceptionClass, null, block)
/**
* Asserts that a [block] fails with a specific exception of type [exceptionClass] being thrown.
@@ -615,7 +615,7 @@ inline fun <T : Throwable> assertFailsWith(exceptionClass: KClass<T>, block: ()
*/
@InlineOnly
@JvmName("assertFailsWithInline")
inline fun <T : Throwable> assertFailsWith(exceptionClass: KClass<T>, message: String?, block: () -> Unit): T =
public inline fun <T : Throwable> assertFailsWith(exceptionClass: KClass<T>, message: String?, block: () -> Unit): T =
checkResultIsFailure(exceptionClass, message, runCatching(block))
/** Platform-specific construction of AssertionError with cause */
@@ -625,13 +625,13 @@ internal expect fun AssertionErrorWithCause(message: String?, cause: Throwable?)
* Abstracts the logic for performing assertions. Specific implementations of [Asserter] can use JUnit
* or TestNG assertion facilities.
*/
interface Asserter {
public interface Asserter {
/**
* Fails the current test with the specified message.
*
* @param message the message to report.
*/
fun fail(message: String?): Nothing
public fun fail(message: String?): Nothing
/**
* Fails the current test with the specified message and cause exception.
@@ -640,14 +640,14 @@ interface Asserter {
* @param cause the exception to set as the root cause of the reported failure.
*/
@SinceKotlin("1.4")
fun fail(message: String?, cause: Throwable?): Nothing
public fun fail(message: String?, cause: Throwable?): Nothing
/**
* Asserts that the specified value is `true`.
*
* @param lazyMessage the function to return a message to report if the assertion fails.
*/
fun assertTrue(lazyMessage: () -> String?, actual: Boolean): Unit {
public fun assertTrue(lazyMessage: () -> String?, actual: Boolean): Unit {
if (!actual) {
fail(lazyMessage())
}
@@ -658,7 +658,7 @@ interface Asserter {
*
* @param message the message to report if the assertion fails.
*/
fun assertTrue(message: String?, actual: Boolean): Unit {
public fun assertTrue(message: String?, actual: Boolean): Unit {
assertTrue({ message }, actual)
}
@@ -667,7 +667,7 @@ interface Asserter {
*
* @param message the message to report if the assertion fails.
*/
fun assertEquals(message: String?, expected: Any?, actual: Any?): Unit {
public fun assertEquals(message: String?, expected: Any?, actual: Any?): Unit {
assertTrue({ messagePrefix(message) + "Expected <$expected>, actual <$actual>." }, actual == expected)
}
@@ -676,7 +676,7 @@ interface Asserter {
*
* @param message the message to report if the assertion fails.
*/
fun assertNotEquals(message: String?, illegal: Any?, actual: Any?): Unit {
public fun assertNotEquals(message: String?, illegal: Any?, actual: Any?): Unit {
assertTrue({ messagePrefix(message) + "Illegal value: <$actual>." }, actual != illegal)
}
@@ -685,7 +685,7 @@ interface Asserter {
*
* @param message the message to report if the assertion fails.
*/
fun assertSame(message: String?, expected: Any?, actual: Any?): Unit {
public fun assertSame(message: String?, expected: Any?, actual: Any?): Unit {
assertTrue({ messagePrefix(message) + "Expected <$expected>, actual <$actual> is not same." }, actual === expected)
}
@@ -694,7 +694,7 @@ interface Asserter {
*
* @param message the message to report if the assertion fails.
*/
fun assertNotSame(message: String?, illegal: Any?, actual: Any?): Unit {
public fun assertNotSame(message: String?, illegal: Any?, actual: Any?): Unit {
assertTrue({ messagePrefix(message) + "Expected not same as <$actual>." }, actual !== illegal)
}
@@ -703,7 +703,7 @@ interface Asserter {
*
* @param message the message to report if the assertion fails.
*/
fun assertNull(message: String?, actual: Any?): Unit {
public fun assertNull(message: String?, actual: Any?): Unit {
assertTrue({ messagePrefix(message) + "Expected value to be null, but was: <$actual>." }, actual == null)
}
@@ -712,7 +712,7 @@ interface Asserter {
*
* @param message the message to report if the assertion fails.
*/
fun assertNotNull(message: String?, actual: Any?): Unit {
public fun assertNotNull(message: String?, actual: Any?): Unit {
assertTrue({ messagePrefix(message) + "Expected value to be not null." }, actual != null)
}
@@ -721,12 +721,12 @@ interface Asserter {
/**
* Checks applicability and provides Asserter instance
*/
interface AsserterContributor {
public interface AsserterContributor {
/**
* Provides [Asserter] instance or `null` depends on the current context.
*
* @return asserter instance or null if it is not applicable now
*/
fun contribute(): Asserter?
public fun contribute(): Asserter?
}
@@ -12,7 +12,7 @@ import kotlin.reflect.KClass
*
* This keeps the code under test referenced, but doesn't actually test it until it is implemented.
*/
expect fun todo(block: () -> Unit)
public expect fun todo(block: () -> Unit)
/** Asserts that a [blockResult] is a failure with the specific exception type being thrown. */
@PublishedApi
@@ -8,7 +8,7 @@ package kotlin.test
/**
* Default [Asserter] implementation to avoid dependency on JUnit or TestNG.
*/
object DefaultAsserter : Asserter {
public object DefaultAsserter : Asserter {
override fun fail(message: String?): Nothing {
if (message == null)
throw AssertionError()
@@ -9,10 +9,10 @@ package kotlin.test
* Describes the result of an assertion execution.
*/
public external interface AssertionResult {
val result: Boolean
val expected: Any?
val actual: Any?
val lazyMessage: () -> String?
public val result: Boolean
public val expected: Any?
public val actual: Any?
public val lazyMessage: () -> String?
}
internal var assertHook: (AssertionResult) -> Unit = { _ -> }
@@ -31,7 +31,7 @@ public external interface FrameworkAdapter {
* @param ignored whether the test suite is ignored, e.g. marked with [Ignore] annotation
* @param suiteFn defines nested suites by calling [kotlin.test.suite] and tests by calling [kotlin.test.test]
*/
fun suite(name: String, ignored: Boolean, suiteFn: () -> Unit)
public fun suite(name: String, ignored: Boolean, suiteFn: () -> Unit)
/**
* Declares a test.
@@ -40,5 +40,5 @@ public external interface FrameworkAdapter {
* @param ignored whether the test is ignored
* @param testFn contains test body invocation
*/
fun test(name: String, ignored: Boolean, testFn: () -> Any?)
public fun test(name: String, ignored: Boolean, testFn: () -> Any?)
}
@@ -12,7 +12,7 @@ import kotlin.reflect.KClass
*
* This keeps the code under test referenced, but doesn't actually test it until it is implemented.
*/
actual fun todo(block: () -> Unit) {
public actual fun todo(block: () -> Unit) {
// println("TODO at " + (Exception() as java.lang.Throwable).getStackTrace()?.get(1) + " for " + block)
println("TODO at " + block)
}
@@ -66,10 +66,10 @@ internal fun adapter(): FrameworkAdapter {
}
@JsName("kotlinTest")
external val kotlinTestNamespace: KotlinTestNamespace
public external val kotlinTestNamespace: KotlinTestNamespace
external interface KotlinTestNamespace {
val adapterTransformer: ((FrameworkAdapter) -> FrameworkAdapter)?
public external interface KotlinTestNamespace {
public val adapterTransformer: ((FrameworkAdapter) -> FrameworkAdapter)?
}
internal fun detectAdapter(): FrameworkAdapter {
@@ -35,41 +35,41 @@ internal actual fun <T : Throwable> checkResultIsFailure(exceptionClass: KClass<
/** @suppress */
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
@JvmName("assertFails")
fun assertFailsNoInline(block: () -> Unit): Throwable = assertFails(block)
public fun assertFailsNoInline(block: () -> Unit): Throwable = assertFails(block)
/** @suppress */
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
@JvmName("assertFails")
fun assertFailsNoInline(message: String?, block: () -> Unit): Throwable = assertFails(message, block)
public fun assertFailsNoInline(message: String?, block: () -> Unit): Throwable = assertFails(message, block)
/** @suppress */
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
@JvmName("assertFailsWith")
fun <T : Throwable> assertFailsWithNoInline(exceptionClass: KClass<T>, block: () -> Unit): T = assertFailsWith(exceptionClass, block)
public fun <T : Throwable> assertFailsWithNoInline(exceptionClass: KClass<T>, block: () -> Unit): T = assertFailsWith(exceptionClass, block)
/** @suppress */
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
@JvmName("assertFailsWith")
fun <T : Throwable> assertFailsWithNoInline(exceptionClass: KClass<T>, message: String?, block: () -> Unit): T =
public fun <T : Throwable> assertFailsWithNoInline(exceptionClass: KClass<T>, message: String?, block: () -> Unit): T =
assertFailsWith(exceptionClass, message, block)
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
@JvmName("assertTrue")
fun assertTrueNoInline(message: String? = null, block: () -> Boolean) {
public fun assertTrueNoInline(message: String? = null, block: () -> Boolean) {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
assertTrue(block(), message)
}
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
@JvmName("assertFalse")
fun assertFalseNoInline(message: String? = null, block: () -> Boolean) {
public fun assertFalseNoInline(message: String? = null, block: () -> Boolean) {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
assertFalse(block(), message)
}
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
@JvmName("assertNotNull")
fun <T : Any, R> assertNotNullNoInline(actual: T?, message: String? = null, block: (T) -> R) {
public fun <T : Any, R> assertNotNullNoInline(actual: T?, message: String? = null, block: (T) -> R) {
contract { returns() implies (actual != null) }
asserter.assertNotNull(message, actual)
if (actual != null) {
@@ -79,14 +79,14 @@ fun <T : Any, R> assertNotNullNoInline(actual: T?, message: String? = null, bloc
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
@JvmName("expect")
fun <T> expectNoInline(expected: T, block: () -> T) {
public fun <T> expectNoInline(expected: T, block: () -> T) {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
assertEquals(expected, block())
}
@Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN)
@JvmName("expect")
fun <T> expectNoInline(expected: T, message: String?, block: () -> T) {
public fun <T> expectNoInline(expected: T, message: String?, block: () -> T) {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
assertEquals(expected, block(), message)
}
@@ -98,7 +98,7 @@ fun <T> expectNoInline(expected: T, message: String?, block: () -> T) {
*/
@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
@InlineOnly
actual inline fun todo(@Suppress("UNUSED_PARAMETER") block: () -> Unit) {
public actual inline fun todo(@Suppress("UNUSED_PARAMETER") block: () -> Unit) {
println("TODO at " + currentStackTrace()[0])
}
@@ -109,7 +109,7 @@ actual inline fun todo(@Suppress("UNUSED_PARAMETER") block: () -> Unit) {
*/
@Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER")
@InlineOnly
inline fun currentStackTrace() = @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") (java.lang.Exception() as java.lang.Throwable).stackTrace
public inline fun currentStackTrace(): Array<StackTraceElement> = @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") (java.lang.Exception() as java.lang.Throwable).stackTrace
/** Platform-specific construction of AssertionError with cause */
@@ -9,10 +9,10 @@ package kotlin.test
* Describes the result of an assertion execution.
*/
public interface AssertionResult {
val result: Boolean
val expected: Any?
val actual: Any?
val lazyMessage: () -> String?
public val result: Boolean
public val expected: Any?
public val actual: Any?
public val lazyMessage: () -> String?
}
internal var assertHook: (AssertionResult) -> Unit = { _ -> }
@@ -31,7 +31,7 @@ public interface FrameworkAdapter {
* @param ignored whether the test suite is ignored, e.g. marked with [Ignore] annotation
* @param suiteFn defines nested suites by calling [kotlin.test.suite] and tests by calling [kotlin.test.test]
*/
fun suite(name: String, ignored: Boolean, suiteFn: () -> Unit)
public fun suite(name: String, ignored: Boolean, suiteFn: () -> Unit)
/**
* Declares a test.
@@ -40,5 +40,5 @@ public interface FrameworkAdapter {
* @param ignored whether the test is ignored
* @param testFn contains test body invocation
*/
fun test(name: String, ignored: Boolean, testFn: () -> Any?)
public fun test(name: String, ignored: Boolean, testFn: () -> Any?)
}
@@ -12,7 +12,7 @@ import kotlin.reflect.KClass
*
* This keeps the code under test referenced, but doesn't actually test it until it is implemented.
*/
actual fun todo(block: () -> Unit) {
public actual fun todo(block: () -> Unit) {
println("TODO at " + block)
}