diff --git a/core/content-matcher-test-utils/src/main/kotlin/matchers/content/ContentMatchersDsl.kt b/core/content-matcher-test-utils/src/main/kotlin/matchers/content/ContentMatchersDsl.kt index 2476a6bec67..962841ba563 100644 --- a/core/content-matcher-test-utils/src/main/kotlin/matchers/content/ContentMatchersDsl.kt +++ b/core/content-matcher-test-utils/src/main/kotlin/matchers/content/ContentMatchersDsl.kt @@ -5,7 +5,7 @@ import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.test.tools.matchers.content.* import kotlin.reflect.KClass import kotlin.test.assertEquals -import kotlin.test.assertTrue +import kotlin.test.asserter // entry point: fun ContentNode.assertNode(block: ContentMatcherBuilder.() -> Unit) { @@ -73,7 +73,7 @@ fun ContentMatcherBuilder<*>.tabbedGroup( block: ContentMatcherBuilder.() -> Unit ) = composite { block() - check { assertTrue(this.style.contains(ContentStyle.TabbedContent)) } + check { assertContains(this.style, ContentStyle.TabbedContent) } } fun ContentMatcherBuilder<*>.tab( @@ -94,7 +94,7 @@ fun ContentMatcherBuilder<*>.header(expectedLevel: Int? = null, block: ContentMa fun ContentMatcherBuilder<*>.p(block: ContentMatcherBuilder.() -> Unit) = composite { block() - check { assertTrue(this.style.contains(TextStyle.Paragraph)) } + check { assertContains(this.style, TextStyle.Paragraph) } } fun ContentMatcherBuilder<*>.link(block: ContentMatcherBuilder.() -> Unit) = composite(block) @@ -112,7 +112,7 @@ fun ContentMatcherBuilder<*>.codeInline(block: ContentMatcherBuilder.caption(block: ContentMatcherBuilder.() -> Unit) = composite { block() - check { assertTrue(this.style.contains(ContentStyle.Caption)) } + check { assertContains(this.style, ContentStyle.Caption) } } fun ContentMatcherBuilder<*>.br() = node() @@ -137,3 +137,13 @@ fun ContentMatcherBuilder.divergent(block: ContentMatc fun ContentMatcherBuilder.after(block: ContentMatcherBuilder.() -> Unit) = composite(block) + +/* + * TODO replace with kotlin.test.assertContains after migrating to Kotlin language version 1.5+ + */ +private fun assertContains(iterable: Iterable, element: T) { + asserter.assertTrue( + { "Expected the collection to contain the element.\nCollection <$iterable>, element <$element>." }, + iterable.contains(element) + ) +} diff --git a/plugins/base/src/test/kotlin/expect/AbstractExpectTest.kt b/plugins/base/src/test/kotlin/expect/AbstractExpectTest.kt index db5e99603e2..2990503561d 100644 --- a/plugins/base/src/test/kotlin/expect/AbstractExpectTest.kt +++ b/plugins/base/src/test/kotlin/expect/AbstractExpectTest.kt @@ -5,6 +5,7 @@ import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths import java.util.concurrent.TimeUnit +import kotlin.test.assertEquals import kotlin.test.assertTrue abstract class AbstractExpectTest( @@ -42,7 +43,7 @@ abstract class AbstractExpectTest( assertTrue(gitCompare.waitFor(gitTimeout, TimeUnit.MILLISECONDS), "Git timed out after $gitTimeout") gitCompare.inputStream.bufferedReader().lines().forEach { logger.info(it) } - assertTrue(gitCompare.exitValue() == 0, "${path.fileName}: outputs don't match") + assertEquals(0, gitCompare.exitValue(), "${path.fileName}: outputs don't match") } ?: throw AssertionError("obtained path is null") } @@ -54,7 +55,7 @@ abstract class AbstractExpectTest( ) { obtained?.let { _ -> val (res, out, err) = runDiff(expected, obtained, excludes, timeout) - assertTrue(res == 0, "Outputs differ:\nstdout - $out\n\nstderr - ${err ?: ""}") + assertEquals(0, res, "Outputs differ:\nstdout - $out\n\nstderr - ${err ?: ""}") } ?: throw AssertionError("obtained path is null") } diff --git a/plugins/base/src/test/kotlin/expectActuals/ExpectActualsTest.kt b/plugins/base/src/test/kotlin/expectActuals/ExpectActualsTest.kt index 36779f39146..6344aa5a31b 100644 --- a/plugins/base/src/test/kotlin/expectActuals/ExpectActualsTest.kt +++ b/plugins/base/src/test/kotlin/expectActuals/ExpectActualsTest.kt @@ -4,6 +4,7 @@ import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest import org.jetbrains.dokka.model.withDescendants import org.jetbrains.dokka.pages.ClasslikePageNode import kotlin.test.Test +import kotlin.test.assertEquals import kotlin.test.assertTrue @@ -146,21 +147,21 @@ class ExpectActualsTest : BaseAbstractTest() { val commonN1 = allChildren.filter { it.name == "[mingwX64, linuxX64]A" } val commonN2 = allChildren.filter { it.name == "[iosX64, iosArm64]A" } val noClass = allChildren.filter { it.name == "A" } - assertTrue(commonJ.size == 1, "There can be only one [jvm, js]A page") + assertEquals(1, commonJ.size, "There can be only one [jvm, js]A page") assertTrue( commonJ.first().documentables.firstOrNull()?.sourceSets?.map { it.displayName } ?.containsAll(listOf("commonJ", "js", "jvm")) ?: false, "A(jvm, js)should have commonJ, js, jvm sources" ) - assertTrue(commonN1.size == 1, "There can be only one [mingwX64, linuxX64]A page") + assertEquals(1, commonN1.size, "There can be only one [mingwX64, linuxX64]A page") assertTrue( commonN1.first().documentables.firstOrNull()?.sourceSets?.map { it.displayName } ?.containsAll(listOf("commonN1", "linuxX64", "mingwX64")) ?: false, "[mingwX64, linuxX64]A should have commonN1, linuxX64, mingwX64 sources" ) - assertTrue(commonN2.size == 1, "There can be only one [iosX64, iosArm64]A page") + assertEquals(1, commonN2.size, "There can be only one [iosX64, iosArm64]A page") assertTrue( commonN2.first().documentables.firstOrNull()?.sourceSets?.map { it.displayName } ?.containsAll(listOf("commonN2", "iosArm64", "iosX64")) ?: false, diff --git a/plugins/base/src/test/kotlin/utils/TestUtils.kt b/plugins/base/src/test/kotlin/utils/TestUtils.kt index fa9c864744d..8b794af0179 100644 --- a/plugins/base/src/test/kotlin/utils/TestUtils.kt +++ b/plugins/base/src/test/kotlin/utils/TestUtils.kt @@ -8,6 +8,7 @@ import kotlin.collections.orEmpty import kotlin.test.assertEquals import kotlin.test.assertTrue import kotlin.test.asserter +import kotlin.test.fail @DslMarker annotation class TestDSL @@ -25,7 +26,7 @@ abstract class ModelDSL : BaseAbstractTest() { interface AssertDSL { infix fun Any?.equals(other: Any?) = assertEquals(other, this) infix fun Collection?.allEquals(other: Any?) = - this?.onEach { it equals other } ?: run { assertTrue(false, "Collection is empty") } + this?.onEach { it equals other } ?: run { fail("Collection is empty") } infix fun Collection?.exists(e: T) { assertTrue(this.orEmpty().isNotEmpty(), "Collection cannot be null or empty") assertTrue(this!!.any{it == e}, "Collection doesn't contain $e")