diff --git a/common/src/main/kotlin/org/amshove/kluent/AssertionErrors.kt b/common/src/main/kotlin/org/amshove/kluent/AssertionErrors.kt new file mode 100644 index 00000000..3b120e2c --- /dev/null +++ b/common/src/main/kotlin/org/amshove/kluent/AssertionErrors.kt @@ -0,0 +1,47 @@ +package org.amshove.kluent + +import kotlin.test.assertFails + +/** An error that bundles multiple other [Throwable]s together */ +class MultiAssertionError(errors: List) : AssertionError(createMessage(errors)) { + companion object { + private fun createMessage(errors: List) = buildString { + append("\nThe following ") + + if (errors.size == 1) { + append("assertion") + } else { + append(errors.size).append(" assertions") + } + append(" failed:\n") + + if (errors.size == 1) { + append(errors[0].message).append("\n") + stacktraces.throwableLocation(errors[0])?.let { + append("\tat ").append(it).append("\n") + } + } else { + for ((i, err) in errors.withIndex()) { + append(i + 1).append(") ").append(err.message).append("\n") + stacktraces.throwableLocation(err)?.let { + append("\tat ").append(it).append("\n") + } + } + } + } + } +} + +fun assertionError(error: Throwable): Throwable { + val message = buildString { + append("\nThe following assertion failed:\n") + + append(error.message).append("\n") + stacktraces.throwableLocation(error)?.let { + append("\tat ").append(it).append("\n") + } + } + val t = AssertionError(message) + stacktraces.cleanStackTrace(t) + return t +} diff --git a/common/src/main/kotlin/org/amshove/kluent/Basic.kt b/common/src/main/kotlin/org/amshove/kluent/Basic.kt index e884cd13..93ae236f 100644 --- a/common/src/main/kotlin/org/amshove/kluent/Basic.kt +++ b/common/src/main/kotlin/org/amshove/kluent/Basic.kt @@ -3,9 +3,6 @@ package org.amshove.kluent import org.amshove.kluent.internal.* import kotlin.contracts.ExperimentalContracts import kotlin.contracts.contract -import kotlin.test.assertEquals -import kotlin.test.assertNotEquals -import kotlin.test.fail @Deprecated("Use `shouldBeEqualTo`", ReplaceWith("this.shouldBeEqualTo(expected)")) infix fun T.shouldEqual(expected: T?): T = this.shouldBeEqualTo(expected) diff --git a/common/src/main/kotlin/org/amshove/kluent/CharSequence.kt b/common/src/main/kotlin/org/amshove/kluent/CharSequence.kt index e0928940..8db73434 100644 --- a/common/src/main/kotlin/org/amshove/kluent/CharSequence.kt +++ b/common/src/main/kotlin/org/amshove/kluent/CharSequence.kt @@ -1,11 +1,11 @@ package org.amshove.kluent +import org.amshove.kluent.internal.assertEquals import org.amshove.kluent.internal.assertFalse +import org.amshove.kluent.internal.assertNotEquals import org.amshove.kluent.internal.assertTrue import kotlin.contracts.ExperimentalContracts import kotlin.contracts.contract -import kotlin.test.assertEquals -import kotlin.test.assertNotEquals infix fun T.shouldStartWith(expected: T) = this.apply { assertTrue("Expected the CharSequence $this to start with $expected", this.startsWith(expected)) } diff --git a/common/src/main/kotlin/org/amshove/kluent/Collections.kt b/common/src/main/kotlin/org/amshove/kluent/Collections.kt index 24a3f3b1..ebd6f721 100644 --- a/common/src/main/kotlin/org/amshove/kluent/Collections.kt +++ b/common/src/main/kotlin/org/amshove/kluent/Collections.kt @@ -1,9 +1,6 @@ package org.amshove.kluent import org.amshove.kluent.internal.* -import kotlin.test.assertEquals -import kotlin.test.assertNotEquals -import kotlin.test.fail infix fun Array.shouldContain(expected: T) = apply { if (this.contains(expected)) Unit else failExpectedActual("Array doesn't contain \"$expected\"", "the Array to contain \"$expected\"", join(this)) } diff --git a/common/src/main/kotlin/org/amshove/kluent/ErrorCollector.kt b/common/src/main/kotlin/org/amshove/kluent/ErrorCollector.kt new file mode 100644 index 00000000..e23598c9 --- /dev/null +++ b/common/src/main/kotlin/org/amshove/kluent/ErrorCollector.kt @@ -0,0 +1,77 @@ +package org.amshove.kluent + +expect val errorCollector: ErrorCollector + +enum class ErrorCollectionMode { + Soft, Hard +} + +interface ErrorCollector { + + fun getCollectionMode(): ErrorCollectionMode + + fun setCollectionMode(mode: ErrorCollectionMode) + + /** + * Returns the errors accumulated in the current context. + */ + fun errors(): List + + /** + * Adds the given error to the current context. + */ + fun pushError(t: Throwable) + + /** + * Clears all errors from the current context. + */ + fun clear() +} + +open class BasicErrorCollector : ErrorCollector { + + private val failures = mutableListOf() + private var mode = ErrorCollectionMode.Hard + + override fun getCollectionMode(): ErrorCollectionMode = mode + + override fun setCollectionMode(mode: ErrorCollectionMode) { + this.mode = mode + } + + override fun pushError(t: Throwable) { + failures.add(t) + } + + override fun errors(): List = failures.toList() + + override fun clear() = failures.clear() +} + +/** + * If we are in "soft assertion mode" will add this throwable to the + * list of throwables for the current execution. Otherwise will + * throw immediately. + */ +fun ErrorCollector.collectOrThrow(error: Throwable) { + when (getCollectionMode()) { + ErrorCollectionMode.Soft -> pushError(error) + ErrorCollectionMode.Hard -> throw error + } +} + +/** + * The errors for the current execution are thrown as a single + * throwable. + */ +fun ErrorCollector.throwCollectedErrors() { + // set the collection mode back to the default + setCollectionMode(ErrorCollectionMode.Hard) + val failures = errors() + clear() + if (failures.isNotEmpty()) { + val t = MultiAssertionError(failures) + stacktraces.cleanStackTrace(t) + throw t + } +} \ No newline at end of file diff --git a/common/src/main/kotlin/org/amshove/kluent/Numerical.kt b/common/src/main/kotlin/org/amshove/kluent/Numerical.kt index 2970e2fd..235eef14 100644 --- a/common/src/main/kotlin/org/amshove/kluent/Numerical.kt +++ b/common/src/main/kotlin/org/amshove/kluent/Numerical.kt @@ -1,8 +1,8 @@ package org.amshove.kluent +import org.amshove.kluent.internal.assertEquals +import org.amshove.kluent.internal.assertNotEquals import org.amshove.kluent.internal.assertTrue -import kotlin.test.assertEquals -import kotlin.test.assertNotEquals @Deprecated("Use `shouldBeEqualTo`", ReplaceWith("this.shouldBeEqualTo(expected)")) infix fun Boolean.shouldEqualTo(expected: Boolean) = this.shouldBeEqualTo(expected) diff --git a/common/src/main/kotlin/org/amshove/kluent/Softly.kt b/common/src/main/kotlin/org/amshove/kluent/Softly.kt new file mode 100644 index 00000000..d279a781 --- /dev/null +++ b/common/src/main/kotlin/org/amshove/kluent/Softly.kt @@ -0,0 +1,20 @@ +package org.amshove.kluent + +inline fun assertSoftly(assertions: () -> T): T { + // Handle the edge case of nested calls to this function by only calling throwCollectedErrors in the + // outermost verifyAll block + if (errorCollector.getCollectionMode() == ErrorCollectionMode.Soft) { + return assertions() + } + errorCollector.setCollectionMode(ErrorCollectionMode.Soft) + return assertions().apply { + errorCollector.throwCollectedErrors() + } +} + +inline fun assertSoftly(t: T, assertions: T.(T) -> Unit): T { + return assertSoftly { + t.assertions(t) + t + } +} \ No newline at end of file diff --git a/common/src/main/kotlin/org/amshove/kluent/StackTraces.kt b/common/src/main/kotlin/org/amshove/kluent/StackTraces.kt new file mode 100644 index 00000000..a47d3481 --- /dev/null +++ b/common/src/main/kotlin/org/amshove/kluent/StackTraces.kt @@ -0,0 +1,37 @@ +package org.amshove.kluent + +expect val stacktraces: StackTraces + +object BasicStackTraces : StackTraces { + override fun throwableLocation(t: Throwable): String? = null + override fun throwableLocation(t: Throwable, n: Int): List? = null + override fun cleanStackTrace(throwable: T): T = throwable + override fun root(throwable: Throwable): Throwable = throwable +} + +interface StackTraces { + + /** + * Returns the first line of this stack trace, skipping io.kotest if possible. + * On some platforms the stack trace may not be available and will return null. + */ + fun throwableLocation(t: Throwable): String? + + /** + * Returns the first n lines of this stack trace, skipping io.test if possible. + * On some platforms the stack trace may not be available and will return null. + */ + fun throwableLocation(t: Throwable, n: Int): List? + + /** + * Removes io.kotest stack elements from the given throwable if the platform supports stack traces, + * otherwise returns the exception as is. + */ + fun cleanStackTrace(throwable: T): T + + /** + * Returns the root cause of the given throwable. If it has no root cause, or the platform does + * not support causes, this will be returned. + */ + fun root(throwable: Throwable): Throwable +} diff --git a/common/src/main/kotlin/org/amshove/kluent/internal/Assertions.kt b/common/src/main/kotlin/org/amshove/kluent/internal/Assertions.kt index 3e6d8a46..9a16cbb2 100644 --- a/common/src/main/kotlin/org/amshove/kluent/internal/Assertions.kt +++ b/common/src/main/kotlin/org/amshove/kluent/internal/Assertions.kt @@ -1,15 +1,37 @@ package org.amshove.kluent.internal -import kotlin.test.assertFalse -import kotlin.test.assertTrue -import kotlin.test.fail +import org.amshove.kluent.* +import kotlin.jvm.JvmName +import kotlin.reflect.KClass +import kotlin.test.asserter internal fun assertTrue(message: String, boolean: Boolean) = assertTrue(boolean, message) -internal inline fun assertTrue(boolean: Boolean, lazyMessage: () -> String) { - if (!boolean) fail(lazyMessage()) +internal fun assertTrue(actual: Boolean, message: String? = null) { + if (!actual) { + if (errorCollector.getCollectionMode() == ErrorCollectionMode.Soft) { + try { + throw AssertionError(message) + } catch (ex: AssertionError) { + errorCollector.pushError(ex) + } + } else { + try { + throw AssertionError(message) + } catch (ex: AssertionError) { + throw assertionError(ex) + } + } + } +} + +internal inline fun assertTrue(actual: Boolean, lazyMessage: () -> String) { + assertTrue(actual, lazyMessage()) } internal fun assertFalse(message: String, boolean: Boolean) = assertFalse(boolean, message) +fun assertFalse(actual: Boolean, message: String? = null) { + return assertTrue(message ?: "Expected value to be false.", !actual) +} internal fun assertArrayEquals(a1: Array?, a2: Array?) { if (!arraysEqual(a1, a2)) { @@ -86,8 +108,8 @@ internal fun failExpectedActual(message: String, expected: String?, actual: Stri internal fun failCollectionWithDifferentItems(message: String, expected: String?, actual: String?): Nothing = fail(""" |$message - |${ if(!expected.isNullOrEmpty()) "Items included on the expected collection but not in the actual: $expected" else "" } - |${ if(!actual.isNullOrEmpty()) "Items included on the actual collection but not in the expected: $actual" else "" } + |${if (!expected.isNullOrEmpty()) "Items included on the expected collection but not in the actual: $expected" else ""} + |${if (!actual.isNullOrEmpty()) "Items included on the actual collection but not in the expected: $actual" else ""} """.trimMargin()) internal fun failFirstSecond(message: String, first: String?, second: String?): Nothing = fail(""" @@ -105,3 +127,95 @@ fun assertNotSame(expected: Any?, actual: Any?) { assertTrue("Expected <$expected>, actual <$actual> are the same instance.", actual !== expected) } +/** Asserts that the [expected] value is equal to the [actual] value, with an optional [message]. */ +fun assertEquals(expected: T, actual: T, message: String? = null) { + assertEquals(message, expected, actual) +} + +/** + * Asserts that the specified values are equal. + * + * @param message the message to report if the assertion fails. + */ +fun assertEquals(message: String?, expected: Any?, actual: Any?): Unit { + assertTrue(actual == expected) { messagePrefix(message) + "Expected <$expected>, actual <$actual>." } +} + +/** Asserts that the [actual] value is not equal to the illegal value, with an optional [message]. */ +fun assertNotEquals(illegal: T, actual: T, message: String? = null) { + assertNotEquals(message, illegal, actual) +} + +/** + * Asserts that the specified values are not equal. + * + * @param message the message to report if the assertion fails. + */ +fun assertNotEquals(message: String?, illegal: Any?, actual: Any?): Unit { + assertTrue(actual != illegal) { messagePrefix(message) + "Illegal value: <$actual>." } +} + +/** + * Asserts that given function [block] fails by throwing an exception. + * + * @return An exception that was expected to be thrown and was successfully caught. + * The returned exception can be inspected further, for example by asserting its property values. + */ +@JvmName("assertFailsInline") +inline fun assertFails(block: () -> Unit): Throwable = + checkResultIsFailure(null, runCatching(block)) + +/** + * Asserts that given function [block] fails by throwing an exception. + * + * If the assertion fails, the specified [message] is used unless it is null as a prefix for the failure message. + * + * @return An exception that was expected to be thrown and was successfully caught. + * The returned exception can be inspected further, for example by asserting its property values. + */ +@JvmName("assertFailsInline") +inline fun assertFails(message: String?, block: () -> Unit): Throwable = + checkResultIsFailure(message, runCatching(block)) + +@PublishedApi +internal fun checkResultIsFailure(message: String?, blockResult: Result): Throwable { + blockResult.fold( + onSuccess = { + asserter.fail(messagePrefix(message) + "Expected an exception to be thrown, but was completed successfully.") + }, + onFailure = { e -> + return e + } + ) +} + +/** Asserts that a [block] fails with a specific exception of type [T] being thrown. + * + * If the assertion fails, the specified [message] is used unless it is null as a prefix for the failure message. + * + * @return An exception of the expected exception type [T] that successfully caught. + * The returned exception can be inspected further, for example by asserting its property values. + */ +inline fun assertFailsWith(message: String? = null, block: () -> Unit): T = + assertFailsWith(T::class, message, block) + +/** + * Asserts that a [block] fails with a specific exception of type [exceptionClass] being thrown. + * + * @return An exception of the expected exception type [T] that successfully caught. + * The returned exception can be inspected further, for example by asserting its property values. + */ +@JvmName("assertFailsWithInline") +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. + * + * If the assertion fails, the specified [message] is used unless it is null as a prefix for the failure message. + * + * @return An exception of the expected exception type [T] that successfully caught. + * The returned exception can be inspected further, for example by asserting its property values. + */ +@JvmName("assertFailsWithInline") +inline fun assertFailsWith(exceptionClass: KClass, message: String?, block: () -> Unit): T = + checkResultIsFailure(exceptionClass, message, runCatching(block)) diff --git a/common/src/main/kotlin/org/amshove/kluent/internal/Utility.kt b/common/src/main/kotlin/org/amshove/kluent/internal/Utility.kt index e53792be..5b1938f1 100644 --- a/common/src/main/kotlin/org/amshove/kluent/internal/Utility.kt +++ b/common/src/main/kotlin/org/amshove/kluent/internal/Utility.kt @@ -1,5 +1,7 @@ package org.amshove.kluent.internal +import kotlin.reflect.KClass + internal fun join(theArray: Array?): String = if (theArray == null) "null" else "[${theArray.joinToString(", ")}]" internal fun join(theIterable: Iterable): String = "[${theIterable.joinToString(", ")}]" internal fun join(theMap: Map): String = "Entries: [${theMap.entries.joinToString(", ")}]" @@ -7,3 +9,13 @@ internal fun join(theMap: Map): String = "Entries: [${theMap.entrie internal fun joinKeys(map: Map<*, *>) = "Keys: [${join(map.keys)}]" internal fun joinValues(map: Map<*, *>) = "Values: [${join(map.values)}]" internal fun joinPairs(map: Map<*, *>) = "Pairs: [${map.map { it.toPair() }.joinToString(", ")}]" + +internal fun fail(message: String): Nothing { + throw AssertionError(message) +} + +internal fun messagePrefix(message: String?) = if (message == null) "" else "$message. " + +/** Asserts that a [blockResult] is a failure with the specific exception type being thrown. */ +@PublishedApi +internal expect fun checkResultIsFailure(exceptionClass: KClass, message: String?, blockResult: Result): T diff --git a/common/src/test/kotlin/org/amshove/kluent/InternalAssertions.kt b/common/src/test/kotlin/org/amshove/kluent/InternalAssertions.kt index f9a37f5f..40a2b117 100644 --- a/common/src/test/kotlin/org/amshove/kluent/InternalAssertions.kt +++ b/common/src/test/kotlin/org/amshove/kluent/InternalAssertions.kt @@ -4,6 +4,14 @@ fun assertMessage(message: String, func: () -> Unit) { try { func() } catch (e: Throwable) { - e.message.shouldBeEqualTo(message) + e.message?.replace("\\s+|\\t|\\n".toRegex(), " ")?.trim().shouldBeEqualTo(message.replace("\\s+|\\t|\\n".toRegex(), " ").trim()) + } +} + +fun assertMessageContain(message: String, func: () -> Unit) { + try { + func() + } catch (e: Throwable) { + e.message?.contains(message, true) } } \ No newline at end of file diff --git a/common/src/test/kotlin/org/amshove/kluent/DataClasses.kt b/common/src/test/kotlin/org/amshove/kluent/tests/DataClasses.kt similarity index 64% rename from common/src/test/kotlin/org/amshove/kluent/DataClasses.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/DataClasses.kt index cc4aeaf6..d8277999 100644 --- a/common/src/test/kotlin/org/amshove/kluent/DataClasses.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/DataClasses.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent +package org.amshove.kluent.tests data class Person(val name: String, val surname: String) diff --git a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldBeDigitShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeDigitShould.kt similarity index 91% rename from common/src/test/kotlin/org/amshove/kluent/basic/ShouldBeDigitShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeDigitShould.kt index 09d5af25..edcb704c 100644 --- a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldBeDigitShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeDigitShould.kt @@ -1,8 +1,8 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeDigit import kotlin.test.Test -import kotlin.test.assertFails class ShouldBeDigitShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldBeFalseShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeFalseShould.kt similarity index 56% rename from common/src/test/kotlin/org/amshove/kluent/basic/ShouldBeFalseShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeFalseShould.kt index e8ce0122..b52e192d 100644 --- a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldBeFalseShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeFalseShould.kt @@ -1,9 +1,9 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic -import org.amshove.kluent.assertMessage +import org.amshove.kluent.assertMessageContain +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeFalse import kotlin.test.Test -import kotlin.test.assertFails class ShouldBeFalseShould { @Test @@ -18,6 +18,8 @@ class ShouldBeFalseShould { @Test fun provideADescriptiveMessage() { - assertMessage("Expected value to be false, but was true") { true.shouldBeFalse() } + assertMessageContain("Expected value to be false, but was true") { + true.shouldBeFalse() + } } } \ No newline at end of file diff --git a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldBeNullShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeNullShould.kt similarity index 76% rename from common/src/test/kotlin/org/amshove/kluent/basic/ShouldBeNullShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeNullShould.kt index 6dec463b..d85edc39 100644 --- a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldBeNullShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeNullShould.kt @@ -1,9 +1,9 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeNull import org.amshove.kluent.shouldNotBeNull import kotlin.test.Test -import kotlin.test.assertFails class ShouldBeNullShould { @Test @@ -14,13 +14,13 @@ class ShouldBeNullShould { @Test fun failWhenPassingNonNull() { - val str: String? = "Hello" + val str = "Hello" assertFails { str.shouldBeNull() } } @Test fun failWhenCheckingNonNullableType() { - val str: String = "Hello" + val str = "Hello" assertFails { str.shouldBeNull() } } } \ No newline at end of file diff --git a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldBeShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeShould.kt similarity index 80% rename from common/src/test/kotlin/org/amshove/kluent/basic/ShouldBeShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeShould.kt index 88bd3fee..08ecf46a 100644 --- a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldBeShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeShould.kt @@ -1,9 +1,9 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic +import org.amshove.kluent.internal.assertFails import kotlin.test.Test -import org.amshove.kluent.Person import org.amshove.kluent.shouldBe -import kotlin.test.assertFails +import org.amshove.kluent.tests.Person class ShouldBeShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldBeTrueShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeTrueShould.kt similarity index 56% rename from common/src/test/kotlin/org/amshove/kluent/basic/ShouldBeTrueShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeTrueShould.kt index 8c4d5315..4b1c27ef 100644 --- a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldBeTrueShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeTrueShould.kt @@ -1,9 +1,9 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic -import org.amshove.kluent.assertMessage +import org.amshove.kluent.assertMessageContain +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeTrue import kotlin.test.Test -import kotlin.test.assertFails class ShouldBeTrueShould { @Test @@ -18,6 +18,8 @@ class ShouldBeTrueShould { @Test fun provideADescriptiveMessage() { - assertMessage("Expected value to be true, but was false") { false.shouldBeTrue() } + assertMessageContain("Expected value to be true, but was false") { + false.shouldBeTrue() + } } } \ No newline at end of file diff --git a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldEqualShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldEqualShould.kt similarity index 89% rename from common/src/test/kotlin/org/amshove/kluent/basic/ShouldEqualShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldEqualShould.kt index 2944adb8..fe7ff79b 100644 --- a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldEqualShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldEqualShould.kt @@ -1,9 +1,9 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic -import org.amshove.kluent.Person +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeEqualTo +import org.amshove.kluent.tests.Person import kotlin.test.Test -import kotlin.test.assertFails class ShouldEqualShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldNotBeDigitShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeDigitShould.kt similarity index 92% rename from common/src/test/kotlin/org/amshove/kluent/basic/ShouldNotBeDigitShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeDigitShould.kt index e4a0bf32..d81b2872 100644 --- a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldNotBeDigitShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeDigitShould.kt @@ -1,8 +1,8 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldNotBeDigit import kotlin.test.Test -import kotlin.test.assertFails class ShouldNotBeDigitShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldNotBeFalseShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeFalseShould.kt similarity index 76% rename from common/src/test/kotlin/org/amshove/kluent/basic/ShouldNotBeFalseShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeFalseShould.kt index c9d7451c..6db05b96 100644 --- a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldNotBeFalseShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeFalseShould.kt @@ -1,8 +1,8 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldNotBeFalse import kotlin.test.Test -import kotlin.test.assertFails class ShouldNotBeFalseShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldNotBeNullShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeNullShould.kt similarity index 73% rename from common/src/test/kotlin/org/amshove/kluent/basic/ShouldNotBeNullShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeNullShould.kt index 8978e07c..d6d3acd3 100644 --- a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldNotBeNullShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeNullShould.kt @@ -1,20 +1,19 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic -import org.amshove.kluent.shouldNotBe +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldNotBeNull import kotlin.test.Test -import kotlin.test.assertFails class ShouldNotBeNullShould { @Test fun passWhenPassingNonNullReference() { - val str: String? = "Hello" + val str = "Hello" str.shouldNotBeNull() } @Test fun returnANonNullableInstance() { - val str: String? = "Hello" + val str = "Hello" val nonNullable: String = str.shouldNotBeNull() nonNullable.shouldNotBeNull() } @@ -27,7 +26,7 @@ class ShouldNotBeNullShould { @Test fun passWhenPassingNonNullableType() { - val str: String = "Hello" + val str = "Hello" str.shouldNotBeNull() } } \ No newline at end of file diff --git a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldNotBeShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeShould.kt similarity index 80% rename from common/src/test/kotlin/org/amshove/kluent/basic/ShouldNotBeShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeShould.kt index 5c2c0827..247d5d0b 100644 --- a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldNotBeShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeShould.kt @@ -1,9 +1,9 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic +import org.amshove.kluent.internal.assertFails import kotlin.test.Test -import org.amshove.kluent.Person import org.amshove.kluent.shouldNotBe -import kotlin.test.assertFails +import org.amshove.kluent.tests.Person class ShouldNotBeShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldNotBeTrueShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeTrueShould.kt similarity index 76% rename from common/src/test/kotlin/org/amshove/kluent/basic/ShouldNotBeTrueShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeTrueShould.kt index 6293eef4..9be15c8d 100644 --- a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldNotBeTrueShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeTrueShould.kt @@ -1,8 +1,8 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldNotBeTrue import kotlin.test.Test -import kotlin.test.assertFails class ShouldNotBeTrueShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldNotEqualShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotEqualShould.kt similarity index 89% rename from common/src/test/kotlin/org/amshove/kluent/basic/ShouldNotEqualShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotEqualShould.kt index 6f253986..4be4fc95 100644 --- a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldNotEqualShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotEqualShould.kt @@ -1,10 +1,10 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic -import org.amshove.kluent.Person +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeEqualTo import org.amshove.kluent.shouldNotBeEqualTo +import org.amshove.kluent.tests.Person import kotlin.test.Test -import kotlin.test.assertFails class ShouldNotEqualShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldShould.kt similarity index 87% rename from common/src/test/kotlin/org/amshove/kluent/basic/ShouldShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldShould.kt index 4e028784..f02ef16b 100644 --- a/common/src/test/kotlin/org/amshove/kluent/basic/ShouldShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldShould.kt @@ -1,10 +1,10 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic +import org.amshove.kluent.internal.assertFails +import org.amshove.kluent.internal.assertTrue import kotlin.test.Test -import org.amshove.kluent.Person import org.amshove.kluent.should -import kotlin.test.assertFails -import kotlin.test.assertTrue +import org.amshove.kluent.tests.Person class ShouldShould { @Test @@ -18,13 +18,13 @@ class ShouldShould { @Test fun passWhenPassingALambdaThatReturnsTrue() { - Person("", "") should { name.length == 0 } + Person("", "") should { name.isEmpty() } } @Test fun failWhenPassingALambdaThatReturnsFalse() { assertFails { - Person("", "") should { name.length > 0 } + Person("", "") should { name.isNotEmpty() } } } diff --git a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldBeBlankShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldBeBlankShould.kt similarity index 76% rename from common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldBeBlankShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldBeBlankShould.kt index 56f1c800..cd528d65 100644 --- a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldBeBlankShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldBeBlankShould.kt @@ -1,8 +1,8 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeBlank import kotlin.test.Test -import kotlin.test.assertFails class ShouldBeBlankShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldBeEmptyShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldBeEmptyShould.kt similarity index 76% rename from common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldBeEmptyShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldBeEmptyShould.kt index 423563bd..d61b3e89 100644 --- a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldBeEmptyShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldBeEmptyShould.kt @@ -1,8 +1,8 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeEmpty import kotlin.test.Test -import kotlin.test.assertFails class ShouldBeEmptyShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldBeNullOrBlankShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldBeNullOrBlankShould.kt similarity index 82% rename from common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldBeNullOrBlankShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldBeNullOrBlankShould.kt index f256edd4..462988b8 100644 --- a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldBeNullOrBlankShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldBeNullOrBlankShould.kt @@ -1,8 +1,8 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeNullOrBlank import kotlin.test.Test -import kotlin.test.assertFails class ShouldBeNullOrBlankShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldBeNullOrEmptyShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldBeNullOrEmptyShould.kt similarity index 82% rename from common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldBeNullOrEmptyShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldBeNullOrEmptyShould.kt index 97750558..78a1c287 100644 --- a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldBeNullOrEmptyShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldBeNullOrEmptyShould.kt @@ -1,8 +1,8 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeNullOrEmpty import kotlin.test.Test -import kotlin.test.assertFails class ShouldBeNullOrEmptyShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldContainAllShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldContainAllShould.kt similarity index 92% rename from common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldContainAllShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldContainAllShould.kt index 0ea847f9..bf82ca71 100644 --- a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldContainAllShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldContainAllShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence import org.amshove.kluent.shouldContainAll import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldContainNoneShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldContainNoneShould.kt similarity index 94% rename from common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldContainNoneShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldContainNoneShould.kt index 7751bfa4..9ea490f3 100644 --- a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldContainNoneShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldContainNoneShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence import org.amshove.kluent.shouldContainNone import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldContainShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldContainShould.kt similarity index 92% rename from common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldContainShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldContainShould.kt index afed8153..0f9c8e5b 100644 --- a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldContainShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldContainShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence import org.amshove.kluent.shouldContain import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldContainSomeShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldContainSomeShould.kt similarity index 81% rename from common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldContainSomeShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldContainSomeShould.kt index 04afd6a9..6ea8e508 100644 --- a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldContainSomeShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldContainSomeShould.kt @@ -1,12 +1,12 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldContainSome import kotlin.test.Test -import kotlin.test.assertFails class ShouldContainSomeShould { @Test - fun passWhenTestingCharSequencesWithAtleastOneBeingInTheOriginalSequence() { + fun passWhenTestingCharSequencesWithAtLeastOneBeingInTheOriginalSequence() { val message = "I love to write fluent tests" val otherStrings = listOf("Berlin", "write") diff --git a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldEndWithShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldEndWithShould.kt similarity index 89% rename from common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldEndWithShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldEndWithShould.kt index 048dd264..f6642d66 100644 --- a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldEndWithShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldEndWithShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence import org.amshove.kluent.shouldEndWith import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldMatchShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldMatchShould.kt similarity index 93% rename from common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldMatchShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldMatchShould.kt index 5c9c6f10..ccdb8653 100644 --- a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldMatchShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldMatchShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence import org.amshove.kluent.shouldMatch import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotBeBlankShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotBeBlankShould.kt similarity index 88% rename from common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotBeBlankShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotBeBlankShould.kt index 28a8d2f0..97d7b459 100644 --- a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotBeBlankShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotBeBlankShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence import org.amshove.kluent.shouldNotBeBlank import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotBeEmptyShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotBeEmptyShould.kt similarity index 88% rename from common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotBeEmptyShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotBeEmptyShould.kt index 51b8faa4..6ee0e0f1 100644 --- a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotBeEmptyShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotBeEmptyShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence import org.amshove.kluent.shouldNotBeEmpty import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotBeNullOrBlankShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotBeNullOrBlankShould.kt similarity index 94% rename from common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotBeNullOrBlankShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotBeNullOrBlankShould.kt index 696ecec6..6dfc7318 100644 --- a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotBeNullOrBlankShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotBeNullOrBlankShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence import org.amshove.kluent.shouldNotBeNullOrBlank import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotBeNullOrEmptyShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotBeNullOrEmptyShould.kt similarity index 94% rename from common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotBeNullOrEmptyShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotBeNullOrEmptyShould.kt index b81c0a5c..6ed1be5b 100644 --- a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotBeNullOrEmptyShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotBeNullOrEmptyShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence import org.amshove.kluent.shouldNotBeNullOrEmpty import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotContainAllShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotContainAllShould.kt similarity index 92% rename from common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotContainAllShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotContainAllShould.kt index 29d64588..65e3717f 100644 --- a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotContainAllShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotContainAllShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence import org.amshove.kluent.shouldNotContainAll import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotContainShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotContainShould.kt similarity index 93% rename from common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotContainShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotContainShould.kt index ca236834..c8e5900c 100644 --- a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotContainShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotContainShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence import org.amshove.kluent.shouldNotContain import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotEndWithShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotEndWithShould.kt similarity index 80% rename from common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotEndWithShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotEndWithShould.kt index 5308823a..33c6b6b9 100644 --- a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotEndWithShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotEndWithShould.kt @@ -1,8 +1,8 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldNotEndWith import kotlin.test.Test -import kotlin.test.assertFails class ShouldNotEndWithShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotMatchShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotMatchShould.kt similarity index 93% rename from common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotMatchShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotMatchShould.kt index ca72f3ba..a9eba221 100644 --- a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotMatchShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotMatchShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence import org.amshove.kluent.shouldNotMatch import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotStartWithShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotStartWithShould.kt similarity index 90% rename from common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotStartWithShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotStartWithShould.kt index 6b640a55..39225103 100644 --- a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldNotStartWithShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotStartWithShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence import org.amshove.kluent.shouldNotStartWith import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldStartWithShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldStartWithShould.kt similarity index 89% rename from common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldStartWithShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldStartWithShould.kt index 30a08cf0..82ec5079 100644 --- a/common/src/test/kotlin/org/amshove/kluent/charsequence/ShouldStartWithShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldStartWithShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence import org.amshove.kluent.shouldStartWith import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldBeEmptyShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeEmptyShould.kt similarity index 97% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldBeEmptyShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeEmptyShould.kt index 8ccbd3e4..4b4607bb 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldBeEmptyShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeEmptyShould.kt @@ -1,8 +1,8 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeEmpty import kotlin.test.Test -import kotlin.test.assertFails class ShouldBeEmptyShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldBeInRangeShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeInRangeShould.kt similarity index 84% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldBeInRangeShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeInRangeShould.kt index 56bbf979..f4649b01 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldBeInRangeShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeInRangeShould.kt @@ -1,8 +1,8 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeInRange import kotlin.test.Test -import kotlin.test.assertFails class ShouldBeInRangeShould { diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldBeInShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeInShould.kt similarity index 96% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldBeInShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeInShould.kt index 906e2b20..a09f00d1 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldBeInShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeInShould.kt @@ -1,9 +1,9 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections +import org.amshove.kluent.internal.assertFails import kotlin.test.Test -import org.amshove.kluent.Person +import org.amshove.kluent.tests.Person import org.amshove.kluent.shouldBeIn -import kotlin.test.assertFails class ShouldBeInShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldBeSortedAccordingToShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeSortedAccordingToShould.kt similarity index 97% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldBeSortedAccordingToShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeSortedAccordingToShould.kt index 5c903538..ddb333b6 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldBeSortedAccordingToShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeSortedAccordingToShould.kt @@ -1,10 +1,10 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections -import org.amshove.kluent.Person +import org.amshove.kluent.internal.assertFails +import org.amshove.kluent.tests.Person import org.amshove.kluent.shouldBeSortedAccordingTo import kotlin.random.Random import kotlin.test.Test -import kotlin.test.assertFails class ShouldBeSortedAccordingToShould { private val intComparator = Comparator { a: Int, b: Int -> a.compareTo(b) } @@ -252,7 +252,7 @@ class ShouldBeSortedAccordingToShould { } @Test - fun failWhenTestingUnsrotedIterable() { + fun failWhenTestingUnsortedIterable() { val iterable = listOf(Person("Jon", "Doe"), Person("Tom", "Guy"), Person("Peter", "Meyer")) assertFails { iterable shouldBeSortedAccordingTo personComparator } } diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainAllShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainAllShould.kt similarity index 98% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainAllShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainAllShould.kt index b5a7d359..b11747e2 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainAllShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainAllShould.kt @@ -1,8 +1,8 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldContainAll import kotlin.test.Test -import kotlin.test.assertFails class ShouldContainAllShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainAnyShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainAnyShould.kt similarity index 97% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainAnyShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainAnyShould.kt index 43421b62..411d8d0d 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainAnyShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainAnyShould.kt @@ -1,9 +1,9 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections import org.amshove.kluent.* +import org.amshove.kluent.internal.assertFails import kotlin.test.Test -import kotlin.test.assertFails class ShouldContainAnyShould { private val strings = listOf("Paris", "Berlin", "Phoenix", "Cairo") diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainFalseShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainFalseShould.kt similarity index 78% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainFalseShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainFalseShould.kt index 64ba591c..e9abf8f5 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainFalseShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainFalseShould.kt @@ -1,9 +1,8 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldContainFalse -import org.amshove.kluent.shouldContainTrue import kotlin.test.Test -import kotlin.test.assertFails class ShouldContainFalseShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainNoneShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainNoneShould.kt similarity index 99% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainNoneShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainNoneShould.kt index 60909143..2e87af62 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainNoneShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainNoneShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections import org.amshove.kluent.shouldContainNone import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainSameShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainSameShould.kt similarity index 99% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainSameShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainSameShould.kt index d78079b0..13c950c0 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainSameShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainSameShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections import org.amshove.kluent.shouldContainSame import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainShould.kt similarity index 97% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainShould.kt index b5f66dab..f032a594 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainShould.kt @@ -1,9 +1,9 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections -import org.amshove.kluent.Person +import org.amshove.kluent.internal.assertFails +import org.amshove.kluent.tests.Person import org.amshove.kluent.shouldContain import kotlin.test.Test -import kotlin.test.assertFails class ShouldContainShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainSingleItemShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainSingleItemShould.kt similarity index 97% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainSingleItemShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainSingleItemShould.kt index 8e9cf936..f562836f 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainSingleItemShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainSingleItemShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections import org.amshove.kluent.shouldBeEqualTo import org.amshove.kluent.shouldHaveSingleItem diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainSomeShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainSomeShould.kt similarity index 98% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainSomeShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainSomeShould.kt index c9c95c03..c2d05a5a 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainSomeShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainSomeShould.kt @@ -1,8 +1,8 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldContainSome import kotlin.test.Test -import kotlin.test.assertFails class ShouldContainSomeShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainTrueShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainTrueShould.kt similarity index 91% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainTrueShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainTrueShould.kt index 757c8f4d..f4f0e86c 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldContainTrueShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainTrueShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections import org.amshove.kluent.shouldContainFalse import org.amshove.kluent.shouldContainTrue diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldEqualShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldEqualShould.kt similarity index 98% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldEqualShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldEqualShould.kt index a7725832..d38b9433 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldEqualShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldEqualShould.kt @@ -1,7 +1,7 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections import org.amshove.kluent.shouldBeEqualTo -import org.amshove.kluent.Person +import org.amshove.kluent.tests.Person import kotlin.test.assertFails import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldEqualUnorderedShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldEqualUnorderedShould.kt similarity index 78% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldEqualUnorderedShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldEqualUnorderedShould.kt index d4075f86..dbdfe1ae 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldEqualUnorderedShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldEqualUnorderedShould.kt @@ -1,8 +1,10 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections -import org.amshove.kluent.* +import org.amshove.kluent.shouldBeEqualTo +import org.amshove.kluent.shouldEqualUnordered import kotlin.test.Test import kotlin.test.assertFails +import org.amshove.kluent.tests.Person class ShouldEqualUnorderedShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldHaveKeyShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldHaveKeyShould.kt similarity index 88% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldHaveKeyShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldHaveKeyShould.kt index 02e9da7f..55604b99 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldHaveKeyShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldHaveKeyShould.kt @@ -1,9 +1,9 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldHaveKey -import org.amshove.kluent.Person +import org.amshove.kluent.tests.Person import kotlin.test.Test -import kotlin.test.assertFails class ShouldHaveKeyShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldHaveSingleItemShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldHaveSingleItemShould.kt similarity index 98% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldHaveSingleItemShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldHaveSingleItemShould.kt index 5d6a2745..110dbf75 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldHaveSingleItemShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldHaveSingleItemShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections import org.amshove.kluent.shouldHaveSingleItem import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldHaveSizeShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldHaveSizeShould.kt similarity index 96% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldHaveSizeShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldHaveSizeShould.kt index 8ab8f57c..81068b88 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldHaveSizeShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldHaveSizeShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections import org.amshove.kluent.shouldHaveSize import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldHaveValueShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldHaveValueShould.kt similarity index 92% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldHaveValueShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldHaveValueShould.kt index 38ec16fa..12214ba3 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldHaveValueShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldHaveValueShould.kt @@ -1,7 +1,7 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections import org.amshove.kluent.shouldHaveValue -import org.amshove.kluent.Person +import org.amshove.kluent.tests.Person import kotlin.test.assertFails import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldMatchPredicateShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldMatchPredicateShould.kt similarity index 96% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldMatchPredicateShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldMatchPredicateShould.kt index 52e67271..28ed0f57 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldMatchPredicateShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldMatchPredicateShould.kt @@ -1,6 +1,6 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections -import org.amshove.kluent.Person +import org.amshove.kluent.tests.Person import org.amshove.kluent.shouldMatchAllWith import org.amshove.kluent.shouldMatchAtLeastOneOf import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotBeEmptyShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotBeEmptyShould.kt similarity index 97% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotBeEmptyShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotBeEmptyShould.kt index 89d58f40..bf508c43 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotBeEmptyShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotBeEmptyShould.kt @@ -1,8 +1,8 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldNotBeEmpty import kotlin.test.Test -import kotlin.test.assertFails class ShouldNotBeEmptyShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotBeInRangeShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotBeInRangeShould.kt similarity index 85% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotBeInRangeShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotBeInRangeShould.kt index 17e07fa4..682eefdf 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotBeInRangeShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotBeInRangeShould.kt @@ -1,8 +1,8 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldNotBeInRange import kotlin.test.Test -import kotlin.test.assertFails class ShouldNotBeInRangeShould { diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotBeInShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotBeInShould.kt similarity index 97% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotBeInShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotBeInShould.kt index 35bf9139..48edc099 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotBeInShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotBeInShould.kt @@ -1,7 +1,7 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections import kotlin.test.assertFails -import org.amshove.kluent.Person +import org.amshove.kluent.tests.Person import org.amshove.kluent.shouldNotBeIn import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotContainAnyShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotContainAnyShould.kt similarity index 99% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotContainAnyShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotContainAnyShould.kt index d4067caa..8dd4d858 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotContainAnyShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotContainAnyShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections import org.amshove.kluent.shouldNotContainAny import kotlin.test.assertFails diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotContainShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotContainShould.kt similarity index 98% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotContainShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotContainShould.kt index 1420e953..ce566b7a 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotContainShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotContainShould.kt @@ -1,7 +1,7 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections import org.amshove.kluent.shouldNotContain -import org.amshove.kluent.Person +import org.amshove.kluent.tests.Person import kotlin.test.Test import kotlin.test.assertFails diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotEqualShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotEqualShould.kt similarity index 97% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotEqualShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotEqualShould.kt index 31f65a9f..bed2ec6b 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotEqualShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotEqualShould.kt @@ -1,10 +1,9 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections -import org.amshove.kluent.Person +import org.amshove.kluent.internal.assertFails +import org.amshove.kluent.tests.Person import org.amshove.kluent.shouldNotBeEqualTo -import org.amshove.kluent.shouldNotEqual import kotlin.test.Test -import kotlin.test.assertFails class ShouldNotEqualShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotEqualUnorderedShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotEqualUnorderedShould.kt similarity index 83% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotEqualUnorderedShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotEqualUnorderedShould.kt index b9df63c5..47b59c30 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotEqualUnorderedShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotEqualUnorderedShould.kt @@ -1,9 +1,9 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections -import org.amshove.kluent.Person +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldNotEqualUnordered +import org.amshove.kluent.tests.Person import kotlin.test.Test -import kotlin.test.assertFails class ShouldNotEqualUnorderedShould { diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotHaveKeyShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotHaveKeyShould.kt similarity index 92% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotHaveKeyShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotHaveKeyShould.kt index 527f5400..b26907c5 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotHaveKeyShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotHaveKeyShould.kt @@ -1,7 +1,7 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections import org.amshove.kluent.shouldNotHaveKey -import org.amshove.kluent.Person +import org.amshove.kluent.tests.Person import kotlin.test.Test import kotlin.test.assertFails diff --git a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotHaveValueShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotHaveValueShould.kt similarity index 88% rename from common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotHaveValueShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotHaveValueShould.kt index 15b6cf45..0e639a3b 100644 --- a/common/src/test/kotlin/org/amshove/kluent/collections/ShouldNotHaveValueShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotHaveValueShould.kt @@ -1,8 +1,8 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections -import org.amshove.kluent.Person +import org.amshove.kluent.internal.assertFails +import org.amshove.kluent.tests.Person import org.amshove.kluent.shouldNotHaveValue -import kotlin.test.assertFails import kotlin.test.Test class ShouldNotHaveValueShould { diff --git a/common/src/test/kotlin/org/amshove/kluent/concepts/ChainingAssertionsShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/concepts/ChainingAssertionsShould.kt similarity index 96% rename from common/src/test/kotlin/org/amshove/kluent/concepts/ChainingAssertionsShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/concepts/ChainingAssertionsShould.kt index de334da1..7825b940 100644 --- a/common/src/test/kotlin/org/amshove/kluent/concepts/ChainingAssertionsShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/concepts/ChainingAssertionsShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.concepts +package org.amshove.kluent.tests.concepts import org.amshove.kluent.* import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/numerical/ShouldBeGreaterOrEqualToShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeGreaterOrEqualToShould.kt similarity index 96% rename from common/src/test/kotlin/org/amshove/kluent/numerical/ShouldBeGreaterOrEqualToShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeGreaterOrEqualToShould.kt index 8f9f1647..05913a48 100644 --- a/common/src/test/kotlin/org/amshove/kluent/numerical/ShouldBeGreaterOrEqualToShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeGreaterOrEqualToShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.numerical +package org.amshove.kluent.tests.numerical import org.amshove.kluent.shouldBeGreaterOrEqualTo import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/numerical/ShouldBeGreaterThanShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeGreaterThanShould.kt similarity index 92% rename from common/src/test/kotlin/org/amshove/kluent/numerical/ShouldBeGreaterThanShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeGreaterThanShould.kt index 04ed97b6..8076f130 100644 --- a/common/src/test/kotlin/org/amshove/kluent/numerical/ShouldBeGreaterThanShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeGreaterThanShould.kt @@ -1,7 +1,7 @@ -package org.amshove.kluent.numerical +package org.amshove.kluent.tests.numerical +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeGreaterThan -import kotlin.test.assertFails import kotlin.test.Test class ShouldBeGreaterThanShould { diff --git a/common/src/test/kotlin/org/amshove/kluent/numerical/ShouldBeInRangeShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeInRangeShould.kt similarity index 98% rename from common/src/test/kotlin/org/amshove/kluent/numerical/ShouldBeInRangeShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeInRangeShould.kt index a41e42f1..c6cb8a94 100644 --- a/common/src/test/kotlin/org/amshove/kluent/numerical/ShouldBeInRangeShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeInRangeShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.numerical +package org.amshove.kluent.tests.numerical import org.amshove.kluent.shouldBeInRange import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/numerical/ShouldBeLessOrEqualToShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeLessOrEqualToShould.kt similarity index 92% rename from common/src/test/kotlin/org/amshove/kluent/numerical/ShouldBeLessOrEqualToShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeLessOrEqualToShould.kt index 423f0d15..2390e7a1 100644 --- a/common/src/test/kotlin/org/amshove/kluent/numerical/ShouldBeLessOrEqualToShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeLessOrEqualToShould.kt @@ -1,8 +1,8 @@ -package org.amshove.kluent.numerical +package org.amshove.kluent.tests.numerical +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeLessOrEqualTo import kotlin.test.Test -import kotlin.test.assertFails class ShouldBeLessOrEqualToShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/numerical/ShouldBeLessThanShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeLessThanShould.kt similarity index 94% rename from common/src/test/kotlin/org/amshove/kluent/numerical/ShouldBeLessThanShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeLessThanShould.kt index c1e5df77..45c4665c 100644 --- a/common/src/test/kotlin/org/amshove/kluent/numerical/ShouldBeLessThanShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeLessThanShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.numerical +package org.amshove.kluent.tests.numerical import org.amshove.kluent.shouldBeLessThan import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/numerical/ShouldBeNearShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeNearShould.kt similarity index 98% rename from common/src/test/kotlin/org/amshove/kluent/numerical/ShouldBeNearShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeNearShould.kt index b986299b..da136dc9 100644 --- a/common/src/test/kotlin/org/amshove/kluent/numerical/ShouldBeNearShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeNearShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.numerical +package org.amshove.kluent.tests.numerical import org.amshove.kluent.shouldBeNear import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/numerical/ShouldBeNegativeShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeNegativeShould.kt similarity index 96% rename from common/src/test/kotlin/org/amshove/kluent/numerical/ShouldBeNegativeShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeNegativeShould.kt index 41d0252f..e347e1bb 100644 --- a/common/src/test/kotlin/org/amshove/kluent/numerical/ShouldBeNegativeShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeNegativeShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.numerical +package org.amshove.kluent.tests.numerical import org.amshove.kluent.shouldBeNegative import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/numerical/ShouldBePositiveShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBePositiveShould.kt similarity index 96% rename from common/src/test/kotlin/org/amshove/kluent/numerical/ShouldBePositiveShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBePositiveShould.kt index 607bcd2b..ea231db4 100644 --- a/common/src/test/kotlin/org/amshove/kluent/numerical/ShouldBePositiveShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBePositiveShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.numerical +package org.amshove.kluent.tests.numerical import org.amshove.kluent.shouldBePositive import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/numerical/ShouldNotBeGreaterOrEqualToShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldNotBeGreaterOrEqualToShould.kt similarity index 93% rename from common/src/test/kotlin/org/amshove/kluent/numerical/ShouldNotBeGreaterOrEqualToShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldNotBeGreaterOrEqualToShould.kt index 75c35fe9..41b2ce4b 100644 --- a/common/src/test/kotlin/org/amshove/kluent/numerical/ShouldNotBeGreaterOrEqualToShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldNotBeGreaterOrEqualToShould.kt @@ -1,8 +1,8 @@ -package org.amshove.kluent.numerical +package org.amshove.kluent.tests.numerical +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldNotBeGreaterOrEqualTo import kotlin.test.Test -import kotlin.test.assertFails class ShouldNotBeGreaterOrEqualToShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/numerical/ShouldNotBeGreaterThanShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldNotBeGreaterThanShould.kt similarity index 96% rename from common/src/test/kotlin/org/amshove/kluent/numerical/ShouldNotBeGreaterThanShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldNotBeGreaterThanShould.kt index e1337c27..b9370eca 100644 --- a/common/src/test/kotlin/org/amshove/kluent/numerical/ShouldNotBeGreaterThanShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldNotBeGreaterThanShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.numerical +package org.amshove.kluent.tests.numerical import org.amshove.kluent.shouldNotBeGreaterThan import kotlin.test.Test diff --git a/common/src/test/kotlin/org/amshove/kluent/numerical/ShouldNotBeInRangeShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldNotBeInRangeShould.kt similarity index 98% rename from common/src/test/kotlin/org/amshove/kluent/numerical/ShouldNotBeInRangeShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldNotBeInRangeShould.kt index 99e23838..51426cf1 100644 --- a/common/src/test/kotlin/org/amshove/kluent/numerical/ShouldNotBeInRangeShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldNotBeInRangeShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.numerical +package org.amshove.kluent.tests.numerical import org.amshove.kluent.shouldNotBeInRange import kotlin.test.assertFails diff --git a/common/src/test/kotlin/org/amshove/kluent/numerical/ShouldNotBeLessOrEqualToShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldNotBeLessOrEqualToShould.kt similarity index 96% rename from common/src/test/kotlin/org/amshove/kluent/numerical/ShouldNotBeLessOrEqualToShould.kt rename to common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldNotBeLessOrEqualToShould.kt index 72baf500..b2a22933 100644 --- a/common/src/test/kotlin/org/amshove/kluent/numerical/ShouldNotBeLessOrEqualToShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldNotBeLessOrEqualToShould.kt @@ -1,4 +1,4 @@ -package org.amshove.kluent.numerical +package org.amshove.kluent.tests.numerical import org.amshove.kluent.shouldNotBeLessOrEqualTo import kotlin.test.Test diff --git a/docs/README.md b/docs/README.md index f31f8aca..c23b9e67 100644 --- a/docs/README.md +++ b/docs/README.md @@ -40,6 +40,8 @@ It uses the [Infix-Notations](https://kotlinlang.org/docs/reference/functions.ht [Equivalency assertions](Equivalency.md) +[Softly assertions](SoftlyAssertions.md) + ## Using backticks Every method that is included in Kluent also has a "backtick version", to make it feel more like a describing sentence. diff --git a/docs/SoftlyAssertions.md b/docs/SoftlyAssertions.md new file mode 100644 index 00000000..4c510a85 --- /dev/null +++ b/docs/SoftlyAssertions.md @@ -0,0 +1,164 @@ +#Softly Assertions + +Inspired by [Kotest](https://github.com/kotest/kotest): + +Usually if an assertion fails, it throws an exception, so you can immediately note that your test fails: +```kt + fun houseTest() { + // arrange + data class Guest(val name: String) + class Room(val maxGuests: Int = 2) { + private var _guests: MutableList = mutableListOf() + + val guests: List + get() = _guests + + fun host(guestToHost: Guest): Boolean { + if (_guests.size < maxGuests) { + _guests.add(guestToHost) + } else { + return false + } + return true + } + } + class House(val maxGuests: Int = 5) { + private var _rooms: MutableList = mutableListOf() + private var _guests: MutableList = mutableListOf() + + val rooms: List + get() = _rooms + + val guests: List + get() = _guests + + fun host(guestToHost: List) { + for (guest in guestToHost) { + if (_guests.size == maxGuests) { + return + } + + if (_rooms.isEmpty()) { + _rooms.add(Room()) + } + if (!_rooms.last().host(guest)) { + _rooms.add(Room()) + _rooms.last().host(guest) + } + + _guests.add(guest) + } + } + } + + // act + val guests = listOf( + Guest("a"), + Guest("b"), + Guest("c"), + Guest("d"), + Guest("e"), + Guest("f") + ) + val house = House() + house.host(guests) + + // assert + house.rooms.size.shouldBeEqualTo(2) + house.guests.size.shouldBeEqualTo(6) + } +``` + +As the result: + +*java.lang.AssertionError:* +*The following assertion failed:* +*Expected <2>, actual <3>.* + +But why is it failed? Why 6 guests occupied 3 rooms? +Now let's move our assertions into assertSoftly: + +```kt + fun houseTest() { + // arrange + data class Guest(val name: String) + class Room(val maxGuests: Int = 2) { + private var _guests: MutableList = mutableListOf() + + val guests: List + get() = _guests + + fun host(guestToHost: Guest): Boolean { + if (_guests.size < maxGuests) { + _guests.add(guestToHost) + } else { + return false + } + return true + } + } + class House(val maxGuests: Int = 5) { + private var _rooms: MutableList = mutableListOf() + private var _guests: MutableList = mutableListOf() + + val rooms: List + get() = _rooms + + val guests: List + get() = _guests + + fun host(guestToHost: List) { + for (guest in guestToHost) { + if (_guests.size == maxGuests) { + return + } + + if (_rooms.isEmpty()) { + _rooms.add(Room()) + } + if (!_rooms.last().host(guest)) { + _rooms.add(Room()) + _rooms.last().host(guest) + } + + _guests.add(guest) + } + } + } + + // act + val guests = listOf( + Guest("a"), + Guest("b"), + Guest("c"), + Guest("d"), + Guest("e"), + Guest("f") + ) + val house = House() + house.host(guests) + + // assert + assertSoftly { + house.rooms.size.shouldBeEqualTo(2) + house.guests.size.shouldBeEqualTo(6) + } + } +``` + +Now we get all assertions at once: + +*org.amshove.kluent.MultiAssertionError:* +*The following 2 assertions failed:* +*1) Expected <2>, actual <3>.* + *at org.amshove.kluent.tests.assertions.softly.AssertSoftly.houseTest(AssertSoftly.kt:147)* +*2) Expected <6>, actual <5>.* + *at org.amshove.kluent.tests.assertions.softly.AssertSoftly.houseTest(AssertSoftly.kt:148)* + +If you like, you can use a bit different syntax achieving the same result: +```kt + assertSoftly(house) { + rooms.size.shouldBeEqualTo(2) + guests.size.shouldBeEqualTo(6) + } +``` diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7c4388a9..558870da 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/js/src/main/kotlin/org/amshove/kluent/ErrorCollector.kt b/js/src/main/kotlin/org/amshove/kluent/ErrorCollector.kt new file mode 100644 index 00000000..7fb10b4a --- /dev/null +++ b/js/src/main/kotlin/org/amshove/kluent/ErrorCollector.kt @@ -0,0 +1,5 @@ +package org.amshove.kluent + +actual val errorCollector: ErrorCollector = JsErrorCollector + +object JsErrorCollector : BasicErrorCollector() \ No newline at end of file diff --git a/js/src/main/kotlin/org/amshove/kluent/StackTraces.kt b/js/src/main/kotlin/org/amshove/kluent/StackTraces.kt new file mode 100644 index 00000000..bfdafd49 --- /dev/null +++ b/js/src/main/kotlin/org/amshove/kluent/StackTraces.kt @@ -0,0 +1,3 @@ +package org.amshove.kluent + +actual val stacktraces: StackTraces = BasicStackTraces diff --git a/js/src/main/kotlin/org/amshove/kluent/internal/checkResultIsFailure.kt b/js/src/main/kotlin/org/amshove/kluent/internal/checkResultIsFailure.kt new file mode 100644 index 00000000..320806ef --- /dev/null +++ b/js/src/main/kotlin/org/amshove/kluent/internal/checkResultIsFailure.kt @@ -0,0 +1,19 @@ +package org.amshove.kluent.internal + +import kotlin.reflect.KClass + +@PublishedApi +internal actual fun checkResultIsFailure(exceptionClass: KClass, message: String?, blockResult: Result): T { + blockResult.fold( + onSuccess = { + fail(messagePrefix(message) + "Expected an exception of $exceptionClass to be thrown, but was completed successfully.") + }, + onFailure = { e -> + if (exceptionClass.isInstance(e)) { + @Suppress("UNCHECKED_CAST") + return e as T + } + fail(messagePrefix(message) + "Expected an exception of $exceptionClass to be thrown, but was $e") + } + ) +} \ No newline at end of file diff --git a/js/src/test/kotlin/TestsRun.kt b/js/src/test/kotlin/TestsRun.kt index 065a39de..45c27a90 100644 --- a/js/src/test/kotlin/TestsRun.kt +++ b/js/src/test/kotlin/TestsRun.kt @@ -1,3 +1,4 @@ +import org.amshove.kluent.* import kotlin.test.* class TestsRun { diff --git a/jvm/src/main/kotlin/org/amshove/kluent/Equivalency.kt b/jvm/src/main/kotlin/org/amshove/kluent/Equivalency.kt index c2da203e..b1811b14 100644 --- a/jvm/src/main/kotlin/org/amshove/kluent/Equivalency.kt +++ b/jvm/src/main/kotlin/org/amshove/kluent/Equivalency.kt @@ -1,11 +1,11 @@ package org.amshove.kluent +import org.amshove.kluent.internal.fail import java.lang.reflect.InvocationTargetException import java.util.* import kotlin.reflect.KProperty1 import kotlin.reflect.KVisibility import kotlin.reflect.full.declaredMemberProperties -import kotlin.test.fail @ExperimentalStdlibApi fun T.shouldBeEquivalentTo(expected: T, config: ((EquivalencyAssertionOptions) -> EquivalencyAssertionOptions)? = null): T = this.apply { assertEquivalency(false, expected, this, config) } diff --git a/jvm/src/main/kotlin/org/amshove/kluent/ErrorCollector.kt b/jvm/src/main/kotlin/org/amshove/kluent/ErrorCollector.kt new file mode 100644 index 00000000..f349d135 --- /dev/null +++ b/jvm/src/main/kotlin/org/amshove/kluent/ErrorCollector.kt @@ -0,0 +1,34 @@ +@file:JvmName("jvmerrorcollector") + +package org.amshove.kluent + +actual val errorCollector: ErrorCollector = ThreadLocalErrorCollector + +object ThreadLocalErrorCollector : ErrorCollector { + + private val failures = object : ThreadLocal>() { + override fun initialValue(): MutableList = mutableListOf() + } + + private val collectionMode = object : ThreadLocal() { + override fun initialValue() = ErrorCollectionMode.Hard + } + + override fun setCollectionMode(mode: ErrorCollectionMode) = collectionMode.set(mode) + + override fun getCollectionMode(): ErrorCollectionMode = collectionMode.get() + + override fun errors(): List = failures.get().toList() + + /** + * Adds the given error to the current context. + */ + override fun pushError(t: Throwable) { + failures.get().add(t) + } + + /** + * Clears all errors from the current context. + */ + override fun clear() = failures.get().clear() +} \ No newline at end of file diff --git a/jvm/src/main/kotlin/org/amshove/kluent/StackTraces.kt b/jvm/src/main/kotlin/org/amshove/kluent/StackTraces.kt new file mode 100644 index 00000000..7bcc8e52 --- /dev/null +++ b/jvm/src/main/kotlin/org/amshove/kluent/StackTraces.kt @@ -0,0 +1,26 @@ +@file:JvmName("stacktracesjvm") + +package org.amshove.kluent + +actual val stacktraces: StackTraces = object : StackTraces { + + override fun throwableLocation(t: Throwable): String? { + return throwableLocation(t, 1).firstOrNull() + } + + override fun throwableLocation(t: Throwable, n: Int): List { + return (t.cause ?: t).stackTrace?.dropWhile { + it.className.startsWith("org.amshove.kluent") && !it.className.startsWith("org.amshove.kluent.test") + }?.take(n)?.map { it.toString() } ?: emptyList() + } + + override fun cleanStackTrace(throwable: T): T { + throwable.stackTrace = UserStackTraceConverter.getUserStacktrace(throwable.stackTrace) + return throwable + } + + override fun root(throwable: Throwable): Throwable { + val cause = throwable.cause + return if (cause == null) throwable else root(cause) + } +} diff --git a/jvm/src/main/kotlin/org/amshove/kluent/UserStackTraceConverter.kt b/jvm/src/main/kotlin/org/amshove/kluent/UserStackTraceConverter.kt new file mode 100644 index 00000000..31160cd4 --- /dev/null +++ b/jvm/src/main/kotlin/org/amshove/kluent/UserStackTraceConverter.kt @@ -0,0 +1,42 @@ +package org.amshove.kluent + +object UserStackTraceConverter { + + fun getUserStacktrace(kotestStacktraces: Array): Array { + return kotestStacktraces.dropUntilUserClass() + } + + /** + * Drops stacktraces until it finds a Kluent Stacktrace then drops stacktraces until it finds a non-Kluent stacktrace + * + * Sometimes, it's possible for the Stacktrace to contain classes that are not from Kluent, + * such as classes from sun.reflect or anything from Java. After clearing these classes, we'll be at Kluent + * stacktrace, which will contain exceptions from the Runners and some other classes + * After everything from Kluent we'll finally be at user classes, at which point the stacktrace is clean and is + * returned. + */ + private fun Array.dropUntilUserClass(): Array { + return toList().dropUntilFirstKluentClass().dropUntilFirstNonKluentClass().toTypedArray() + } + + private fun List.dropUntilFirstKluentClass(): List { + return dropWhile { + it.isNotKluentClass() + } + } + + private fun List.dropUntilFirstNonKluentClass(): List { + return dropWhile { + it.isKluentClass() + } + } + + private fun StackTraceElement.isKluentClass(): Boolean { + return className.startsWith("org.amshove.kluent") + } + + private fun StackTraceElement.isNotKluentClass(): Boolean { + return !isKluentClass() + } + +} \ No newline at end of file diff --git a/jvm/src/main/kotlin/org/amshove/kluent/internal/checkResultIsFailure.kt b/jvm/src/main/kotlin/org/amshove/kluent/internal/checkResultIsFailure.kt new file mode 100644 index 00000000..1b2dabeb --- /dev/null +++ b/jvm/src/main/kotlin/org/amshove/kluent/internal/checkResultIsFailure.kt @@ -0,0 +1,22 @@ +package org.amshove.kluent.internal + +import kotlin.reflect.KClass + +/** Asserts that a [blockResult] is a failure with the specific exception type being thrown. */ +@PublishedApi +internal actual fun checkResultIsFailure(exceptionClass: KClass, message: String?, blockResult: Result): T { + blockResult.fold( + onSuccess = { + val msg = messagePrefix(message) + fail(msg + "Expected an exception of ${exceptionClass.java} to be thrown, but was completed successfully.") + }, + onFailure = { e -> + if (exceptionClass.java.isInstance(e)) { + @Suppress("UNCHECKED_CAST") + return e as T + } + + fail(messagePrefix(message) + "Expected an exception of ${exceptionClass.java} to be thrown, but was $e") + } + ) +} \ No newline at end of file diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeGreaterOrEqualToShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeGreaterOrEqualToShould.kt index 9105d8d3..a634551e 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeGreaterOrEqualToShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeGreaterOrEqualToShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.assertions.bigdecimal +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeGreaterOrEqualTo import kotlin.test.Test import java.math.BigDecimal -import kotlin.test.assertFails class BigDecimalShouldBeGreaterOrEqualToShould { @Test diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeGreaterThanShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeGreaterThanShould.kt index 527202b0..4f5c9188 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeGreaterThanShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeGreaterThanShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.assertions.bigdecimal +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeGreaterThan import org.junit.Test import java.math.BigDecimal -import kotlin.test.assertFails class BigDecimalShouldBeGreaterThanShould { @Test diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeInRangeShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeInRangeShould.kt index f5253667..2bfdfc97 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeInRangeShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeInRangeShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.assertions.bigdecimal +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeInRange import java.math.BigDecimal import kotlin.test.Test -import kotlin.test.assertFails class BigDecimalShouldBeInRangeShould { @Test diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeLessOrEqualToShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeLessOrEqualToShould.kt index df005811..11155a46 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeLessOrEqualToShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeLessOrEqualToShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.assertions.bigdecimal +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeLessOrEqualTo import java.math.BigDecimal import kotlin.test.Test -import kotlin.test.assertFails class BigDecimalShouldBeLessOrEqualToShould { @Test diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeLessThanShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeLessThanShould.kt index abed3826..6266e774 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeLessThanShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeLessThanShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.assertions.bigdecimal +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeLessThan import java.math.BigDecimal import kotlin.test.Test -import kotlin.test.assertFails class BigDecimalShouldBeLessThanShould { @Test diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeNegativeShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeNegativeShould.kt index 22d146d5..aeeed404 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeNegativeShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBeNegativeShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.assertions.bigdecimal +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeNegative import kotlin.test.Test import java.math.BigDecimal -import kotlin.test.assertFails class BigDecimalShouldBeNegativeShould { @Test diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBePositiveShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBePositiveShould.kt index eba3a4ca..351d4e7d 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBePositiveShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldBePositiveShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.assertions.bigdecimal +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBePositive import kotlin.test.Test import java.math.BigDecimal -import kotlin.test.assertFails class BigDecimalShouldBePositiveShould { @Test diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldEqualToShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldEqualToShould.kt index 00dad72e..291c331e 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldEqualToShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldEqualToShould.kt @@ -1,10 +1,10 @@ package org.amshove.kluent.tests.assertions.bigdecimal +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeEqualTo import java.math.BigDecimal import java.math.BigInteger import kotlin.test.Test -import kotlin.test.assertFails class BigDecimalShouldEqualToShould { diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotBeGreaterOrEqualTo.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotBeGreaterOrEqualTo.kt index 9d5658dd..f509b918 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotBeGreaterOrEqualTo.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotBeGreaterOrEqualTo.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.assertions.bigdecimal +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldNotBeGreaterOrEqualTo import java.math.BigDecimal import kotlin.test.Test -import kotlin.test.assertFails class BigDecimalShouldNotBeGreaterOrEqualTo { @Test diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotBeGreaterThanShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotBeGreaterThanShould.kt index d6209fb7..0da4cae9 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotBeGreaterThanShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotBeGreaterThanShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.assertions.bigdecimal +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldNotBeGreaterThan import org.junit.Test import java.math.BigDecimal -import kotlin.test.assertFails class BigDecimalShouldNotBeGreaterThanShould { @Test diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotBeInRangeShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotBeInRangeShould.kt index 534627ea..f272293f 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotBeInRangeShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotBeInRangeShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.assertions.bigdecimal +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldNotBeInRange import java.math.BigDecimal import kotlin.test.Test -import kotlin.test.assertFails class BigDecimalShouldNotBeInRangeShould { @Test diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotBeLessOrEqualToShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotBeLessOrEqualToShould.kt index 40f18bd6..87778388 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotBeLessOrEqualToShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotBeLessOrEqualToShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.assertions.bigdecimal +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldNotBeLessOrEqualTo import java.math.BigDecimal import kotlin.test.Test -import kotlin.test.assertFails class BigDecimalShouldNotBeLessOrEqualToShould { @Test diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotBeLessThanShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotBeLessThanShould.kt index 1c87ee4a..8e13ca79 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotBeLessThanShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotBeLessThanShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.assertions.bigdecimal +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldNotBeLessThan import org.junit.Test import java.math.BigDecimal -import kotlin.test.assertFails class BigDecimalShouldNotBeLessThanShould { @Test diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotEqualToShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotEqualToShould.kt index 72b64477..1d60939b 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotEqualToShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/bigdecimal/BigDecimalShouldNotEqualToShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.assertions.bigdecimal +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldNotBeEqualTo import org.junit.Test import java.math.BigDecimal -import kotlin.test.assertFails class BigDecimalShouldNotEqualToShould { diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/file/ShouldBeDirShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/file/ShouldBeDirShould.kt index 39f88d9b..bf99f573 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/file/ShouldBeDirShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/file/ShouldBeDirShould.kt @@ -1,10 +1,10 @@ package org.amshove.kluent.tests.assertions.file +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeDir import org.junit.Before import org.junit.Test import java.io.File -import kotlin.test.assertFails class ShouldBeDirShould { lateinit var dir: File diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/file/ShouldExistShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/file/ShouldExistShould.kt index 5a5bffa2..e7bbb8fe 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/file/ShouldExistShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/file/ShouldExistShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.assertions.file +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldExist import org.junit.Test import java.io.File -import kotlin.test.assertFails class ShouldExistShould { private val file = File("test") diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/file/ShouldHaveExtensionShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/file/ShouldHaveExtensionShould.kt index 3df6e845..a697be93 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/file/ShouldHaveExtensionShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/file/ShouldHaveExtensionShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.assertions.file +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldHaveExtension import java.io.File import kotlin.test.Test -import kotlin.test.assertFails class ShouldHaveExtensionShould { private val txtFile = File("test.txt") diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/file/ShouldHaveNameShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/file/ShouldHaveNameShould.kt index 2d1c2165..bb9d14e2 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/file/ShouldHaveNameShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/file/ShouldHaveNameShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.assertions.file +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldHaveName import java.io.File import kotlin.test.Test -import kotlin.test.assertFails class ShouldHaveNameShould { diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/softly/AssertSoftly.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/softly/AssertSoftly.kt new file mode 100644 index 00000000..d873e154 --- /dev/null +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/softly/AssertSoftly.kt @@ -0,0 +1,162 @@ +package org.amshove.kluent.tests.assertions.softly + +import org.amshove.kluent.* +import kotlin.test.Test + +class AssertSoftly { + @Test + fun failShouldAssertSoftly() { + // arrange + val a = "ab1" + + // act + try { + assertSoftly(a) { + shouldNotBeNull() + shouldContain("2") + length.shouldBeGreaterOrEqualTo(4) + } + } catch (e: Throwable) { + e.message!!.replace("\\s+|\\t|\\n".toRegex(), " ").trim().shouldBeEqualTo(""" + The following 2 assertions failed: + 1) Expected the CharSequence ab1 to contain 2 + at org.amshove.kluent.tests.assertions.softly.AssertSoftly.failShouldAssertSoftly(AssertSoftly.kt:16) + 2) Expected 3 to be greater or equal to 4 + at org.amshove.kluent.tests.assertions.softly.AssertSoftly.failShouldAssertSoftly(AssertSoftly.kt:17)""".replace("\\s+|\\t|\\n".toRegex(), " ").trim()) + } + } + + @Test + fun passShouldAssertSoftly() { + // arrange + val a = "ab1" + + // act + assertSoftly(a) { + shouldNotBeNull() + shouldContain("1") + length.shouldBeGreaterOrEqualTo(3) + } + } + + @Test + fun verifyAssertErrorForNonSoftlyAssertions() { + // arrange + val a = "ab1" + + // act + try { + with(a) { + shouldNotBeNull() + shouldContain("2") + length.shouldBeGreaterOrEqualTo(4) + } + } catch (e: Throwable) { + e.message!!.replace("\\s+|\\t|\\n".toRegex(), " ").trim().shouldBeEqualTo(""" + The following assertion failed: + Expected the CharSequence ab1 to contain 2 + at org.amshove.kluent.tests.assertions.softly.AssertSoftly.verifyAssertErrorForNonSoftlyAssertions(AssertSoftly.kt:51)""" + .replace("\\s+|\\t|\\n".toRegex(), " ").trim()) + } + } + + @Test + fun failShouldAssertSoftlyForSeveralObjects() { + // arrange + val a = "ab1" + val b = "ab2" + + // act + try { + assertSoftly { + a.shouldNotBeNull() + b.shouldContain("2") + a.length.shouldBeGreaterOrEqualTo(4) + } + } catch (e: Throwable) { + e.message!!.replace("\\s+|\\t|\\n".toRegex(), " ").trim().shouldBeEqualTo(""" + The following assertion failed: + Expected 3 to be greater or equal to 4 + at org.amshove.kluent.tests.assertions.softly.AssertSoftly.failShouldAssertSoftlyForSeveralObjects(AssertSoftly.kt:74)""" + .replace("\\s+|\\t|\\n".toRegex(), " ").trim()) + } + } + + @Test + fun houseTest() { + // arrange + data class Guest(val name: String) + class Room(val maxGuests: Int = 2) { + private var _guests: MutableList = mutableListOf() + + val guests: List + get() = _guests + + fun host(guestToHost: Guest): Boolean { + if (_guests.size < maxGuests) { + _guests.add(guestToHost) + } else { + return false + } + return true + } + } + class House(val maxGuests: Int = 5) { + private var _rooms: MutableList = mutableListOf() + private var _guests: MutableList = mutableListOf() + + val rooms: List + get() = _rooms + + val guests: List + get() = _guests + + fun host(guestToHost: List) { + for (guest in guestToHost) { + if (_guests.size == maxGuests) { + return + } + + if (_rooms.isEmpty()) { + _rooms.add(Room()) + } + if (!_rooms.last().host(guest)) { + _rooms.add(Room()) + _rooms.last().host(guest) + } + + _guests.add(guest) + } + } + } + + // act + val guests = listOf( + Guest("a"), + Guest("b"), + Guest("c"), + Guest("d"), + Guest("e"), + Guest("f") + ) + val house = House() + house.host(guests) + + try { + // assert + assertSoftly { + house.rooms.size.shouldBeEqualTo(2) + house.guests.size.shouldBeEqualTo(6) + } + } catch (e: Throwable) { + e.message!!.replace("\\s+|\\t|\\n".toRegex(), " ").trim().shouldBeEqualTo(""" + The following 2 assertions failed: + 1) Expected <2>, actual <3>. + at org.amshove.kluent.tests.assertions.softly.AssertSoftly.houseTest(AssertSoftly.kt:148) + 2) Expected <6>, actual <5>. + at org.amshove.kluent.tests.assertions.softly.AssertSoftly.houseTest(AssertSoftly.kt:149) + """.replace("\\s+|\\t|\\n".toRegex(), " ").trim()) + } + } + +} \ No newline at end of file diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/instant/ShouldBeAfterShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/instant/ShouldBeAfterShould.kt index 99e72f73..08b4ffc2 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/instant/ShouldBeAfterShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/instant/ShouldBeAfterShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.assertions.time.instant +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeAfter import java.time.Instant import kotlin.test.Test -import kotlin.test.assertFails class ShouldBeAfterShould { @Test diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localdate/ShouldBeAfterShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localdate/ShouldBeAfterShould.kt index f6f67c6f..042cdfdc 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localdate/ShouldBeAfterShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localdate/ShouldBeAfterShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.assertions.time.localdate +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeAfter import java.time.LocalDate import kotlin.test.Test -import kotlin.test.assertFails class ShouldBeAfterShould { @Test diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localdate/ShouldBeAtLeastXDaysAfterShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localdate/ShouldBeAtLeastXDaysAfterShould.kt index 44e93d99..f4a4b4ec 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localdate/ShouldBeAtLeastXDaysAfterShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localdate/ShouldBeAtLeastXDaysAfterShould.kt @@ -2,10 +2,10 @@ package org.amshove.kluent.tests.assertions.time.localdate import org.amshove.kluent.after import org.amshove.kluent.days +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeAtLeast import java.time.LocalDate import kotlin.test.Test -import kotlin.test.assertFails class ShouldBeAtLeastXDaysAfterShould { val orderDate = LocalDate.of(2017, 6, 5) diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localdate/ShouldBeInMonthShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localdate/ShouldBeInMonthShould.kt index 5e66fbd8..77f06525 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localdate/ShouldBeInMonthShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localdate/ShouldBeInMonthShould.kt @@ -1,10 +1,10 @@ package org.amshove.kluent.tests.assertions.time.localdate +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldBeIn import java.time.LocalDate import java.time.Month import kotlin.test.Test -import kotlin.test.assertFails class ShouldBeInMonthShould { diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localtime/ShouldBeAtLeastXMinutesAfterShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localtime/ShouldBeAtLeastXMinutesAfterShould.kt index bf255d40..749e7d29 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localtime/ShouldBeAtLeastXMinutesAfterShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localtime/ShouldBeAtLeastXMinutesAfterShould.kt @@ -1,11 +1,11 @@ package org.amshove.kluent.tests.assertions.time.localtime import org.amshove.kluent.after +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.minutes import org.amshove.kluent.shouldBeAtLeast import java.time.LocalTime import kotlin.test.Test -import kotlin.test.assertFails class ShouldBeAtLeastXMinutesAfterShould { val loginTime = LocalTime.of(10, 59) diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localtime/ShouldBeAtMostXMinutesAfterShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localtime/ShouldBeAtMostXMinutesAfterShould.kt index a7483df1..8c4c8ed7 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localtime/ShouldBeAtMostXMinutesAfterShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localtime/ShouldBeAtMostXMinutesAfterShould.kt @@ -1,11 +1,11 @@ package org.amshove.kluent.tests.assertions.time.localtime import org.amshove.kluent.after +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.minutes import org.amshove.kluent.shouldBeAtMost import java.time.LocalTime import kotlin.test.Test -import kotlin.test.assertFails class ShouldBeAtMostXMinutesAfterShould { val loginTime = LocalTime.of(10, 10) diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localtime/ShouldBeXMinutesAfterShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localtime/ShouldBeXMinutesAfterShould.kt index 9369ad86..a9bbd236 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localtime/ShouldBeXMinutesAfterShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/time/localtime/ShouldBeXMinutesAfterShould.kt @@ -1,11 +1,11 @@ package org.amshove.kluent.tests.assertions.time.localtime import org.amshove.kluent.after +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.minutes import org.amshove.kluent.shouldBe import java.time.LocalTime import kotlin.test.Test -import kotlin.test.assertFails class ShouldBeXMinutesAfterShould { val loginTime = LocalTime.of(10, 59) diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/collections/BackticksShould.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/collections/BackticksShould.kt index 553d18f9..2b79c875 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/collections/BackticksShould.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/collections/BackticksShould.kt @@ -1,6 +1,6 @@ package org.amshove.kluent.tests.collections -import org.amshove.kluent.Person +import org.amshove.kluent.tests.Person import org.amshove.kluent.`should match at least one of` import kotlin.test.Test diff --git a/jvm/src/test/kotlin/org/amshove/kluent/tests/equivalency/ShouldBeEquivalentTo.kt b/jvm/src/test/kotlin/org/amshove/kluent/tests/equivalency/ShouldBeEquivalentTo.kt index 747871f3..6550f273 100644 --- a/jvm/src/test/kotlin/org/amshove/kluent/tests/equivalency/ShouldBeEquivalentTo.kt +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/equivalency/ShouldBeEquivalentTo.kt @@ -1,10 +1,10 @@ package org.amshove.kluent.tests.equivalency import org.amshove.kluent.* +import org.amshove.kluent.internal.assertFailsWith import org.junit.ComparisonFailure import org.junit.Test import java.time.LocalDate -import kotlin.test.assertFailsWith @ExperimentalStdlibApi class ShouldBeEquivalentTo { diff --git a/native/src/main/kotlin/org/amshove/kluent/ErrorCollector.kt b/native/src/main/kotlin/org/amshove/kluent/ErrorCollector.kt new file mode 100644 index 00000000..f571c76f --- /dev/null +++ b/native/src/main/kotlin/org/amshove/kluent/ErrorCollector.kt @@ -0,0 +1,5 @@ +package org.amshove.kluent + +actual val errorCollector: ErrorCollector = NativeErrorCollector + +object NativeErrorCollector : BasicErrorCollector() \ No newline at end of file diff --git a/native/src/main/kotlin/org/amshove/kluent/StackTraces.kt b/native/src/main/kotlin/org/amshove/kluent/StackTraces.kt new file mode 100644 index 00000000..219ac460 --- /dev/null +++ b/native/src/main/kotlin/org/amshove/kluent/StackTraces.kt @@ -0,0 +1,3 @@ +package org.amshove.kluent + +actual val stacktraces: StackTraces = BasicStackTraces \ No newline at end of file diff --git a/native/src/main/kotlin/org/amshove/kluent/internal/checkResultIsFailure.kt b/native/src/main/kotlin/org/amshove/kluent/internal/checkResultIsFailure.kt new file mode 100644 index 00000000..320806ef --- /dev/null +++ b/native/src/main/kotlin/org/amshove/kluent/internal/checkResultIsFailure.kt @@ -0,0 +1,19 @@ +package org.amshove.kluent.internal + +import kotlin.reflect.KClass + +@PublishedApi +internal actual fun checkResultIsFailure(exceptionClass: KClass, message: String?, blockResult: Result): T { + blockResult.fold( + onSuccess = { + fail(messagePrefix(message) + "Expected an exception of $exceptionClass to be thrown, but was completed successfully.") + }, + onFailure = { e -> + if (exceptionClass.isInstance(e)) { + @Suppress("UNCHECKED_CAST") + return e as T + } + fail(messagePrefix(message) + "Expected an exception of $exceptionClass to be thrown, but was $e") + } + ) +} \ No newline at end of file