Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnatBeresnev committed Aug 29, 2023
1 parent 3cf5d11 commit 3585e97
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContentComposite>.() -> Unit) {
Expand Down Expand Up @@ -73,7 +73,7 @@ fun ContentMatcherBuilder<*>.tabbedGroup(
block: ContentMatcherBuilder<ContentGroup>.() -> Unit
) = composite<ContentGroup> {
block()
check { assertTrue(this.style.contains(ContentStyle.TabbedContent)) }
check { assertContains(this.style, ContentStyle.TabbedContent) }
}

fun ContentMatcherBuilder<*>.tab(
Expand All @@ -94,7 +94,7 @@ fun ContentMatcherBuilder<*>.header(expectedLevel: Int? = null, block: ContentMa
fun ContentMatcherBuilder<*>.p(block: ContentMatcherBuilder<ContentGroup>.() -> Unit) =
composite<ContentGroup> {
block()
check { assertTrue(this.style.contains(TextStyle.Paragraph)) }
check { assertContains(this.style, TextStyle.Paragraph) }
}

fun ContentMatcherBuilder<*>.link(block: ContentMatcherBuilder<ContentLink>.() -> Unit) = composite(block)
Expand All @@ -112,7 +112,7 @@ fun ContentMatcherBuilder<*>.codeInline(block: ContentMatcherBuilder<ContentCode

fun ContentMatcherBuilder<*>.caption(block: ContentMatcherBuilder<ContentGroup>.() -> Unit) = composite<ContentGroup> {
block()
check { assertTrue(this.style.contains(ContentStyle.Caption)) }
check { assertContains(this.style, ContentStyle.Caption) }
}

fun ContentMatcherBuilder<*>.br() = node<ContentBreakLine>()
Expand All @@ -137,3 +137,13 @@ fun ContentMatcherBuilder<ContentDivergentInstance>.divergent(block: ContentMatc

fun ContentMatcherBuilder<ContentDivergentInstance>.after(block: ContentMatcherBuilder<ContentComposite>.() -> Unit) =
composite(block)

/*
* TODO replace with kotlin.test.assertContains after migrating to Kotlin language version 1.5+
*/
private fun <T> assertContains(iterable: Iterable<T>, element: T) {
asserter.assertTrue(
{ "Expected the collection to contain the element.\nCollection <$iterable>, element <$element>." },
iterable.contains(element)
)
}
5 changes: 3 additions & 2 deletions plugins/base/src/test/kotlin/expect/AbstractExpectTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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")
}

Expand All @@ -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")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion plugins/base/src/test/kotlin/utils/TestUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,7 +26,7 @@ abstract class ModelDSL : BaseAbstractTest() {
interface AssertDSL {
infix fun Any?.equals(other: Any?) = assertEquals(other, this)
infix fun Collection<Any>?.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 <T> Collection<T>?.exists(e: T) {
assertTrue(this.orEmpty().isNotEmpty(), "Collection cannot be null or empty")
assertTrue(this!!.any{it == e}, "Collection doesn't contain $e")
Expand Down

0 comments on commit 3585e97

Please sign in to comment.