diff --git a/libraries/kotlin.test/common/src/main/kotlin/kotlin/test/Assertions.kt b/libraries/kotlin.test/common/src/main/kotlin/kotlin/test/Assertions.kt index 5d2d49aabcb..eb9304a9999 100644 --- a/libraries/kotlin.test/common/src/main/kotlin/kotlin/test/Assertions.kt +++ b/libraries/kotlin.test/common/src/main/kotlin/kotlin/test/Assertions.kt @@ -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 assertIs(value: Any?, message: String? = null): T { +public inline fun assertIs(value: Any?, message: String? = null): T { contract { returns() implies (value is T) } assertIsOfType(value, typeOf(), 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 assertIsNot(value: Any?, message: String? = null) { +public inline fun assertIsNot(value: Any?, message: String? = null) { assertIsNotOfType(value, typeOf(), 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 assertNotNull(actual: T?, message: String? = null): T { +public fun assertNotNull(actual: T?, message: String? = null): T { contract { returns() implies (actual != null) } asserter.assertNotNull(message, actual) return actual!! @@ -149,19 +149,19 @@ fun 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 assertNotNull(actual: T?, message: String? = null, block: (T) -> R) { +public inline fun 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, element: T, message: String? = null) { +public fun <@OnlyInputTypes T> assertContains(iterable: Iterable, 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, element: T, messag /** Asserts that the [sequence] contains the specified [element], with an optional [message]. */ @SinceKotlin("1.5") -fun <@OnlyInputTypes T> assertContains(sequence: Sequence, element: T, message: String? = null) { +public fun <@OnlyInputTypes T> assertContains(sequence: Sequence, 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, element: T, messag /** Asserts that the [array] contains the specified [element], with an optional [message]. */ @SinceKotlin("1.5") -fun <@OnlyInputTypes T> assertContains(array: Array, element: T, message: String? = null) { +public fun <@OnlyInputTypes T> assertContains(array: Array, element: T, message: String? = null) { assertArrayContains(array, element, message, Array::contains, Array::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 > assertContains(range: ClosedRange, value: T, message: String? = null) { +public fun > assertContains(range: ClosedRange, value: T, message: String? = null) { assertRangeContains(range, value, message, ClosedRange::contains) } /** Asserts that the [range] contains the specified [value], with an optional [message]. */ @SinceKotlin("1.7") @ExperimentalStdlibApi -fun > assertContains(range: OpenEndRange, value: T, message: String? = null) { +public fun > assertContains(range: OpenEndRange, value: T, message: String? = null) { assertRangeContains(range, value, message, OpenEndRange::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 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, key: K, message: String? = null) { +public fun <@OnlyInputTypes K, V> assertContains(map: Map, 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, 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?, actual: Iterable?, message: String? = null) { +public fun <@OnlyInputTypes T> assertContentEquals(expected: Iterable?, actual: Iterable?, message: String? = null) { assertIterableContentEquals("Iterable", message, expected, actual, Iterable<*>::iterator) } @@ -370,7 +370,7 @@ fun <@OnlyInputTypes T> assertContentEquals(expected: Iterable?, 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?, actual: Set?, message: String? = null): Unit = +public fun <@OnlyInputTypes T> assertContentEquals(expected: Set?, actual: Set?, message: String? = null): Unit = assertContentEquals(expected, actual?.asIterable(), message) /** @@ -381,7 +381,7 @@ fun <@OnlyInputTypes T> assertContentEquals(expected: Set?, actual: Set?, * 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?, actual: Sequence?, message: String? = null) { +public fun <@OnlyInputTypes T> assertContentEquals(expected: Sequence?, actual: Sequence?, message: String? = null) { assertIterableContentEquals("Sequence", message, expected, actual, Sequence<*>::iterator) } @@ -393,7 +393,7 @@ fun <@OnlyInputTypes T> assertContentEquals(expected: Sequence?, 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?, actual: Array?, message: String? = null) { +public fun <@OnlyInputTypes T> assertContentEquals(expected: Array?, actual: Array?, 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?, actual: Array 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): * The returned exception can be inspected further, for example by asserting its property values. */ @InlineOnly -inline fun assertFailsWith(message: String? = null, block: () -> Unit): T = +public inline fun assertFailsWith(message: String? = null, block: () -> Unit): T = assertFailsWith(T::class, message, block) /** @@ -603,7 +603,7 @@ inline fun assertFailsWith(message: String? = null, bloc */ @InlineOnly @JvmName("assertFailsWithInline") -inline fun assertFailsWith(exceptionClass: KClass, block: () -> Unit): T = assertFailsWith(exceptionClass, null, block) +public inline fun assertFailsWith(exceptionClass: KClass, 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 assertFailsWith(exceptionClass: KClass, block: () */ @InlineOnly @JvmName("assertFailsWithInline") -inline fun assertFailsWith(exceptionClass: KClass, message: String?, block: () -> Unit): T = +public inline fun assertFailsWith(exceptionClass: KClass, 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? } diff --git a/libraries/kotlin.test/common/src/main/kotlin/kotlin/test/AssertionsH.kt b/libraries/kotlin.test/common/src/main/kotlin/kotlin/test/AssertionsH.kt index 1ba78fb2462..a587efcf02f 100644 --- a/libraries/kotlin.test/common/src/main/kotlin/kotlin/test/AssertionsH.kt +++ b/libraries/kotlin.test/common/src/main/kotlin/kotlin/test/AssertionsH.kt @@ -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 diff --git a/libraries/kotlin.test/common/src/main/kotlin/kotlin/test/DefaultAsserter.kt b/libraries/kotlin.test/common/src/main/kotlin/kotlin/test/DefaultAsserter.kt index ecbb0e26a12..c0a0aafc0b4 100644 --- a/libraries/kotlin.test/common/src/main/kotlin/kotlin/test/DefaultAsserter.kt +++ b/libraries/kotlin.test/common/src/main/kotlin/kotlin/test/DefaultAsserter.kt @@ -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() diff --git a/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/DefaultJsAsserter.kt b/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/DefaultJsAsserter.kt index 5ab5d9a6a35..3f56f820059 100644 --- a/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/DefaultJsAsserter.kt +++ b/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/DefaultJsAsserter.kt @@ -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 = { _ -> } diff --git a/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/FrameworkAdapter.kt b/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/FrameworkAdapter.kt index 6b5cbcaa3a4..01811ffbbae 100644 --- a/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/FrameworkAdapter.kt +++ b/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/FrameworkAdapter.kt @@ -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?) } diff --git a/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/JsImpl.kt b/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/JsImpl.kt index e8c9ff3d0fb..8e3145642f5 100644 --- a/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/JsImpl.kt +++ b/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/JsImpl.kt @@ -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) } diff --git a/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/TestApi.kt b/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/TestApi.kt index 04843dfef58..4d2259f75c6 100644 --- a/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/TestApi.kt +++ b/libraries/kotlin.test/js/src/main/kotlin/kotlin/test/TestApi.kt @@ -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 { diff --git a/libraries/kotlin.test/jvm/src/main/kotlin/AssertionsImpl.kt b/libraries/kotlin.test/jvm/src/main/kotlin/AssertionsImpl.kt index 741ddbf7744..986a6690236 100644 --- a/libraries/kotlin.test/jvm/src/main/kotlin/AssertionsImpl.kt +++ b/libraries/kotlin.test/jvm/src/main/kotlin/AssertionsImpl.kt @@ -35,41 +35,41 @@ internal actual fun 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 assertFailsWithNoInline(exceptionClass: KClass, block: () -> Unit): T = assertFailsWith(exceptionClass, block) +public fun assertFailsWithNoInline(exceptionClass: KClass, block: () -> Unit): T = assertFailsWith(exceptionClass, block) /** @suppress */ @Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN) @JvmName("assertFailsWith") -fun assertFailsWithNoInline(exceptionClass: KClass, message: String?, block: () -> Unit): T = +public fun assertFailsWithNoInline(exceptionClass: KClass, 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 assertNotNullNoInline(actual: T?, message: String? = null, block: (T) -> R) { +public fun 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 assertNotNullNoInline(actual: T?, message: String? = null, bloc @Deprecated("Provided for binary compatibility", level = DeprecationLevel.HIDDEN) @JvmName("expect") -fun expectNoInline(expected: T, block: () -> T) { +public fun 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 expectNoInline(expected: T, message: String?, block: () -> T) { +public fun expectNoInline(expected: T, message: String?, block: () -> T) { contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) } assertEquals(expected, block(), message) } @@ -98,7 +98,7 @@ fun 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 = @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") (java.lang.Exception() as java.lang.Throwable).stackTrace /** Platform-specific construction of AssertionError with cause */ diff --git a/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/DefaultWasmAsserter.kt b/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/DefaultWasmAsserter.kt index 19a16ab6fe9..5298a61cf3b 100644 --- a/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/DefaultWasmAsserter.kt +++ b/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/DefaultWasmAsserter.kt @@ -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 = { _ -> } diff --git a/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/FrameworkAdapter.kt b/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/FrameworkAdapter.kt index 6ed7616b493..231227e0a5c 100644 --- a/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/FrameworkAdapter.kt +++ b/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/FrameworkAdapter.kt @@ -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?) } diff --git a/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/WasmImpl.kt b/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/WasmImpl.kt index f6f6fddc77e..6e178c0cd09 100644 --- a/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/WasmImpl.kt +++ b/libraries/kotlin.test/wasm/src/main/kotlin/kotlin/test/WasmImpl.kt @@ -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) }