From 36f8438a2b8eaaa71634cd8404f43f7d4cfb7106 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Tue, 17 Nov 2020 14:27:06 +0100 Subject: [PATCH 1/5] #178: added support for assertSoftly --- .../org/amshove/kluent/AssertionErrors.kt | 47 ++++++++ .../main/kotlin/org/amshove/kluent/Basic.kt | 1 - .../kotlin/org/amshove/kluent/Collections.kt | 1 - .../org/amshove/kluent/ErrorCollector.kt | 104 ++++++++++++++++++ .../main/kotlin/org/amshove/kluent/Softly.kt | 20 ++++ .../kotlin/org/amshove/kluent/StackTraces.kt | 37 +++++++ .../org/amshove/kluent/internal/Assertions.kt | 34 ++++-- .../org/amshove/kluent/internal/Utility.kt | 4 + .../org/amshove/kluent/InternalAssertions.kt | 10 +- .../amshove/kluent/{ => tests}/DataClasses.kt | 2 +- .../{ => tests}/basic/ShouldBeDigitShould.kt | 2 +- .../{ => tests}/basic/ShouldBeFalseShould.kt | 9 +- .../{ => tests}/basic/ShouldBeNullShould.kt | 2 +- .../{ => tests}/basic/ShouldBeShould.kt | 4 +- .../{ => tests}/basic/ShouldBeTrueShould.kt | 10 +- .../{ => tests}/basic/ShouldEqualShould.kt | 4 +- .../basic/ShouldNotBeDigitShould.kt | 2 +- .../basic/ShouldNotBeFalseShould.kt | 2 +- .../basic/ShouldNotBeNullShould.kt | 2 +- .../{ => tests}/basic/ShouldNotBeShould.kt | 4 +- .../basic/ShouldNotBeTrueShould.kt | 2 +- .../{ => tests}/basic/ShouldNotEqualShould.kt | 4 +- .../kluent/{ => tests}/basic/ShouldShould.kt | 4 +- .../charsequence/ShouldBeBlankShould.kt | 2 +- .../charsequence/ShouldBeEmptyShould.kt | 2 +- .../charsequence/ShouldBeNullOrBlankShould.kt | 2 +- .../charsequence/ShouldBeNullOrEmptyShould.kt | 2 +- .../charsequence/ShouldContainAllShould.kt | 2 +- .../charsequence/ShouldContainNoneShould.kt | 2 +- .../charsequence/ShouldContainShould.kt | 2 +- .../charsequence/ShouldContainSomeShould.kt | 2 +- .../charsequence/ShouldEndWithShould.kt | 2 +- .../charsequence/ShouldMatchShould.kt | 2 +- .../charsequence/ShouldNotBeBlankShould.kt | 2 +- .../charsequence/ShouldNotBeEmptyShould.kt | 2 +- .../ShouldNotBeNullOrBlankShould.kt | 2 +- .../ShouldNotBeNullOrEmptyShould.kt | 2 +- .../charsequence/ShouldNotContainAllShould.kt | 2 +- .../charsequence/ShouldNotContainShould.kt | 2 +- .../charsequence/ShouldNotEndWithShould.kt | 2 +- .../charsequence/ShouldNotMatchShould.kt | 2 +- .../charsequence/ShouldNotStartWithShould.kt | 2 +- .../charsequence/ShouldStartWithShould.kt | 2 +- .../collections/ShouldBeEmptyShould.kt | 2 +- .../collections/ShouldBeInRangeShould.kt | 2 +- .../collections/ShouldBeInShould.kt | 4 +- .../ShouldBeSortedAccordingToShould.kt | 4 +- .../collections/ShouldContainAllShould.kt | 2 +- .../collections/ShouldContainAnyShould.kt | 2 +- .../collections/ShouldContainFalseShould.kt | 2 +- .../collections/ShouldContainNoneShould.kt | 2 +- .../collections/ShouldContainSameShould.kt | 2 +- .../collections/ShouldContainShould.kt | 4 +- .../ShouldContainSingleItemShould.kt | 2 +- .../collections/ShouldContainSomeShould.kt | 2 +- .../collections/ShouldContainTrueShould.kt | 2 +- .../collections/ShouldEqualShould.kt | 4 +- .../collections/ShouldEqualUnorderedShould.kt | 6 +- .../collections/ShouldHaveKeyShould.kt | 4 +- .../collections/ShouldHaveSingleItemShould.kt | 2 +- .../collections/ShouldHaveSizeShould.kt | 2 +- .../collections/ShouldHaveValueShould.kt | 4 +- .../collections/ShouldMatchPredicateShould.kt | 4 +- .../collections/ShouldNotBeEmptyShould.kt | 2 +- .../collections/ShouldNotBeInRangeShould.kt | 2 +- .../collections/ShouldNotBeInShould.kt | 4 +- .../collections/ShouldNotContainAnyShould.kt | 2 +- .../collections/ShouldNotContainShould.kt | 4 +- .../collections/ShouldNotEqualShould.kt | 5 +- .../ShouldNotEqualUnorderedShould.kt | 4 +- .../collections/ShouldNotHaveKeyShould.kt | 4 +- .../collections/ShouldNotHaveValueShould.kt | 4 +- .../concepts/ChainingAssertionsShould.kt | 2 +- .../ShouldBeGreaterOrEqualToShould.kt | 2 +- .../numerical/ShouldBeGreaterThanShould.kt | 2 +- .../numerical/ShouldBeInRangeShould.kt | 2 +- .../numerical/ShouldBeLessOrEqualToShould.kt | 2 +- .../numerical/ShouldBeLessThanShould.kt | 2 +- .../numerical/ShouldBeNearShould.kt | 2 +- .../numerical/ShouldBeNegativeShould.kt | 2 +- .../numerical/ShouldBePositiveShould.kt | 2 +- .../ShouldNotBeGreaterOrEqualToShould.kt | 2 +- .../numerical/ShouldNotBeGreaterThanShould.kt | 2 +- .../numerical/ShouldNotBeInRangeShould.kt | 2 +- .../ShouldNotBeLessOrEqualToShould.kt | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../org/amshove/kluent/ErrorCollector.kt | 5 + .../kotlin/org/amshove/kluent/StackTraces.kt | 3 + .../kotlin/org/amshove/kluent/Equivalency.kt | 2 +- .../amshove/kluent/UserStackTraceConverter.kt | 42 +++++++ .../org/amshove/kluent/errorCollector.kt | 50 +++++++++ .../kotlin/org/amshove/kluent/stacktraces.kt | 26 +++++ .../tests/assertions/softly/AssertSoftly.kt | 85 ++++++++++++++ .../tests/collections/BackticksShould.kt | 2 +- .../org/amshove/kluent/ErrorCollector.kt | 5 + .../kotlin/org/amshove/kluent/StackTraces.kt | 3 + 96 files changed, 577 insertions(+), 114 deletions(-) create mode 100644 common/src/main/kotlin/org/amshove/kluent/AssertionErrors.kt create mode 100644 common/src/main/kotlin/org/amshove/kluent/ErrorCollector.kt create mode 100644 common/src/main/kotlin/org/amshove/kluent/Softly.kt create mode 100644 common/src/main/kotlin/org/amshove/kluent/StackTraces.kt rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/DataClasses.kt (64%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/basic/ShouldBeDigitShould.kt (96%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/basic/ShouldBeFalseShould.kt (65%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/basic/ShouldBeNullShould.kt (93%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/basic/ShouldBeShould.kt (87%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/basic/ShouldBeTrueShould.kt (61%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/basic/ShouldEqualShould.kt (93%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/basic/ShouldNotBeDigitShould.kt (96%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/basic/ShouldNotBeFalseShould.kt (88%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/basic/ShouldNotBeNullShould.kt (94%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/basic/ShouldNotBeShould.kt (87%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/basic/ShouldNotBeTrueShould.kt (88%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/basic/ShouldNotEqualShould.kt (93%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/basic/ShouldShould.kt (96%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/charsequence/ShouldBeBlankShould.kt (87%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/charsequence/ShouldBeEmptyShould.kt (87%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/charsequence/ShouldBeNullOrBlankShould.kt (91%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/charsequence/ShouldBeNullOrEmptyShould.kt (91%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/charsequence/ShouldContainAllShould.kt (92%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/charsequence/ShouldContainNoneShould.kt (94%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/charsequence/ShouldContainShould.kt (92%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/charsequence/ShouldContainSomeShould.kt (94%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/charsequence/ShouldEndWithShould.kt (89%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/charsequence/ShouldMatchShould.kt (93%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/charsequence/ShouldNotBeBlankShould.kt (88%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/charsequence/ShouldNotBeEmptyShould.kt (88%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/charsequence/ShouldNotBeNullOrBlankShould.kt (94%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/charsequence/ShouldNotBeNullOrEmptyShould.kt (94%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/charsequence/ShouldNotContainAllShould.kt (92%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/charsequence/ShouldNotContainShould.kt (93%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/charsequence/ShouldNotEndWithShould.kt (89%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/charsequence/ShouldNotMatchShould.kt (93%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/charsequence/ShouldNotStartWithShould.kt (90%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/charsequence/ShouldStartWithShould.kt (89%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldBeEmptyShould.kt (98%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldBeInRangeShould.kt (92%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldBeInShould.kt (97%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldBeSortedAccordingToShould.kt (98%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldContainAllShould.kt (99%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldContainAnyShould.kt (98%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldContainFalseShould.kt (91%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldContainNoneShould.kt (99%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldContainSameShould.kt (99%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldContainShould.kt (98%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldContainSingleItemShould.kt (97%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldContainSomeShould.kt (99%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldContainTrueShould.kt (91%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldEqualShould.kt (98%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldEqualUnorderedShould.kt (78%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldHaveKeyShould.kt (92%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldHaveSingleItemShould.kt (98%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldHaveSizeShould.kt (96%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldHaveValueShould.kt (92%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldMatchPredicateShould.kt (96%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldNotBeEmptyShould.kt (98%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldNotBeInRangeShould.kt (92%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldNotBeInShould.kt (97%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldNotContainAnyShould.kt (99%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldNotContainShould.kt (98%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldNotEqualShould.kt (97%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldNotEqualUnorderedShould.kt (89%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldNotHaveKeyShould.kt (92%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/collections/ShouldNotHaveValueShould.kt (92%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/concepts/ChainingAssertionsShould.kt (96%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/numerical/ShouldBeGreaterOrEqualToShould.kt (96%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/numerical/ShouldBeGreaterThanShould.kt (96%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/numerical/ShouldBeInRangeShould.kt (98%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/numerical/ShouldBeLessOrEqualToShould.kt (96%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/numerical/ShouldBeLessThanShould.kt (94%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/numerical/ShouldBeNearShould.kt (98%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/numerical/ShouldBeNegativeShould.kt (96%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/numerical/ShouldBePositiveShould.kt (96%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/numerical/ShouldNotBeGreaterOrEqualToShould.kt (96%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/numerical/ShouldNotBeGreaterThanShould.kt (96%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/numerical/ShouldNotBeInRangeShould.kt (98%) rename common/src/test/kotlin/org/amshove/kluent/{ => tests}/numerical/ShouldNotBeLessOrEqualToShould.kt (96%) create mode 100644 js/src/main/kotlin/org/amshove/kluent/ErrorCollector.kt create mode 100644 js/src/main/kotlin/org/amshove/kluent/StackTraces.kt create mode 100644 jvm/src/main/kotlin/org/amshove/kluent/UserStackTraceConverter.kt create mode 100644 jvm/src/main/kotlin/org/amshove/kluent/errorCollector.kt create mode 100644 jvm/src/main/kotlin/org/amshove/kluent/stacktraces.kt create mode 100644 jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/softly/AssertSoftly.kt create mode 100644 native/src/main/kotlin/org/amshove/kluent/ErrorCollector.kt create mode 100644 native/src/main/kotlin/org/amshove/kluent/StackTraces.kt 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..29c342e7 100644 --- a/common/src/main/kotlin/org/amshove/kluent/Basic.kt +++ b/common/src/main/kotlin/org/amshove/kluent/Basic.kt @@ -5,7 +5,6 @@ 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/Collections.kt b/common/src/main/kotlin/org/amshove/kluent/Collections.kt index 24a3f3b1..5201476c 100644 --- a/common/src/main/kotlin/org/amshove/kluent/Collections.kt +++ b/common/src/main/kotlin/org/amshove/kluent/Collections.kt @@ -3,7 +3,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..6b5c5fd6 --- /dev/null +++ b/common/src/main/kotlin/org/amshove/kluent/ErrorCollector.kt @@ -0,0 +1,104 @@ +package org.amshove.kluent + +expect val errorCollector: ErrorCollector + +enum class ErrorCollectionMode { + Soft, Hard +} + +typealias Clue = () -> String + +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() + + fun pushClue(clue: Clue) + + fun popClue() + + /** + * Returns the current clue context. + * That is all the clues nested to this point. + */ + fun clueContext(): List +} + +open class BasicErrorCollector : ErrorCollector { + + private val failures = mutableListOf() + private var mode = ErrorCollectionMode.Hard + private val clues = mutableListOf() + + override fun getCollectionMode(): ErrorCollectionMode = mode + + override fun setCollectionMode(mode: ErrorCollectionMode) { + this.mode = mode + } + + override fun pushClue(clue: Clue) { + clues.add(0, clue) + } + + override fun popClue() { + clues.removeAt(0) + } + + override fun clueContext(): List = clues.toList() + + override fun pushError(t: Throwable) { + failures.add(t) + } + + override fun errors(): List = failures.toList() + + override fun clear() = failures.clear() +} + +fun clueContextAsString() = errorCollector.clueContext().let { + if (it.isEmpty()) "" else it.joinToString("\n", postfix = "\n") { f -> f.invoke() } +} + +/** + * 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/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..9eb4acc7 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,34 @@ package org.amshove.kluent.internal -import kotlin.test.assertFalse -import kotlin.test.assertTrue -import kotlin.test.fail +import org.amshove.kluent.* 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 +105,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(""" @@ -104,4 +123,3 @@ fun assertSame(expected: Any?, actual: Any?) { fun assertNotSame(expected: Any?, actual: Any?) { assertTrue("Expected <$expected>, actual <$actual> are the same instance.", actual !== expected) } - 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..c2a95fbb 100644 --- a/common/src/main/kotlin/org/amshove/kluent/internal/Utility.kt +++ b/common/src/main/kotlin/org/amshove/kluent/internal/Utility.kt @@ -7,3 +7,7 @@ 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) +} \ No newline at end of file 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 96% 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..fd340d92 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,4 +1,4 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic import org.amshove.kluent.shouldBeDigit import kotlin.test.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 65% 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..60a7a58b 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,7 +1,8 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic -import org.amshove.kluent.assertMessage import org.amshove.kluent.shouldBeFalse +import org.amshove.kluent.assertMessage +import org.amshove.kluent.assertMessageContain import kotlin.test.Test import kotlin.test.assertFails @@ -18,6 +19,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 93% 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..a89b5e63 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,4 +1,4 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic import org.amshove.kluent.shouldBeNull import org.amshove.kluent.shouldNotBeNull 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 87% 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..9f80013c 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,8 +1,8 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic import kotlin.test.Test -import org.amshove.kluent.Person import org.amshove.kluent.shouldBe +import org.amshove.kluent.tests.Person import kotlin.test.assertFails class ShouldBeShould { 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 61% 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..2195f82d 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,7 +1,9 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic -import org.amshove.kluent.assertMessage import org.amshove.kluent.shouldBeTrue +import org.amshove.kluent.assertMessage +import org.amshove.kluent.assertMessageContain +import org.amshove.kluent.shouldBeFalse import kotlin.test.Test import kotlin.test.assertFails @@ -18,6 +20,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 93% 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..355dcb6f 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,7 +1,7 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic -import org.amshove.kluent.Person import org.amshove.kluent.shouldBeEqualTo +import org.amshove.kluent.tests.Person import kotlin.test.Test import kotlin.test.assertFails 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 96% 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..0dc39c90 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,4 +1,4 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic import org.amshove.kluent.shouldNotBeDigit import kotlin.test.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 88% 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..015f3c76 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,4 +1,4 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic import org.amshove.kluent.shouldNotBeFalse import kotlin.test.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 94% 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..69e569ae 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,4 +1,4 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic import org.amshove.kluent.shouldNotBe import org.amshove.kluent.shouldNotBeNull 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 87% 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..8c5cb701 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,8 +1,8 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic import kotlin.test.Test -import org.amshove.kluent.Person import org.amshove.kluent.shouldNotBe +import org.amshove.kluent.tests.Person import kotlin.test.assertFails class ShouldNotBeShould { 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 88% 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..0236fe4e 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,4 +1,4 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic import org.amshove.kluent.shouldNotBeTrue import kotlin.test.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 93% 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..156128fb 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,8 +1,8 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic -import org.amshove.kluent.Person import org.amshove.kluent.shouldBeEqualTo import org.amshove.kluent.shouldNotBeEqualTo +import org.amshove.kluent.tests.Person import kotlin.test.Test import kotlin.test.assertFails 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 96% 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..44194de1 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,8 +1,8 @@ -package org.amshove.kluent.basic +package org.amshove.kluent.tests.basic import kotlin.test.Test -import org.amshove.kluent.Person import org.amshove.kluent.should +import org.amshove.kluent.tests.Person import kotlin.test.assertFails import kotlin.test.assertTrue 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 87% 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..854677cc 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,4 +1,4 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence import org.amshove.kluent.shouldBeBlank import kotlin.test.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 87% 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..76358cfb 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,4 +1,4 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence import org.amshove.kluent.shouldBeEmpty import kotlin.test.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 91% 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..0bdec919 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,4 +1,4 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence import org.amshove.kluent.shouldBeNullOrBlank import kotlin.test.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 91% 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..71920b21 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,4 +1,4 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence import org.amshove.kluent.shouldBeNullOrEmpty import kotlin.test.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 94% 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..142943de 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,4 +1,4 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence import org.amshove.kluent.shouldContainSome import kotlin.test.Test 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 89% 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..c0fabb33 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,4 +1,4 @@ -package org.amshove.kluent.charsequence +package org.amshove.kluent.tests.charsequence import org.amshove.kluent.shouldNotEndWith import kotlin.test.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 98% 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..163b94b3 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,4 +1,4 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections import org.amshove.kluent.shouldBeEmpty import kotlin.test.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 92% 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..167ae854 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,4 +1,4 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections import org.amshove.kluent.shouldBeInRange import kotlin.test.Test 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 97% 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..2ece9b2c 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,7 +1,7 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections import kotlin.test.Test -import org.amshove.kluent.Person +import org.amshove.kluent.tests.Person import org.amshove.kluent.shouldBeIn import kotlin.test.assertFails 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 98% 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..9266f109 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,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.shouldBeSortedAccordingTo import kotlin.random.Random import kotlin.test.Test 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 99% 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..15428d24 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,4 +1,4 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections import org.amshove.kluent.shouldContainAll import kotlin.test.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 98% 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..5627f47a 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,4 +1,4 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections import org.amshove.kluent.* 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 91% 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..6c3542dc 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,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/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 98% 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..041f4733 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,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.shouldContain import kotlin.test.Test import kotlin.test.assertFails 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 99% 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..3ba7a034 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,4 +1,4 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections import org.amshove.kluent.shouldContainSome import kotlin.test.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 92% 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..985ad67d 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,7 +1,7 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections import org.amshove.kluent.shouldHaveKey -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/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 98% 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..f89fc884 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,4 +1,4 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections import org.amshove.kluent.shouldNotBeEmpty import kotlin.test.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 92% 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..001d3b52 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,4 +1,4 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections import org.amshove.kluent.shouldNotBeInRange import kotlin.test.Test 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..ae46dce0 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,8 +1,7 @@ -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.shouldNotBeEqualTo -import org.amshove.kluent.shouldNotEqual import kotlin.test.Test import kotlin.test.assertFails 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 89% 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..24aeca6c 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,7 +1,7 @@ -package org.amshove.kluent.collections +package org.amshove.kluent.tests.collections -import org.amshove.kluent.Person import org.amshove.kluent.shouldNotEqualUnordered +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/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 92% 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..c0a72ac6 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,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.shouldNotHaveValue import kotlin.test.assertFails import kotlin.test.Test 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 96% 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..6da713b1 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,4 +1,4 @@ -package org.amshove.kluent.numerical +package org.amshove.kluent.tests.numerical import org.amshove.kluent.shouldBeGreaterThan import kotlin.test.assertFails 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 96% 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..9130cc4b 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,4 +1,4 @@ -package org.amshove.kluent.numerical +package org.amshove.kluent.tests.numerical import org.amshove.kluent.shouldBeLessOrEqualTo import kotlin.test.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 96% 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..43b66092 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,4 +1,4 @@ -package org.amshove.kluent.numerical +package org.amshove.kluent.tests.numerical import org.amshove.kluent.shouldNotBeGreaterOrEqualTo import kotlin.test.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/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/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/UserStackTraceConverter.kt b/jvm/src/main/kotlin/org/amshove/kluent/UserStackTraceConverter.kt new file mode 100644 index 00000000..564df2a3 --- /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 Kotest Stacktrace then drops stacktraces until it finds a non-Kotest stacktrace + * + * Sometimes, it's possible for the Stacktrace to contain classes that are not from Kotest, + * such as classes from sun.reflect or anything from Java. After clearing these classes, we'll be at Kotest + * stacktrace, which will contain exceptions from the Runners and some other classes + * After everything from Kotest we'll finally be at user classes, at which point the stacktrace is clean and is + * returned. + */ + private fun Array.dropUntilUserClass(): Array { + return toList().dropUntilFirstKotestClass().dropUntilFirstNonKotestClass().toTypedArray() + } + + private fun List.dropUntilFirstKotestClass(): List { + return dropWhile { + it.isNotKotestClass() + } + } + + private fun List.dropUntilFirstNonKotestClass(): List { + return dropWhile { + it.isKotestClass() + } + } + + private fun StackTraceElement.isKotestClass(): Boolean { + return className.startsWith("org.amshove.kluent") + } + + private fun StackTraceElement.isNotKotestClass(): Boolean { + return !isKotestClass() + } + +} \ No newline at end of file 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..93d88fde --- /dev/null +++ b/jvm/src/main/kotlin/org/amshove/kluent/errorCollector.kt @@ -0,0 +1,50 @@ +@file:JvmName("jvmerrorcollector") + +package org.amshove.kluent + +import java.util.* + +actual val errorCollector: ErrorCollector = ThreadLocalErrorCollector + +object ThreadLocalErrorCollector : ErrorCollector { + + private val clueContext = object : ThreadLocal>() { + override fun initialValue(): Stack = Stack() + } + + 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 pushClue(clue: Clue) { + clueContext.get().push(clue) + } + + override fun popClue() { + clueContext.get().pop() + } + + override fun clueContext(): List = clueContext.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..05567bf5 --- /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/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..f2d89cd6 --- /dev/null +++ b/jvm/src/test/kotlin/org/amshove/kluent/tests/assertions/softly/AssertSoftly.kt @@ -0,0 +1,85 @@ +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()) + } + } + +} \ No newline at end of file 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/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 From f218275e769f937231435c9f5f5fbdf268a4210f Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Sun, 22 Nov 2020 18:07:27 +0100 Subject: [PATCH 2/5] Small refactoring referencing "Kluent" instead of "Kotest" --- .../amshove/kluent/UserStackTraceConverter.kt | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/jvm/src/main/kotlin/org/amshove/kluent/UserStackTraceConverter.kt b/jvm/src/main/kotlin/org/amshove/kluent/UserStackTraceConverter.kt index 564df2a3..31160cd4 100644 --- a/jvm/src/main/kotlin/org/amshove/kluent/UserStackTraceConverter.kt +++ b/jvm/src/main/kotlin/org/amshove/kluent/UserStackTraceConverter.kt @@ -7,36 +7,36 @@ object UserStackTraceConverter { } /** - * Drops stacktraces until it finds a Kotest Stacktrace then drops stacktraces until it finds a non-Kotest stacktrace + * 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 Kotest, - * such as classes from sun.reflect or anything from Java. After clearing these classes, we'll be at Kotest + * 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 Kotest we'll finally be at user classes, at which point the stacktrace is clean and is + * 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().dropUntilFirstKotestClass().dropUntilFirstNonKotestClass().toTypedArray() + return toList().dropUntilFirstKluentClass().dropUntilFirstNonKluentClass().toTypedArray() } - private fun List.dropUntilFirstKotestClass(): List { + private fun List.dropUntilFirstKluentClass(): List { return dropWhile { - it.isNotKotestClass() + it.isNotKluentClass() } } - private fun List.dropUntilFirstNonKotestClass(): List { + private fun List.dropUntilFirstNonKluentClass(): List { return dropWhile { - it.isKotestClass() + it.isKluentClass() } } - private fun StackTraceElement.isKotestClass(): Boolean { + private fun StackTraceElement.isKluentClass(): Boolean { return className.startsWith("org.amshove.kluent") } - private fun StackTraceElement.isNotKotestClass(): Boolean { - return !isKotestClass() + private fun StackTraceElement.isNotKluentClass(): Boolean { + return !isKluentClass() } } \ No newline at end of file From 7806e86e3cd7408d885d803ac796ff47ece15582 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Sun, 22 Nov 2020 18:09:46 +0100 Subject: [PATCH 3/5] Removed clues as they are not currently used within Kluent --- .../org/amshove/kluent/ErrorCollector.kt | 27 ------------------- .../{errorCollector.kt => ErrorCollector.kt} | 16 ----------- 2 files changed, 43 deletions(-) rename jvm/src/main/kotlin/org/amshove/kluent/{errorCollector.kt => ErrorCollector.kt} (73%) diff --git a/common/src/main/kotlin/org/amshove/kluent/ErrorCollector.kt b/common/src/main/kotlin/org/amshove/kluent/ErrorCollector.kt index 6b5c5fd6..e23598c9 100644 --- a/common/src/main/kotlin/org/amshove/kluent/ErrorCollector.kt +++ b/common/src/main/kotlin/org/amshove/kluent/ErrorCollector.kt @@ -6,8 +6,6 @@ enum class ErrorCollectionMode { Soft, Hard } -typealias Clue = () -> String - interface ErrorCollector { fun getCollectionMode(): ErrorCollectionMode @@ -28,23 +26,12 @@ interface ErrorCollector { * Clears all errors from the current context. */ fun clear() - - fun pushClue(clue: Clue) - - fun popClue() - - /** - * Returns the current clue context. - * That is all the clues nested to this point. - */ - fun clueContext(): List } open class BasicErrorCollector : ErrorCollector { private val failures = mutableListOf() private var mode = ErrorCollectionMode.Hard - private val clues = mutableListOf() override fun getCollectionMode(): ErrorCollectionMode = mode @@ -52,16 +39,6 @@ open class BasicErrorCollector : ErrorCollector { this.mode = mode } - override fun pushClue(clue: Clue) { - clues.add(0, clue) - } - - override fun popClue() { - clues.removeAt(0) - } - - override fun clueContext(): List = clues.toList() - override fun pushError(t: Throwable) { failures.add(t) } @@ -71,10 +48,6 @@ open class BasicErrorCollector : ErrorCollector { override fun clear() = failures.clear() } -fun clueContextAsString() = errorCollector.clueContext().let { - if (it.isEmpty()) "" else it.joinToString("\n", postfix = "\n") { f -> f.invoke() } -} - /** * If we are in "soft assertion mode" will add this throwable to the * list of throwables for the current execution. Otherwise will diff --git a/jvm/src/main/kotlin/org/amshove/kluent/errorCollector.kt b/jvm/src/main/kotlin/org/amshove/kluent/ErrorCollector.kt similarity index 73% rename from jvm/src/main/kotlin/org/amshove/kluent/errorCollector.kt rename to jvm/src/main/kotlin/org/amshove/kluent/ErrorCollector.kt index 93d88fde..f349d135 100644 --- a/jvm/src/main/kotlin/org/amshove/kluent/errorCollector.kt +++ b/jvm/src/main/kotlin/org/amshove/kluent/ErrorCollector.kt @@ -2,16 +2,10 @@ package org.amshove.kluent -import java.util.* - actual val errorCollector: ErrorCollector = ThreadLocalErrorCollector object ThreadLocalErrorCollector : ErrorCollector { - private val clueContext = object : ThreadLocal>() { - override fun initialValue(): Stack = Stack() - } - private val failures = object : ThreadLocal>() { override fun initialValue(): MutableList = mutableListOf() } @@ -24,16 +18,6 @@ object ThreadLocalErrorCollector : ErrorCollector { override fun getCollectionMode(): ErrorCollectionMode = collectionMode.get() - override fun pushClue(clue: Clue) { - clueContext.get().push(clue) - } - - override fun popClue() { - clueContext.get().pop() - } - - override fun clueContext(): List = clueContext.get() - override fun errors(): List = failures.get().toList() /** From 00ae45258c483abc28f5f7106756c45eaeb44b7e Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Tue, 24 Nov 2020 09:29:53 +0100 Subject: [PATCH 4/5] 1. Removed dependencies on kotlin.test assertions, as all of them are internally implemented within Kluent to support assertSoftly notation; 2. Updated/fixed code and tests for JS and NATIVE; 3. Added documentation (docs/SoftlyAssertions.md) describing the assertSoftly notation. --- .../main/kotlin/org/amshove/kluent/Basic.kt | 2 - .../kotlin/org/amshove/kluent/CharSequence.kt | 4 +- .../kotlin/org/amshove/kluent/Collections.kt | 2 - .../kotlin/org/amshove/kluent/Numerical.kt | 4 +- .../org/amshove/kluent/internal/Assertions.kt | 96 ++++++++++ .../org/amshove/kluent/internal/Utility.kt | 10 +- .../kluent/tests/basic/ShouldBeDigitShould.kt | 2 +- .../kluent/tests/basic/ShouldBeFalseShould.kt | 5 +- .../kluent/tests/basic/ShouldBeNullShould.kt | 6 +- .../kluent/tests/basic/ShouldBeShould.kt | 2 +- .../kluent/tests/basic/ShouldBeTrueShould.kt | 6 +- .../kluent/tests/basic/ShouldEqualShould.kt | 2 +- .../tests/basic/ShouldNotBeDigitShould.kt | 2 +- .../tests/basic/ShouldNotBeFalseShould.kt | 2 +- .../tests/basic/ShouldNotBeNullShould.kt | 9 +- .../kluent/tests/basic/ShouldNotBeShould.kt | 2 +- .../tests/basic/ShouldNotBeTrueShould.kt | 2 +- .../tests/basic/ShouldNotEqualShould.kt | 2 +- .../kluent/tests/basic/ShouldShould.kt | 8 +- .../tests/charsequence/ShouldBeBlankShould.kt | 2 +- .../tests/charsequence/ShouldBeEmptyShould.kt | 2 +- .../charsequence/ShouldBeNullOrBlankShould.kt | 2 +- .../charsequence/ShouldBeNullOrEmptyShould.kt | 2 +- .../charsequence/ShouldContainSomeShould.kt | 4 +- .../charsequence/ShouldNotEndWithShould.kt | 2 +- .../tests/collections/ShouldBeEmptyShould.kt | 2 +- .../collections/ShouldBeInRangeShould.kt | 2 +- .../tests/collections/ShouldBeInShould.kt | 2 +- .../ShouldBeSortedAccordingToShould.kt | 4 +- .../collections/ShouldContainAllShould.kt | 2 +- .../collections/ShouldContainAnyShould.kt | 2 +- .../collections/ShouldContainFalseShould.kt | 3 +- .../tests/collections/ShouldContainShould.kt | 2 +- .../collections/ShouldContainSomeShould.kt | 2 +- .../tests/collections/ShouldHaveKeyShould.kt | 2 +- .../collections/ShouldNotBeEmptyShould.kt | 2 +- .../collections/ShouldNotBeInRangeShould.kt | 2 +- .../tests/collections/ShouldNotEqualShould.kt | 2 +- .../ShouldNotEqualUnorderedShould.kt | 2 +- .../collections/ShouldNotHaveValueShould.kt | 2 +- .../numerical/ShouldBeGreaterThanShould.kt | 2 +- .../numerical/ShouldBeLessOrEqualToShould.kt | 2 +- .../ShouldNotBeGreaterOrEqualToShould.kt | 2 +- docs/README.md | 2 + docs/SoftlyAssertions.md | 164 ++++++++++++++++++ .../kluent/internal/checkResultIsFailure.kt | 19 ++ js/src/test/kotlin/TestsRun.kt | 1 + .../kluent/{stacktraces.kt => StackTraces.kt} | 4 +- .../kluent/internal/checkResultIsFailure.kt | 22 +++ ...igDecimalShouldBeGreaterOrEqualToShould.kt | 2 +- .../BigDecimalShouldBeGreaterThanShould.kt | 2 +- .../BigDecimalShouldBeInRangeShould.kt | 2 +- .../BigDecimalShouldBeLessOrEqualToShould.kt | 2 +- .../BigDecimalShouldBeLessThanShould.kt | 2 +- .../BigDecimalShouldBeNegativeShould.kt | 2 +- .../BigDecimalShouldBePositiveShould.kt | 2 +- .../BigDecimalShouldEqualToShould.kt | 2 +- .../BigDecimalShouldNotBeGreaterOrEqualTo.kt | 2 +- .../BigDecimalShouldNotBeGreaterThanShould.kt | 2 +- .../BigDecimalShouldNotBeInRangeShould.kt | 2 +- ...igDecimalShouldNotBeLessOrEqualToShould.kt | 2 +- .../BigDecimalShouldNotBeLessThanShould.kt | 2 +- .../BigDecimalShouldNotEqualToShould.kt | 2 +- .../assertions/file/ShouldBeDirShould.kt | 2 +- .../assertions/file/ShouldExistShould.kt | 2 +- .../file/ShouldHaveExtensionShould.kt | 2 +- .../assertions/file/ShouldHaveNameShould.kt | 2 +- .../tests/assertions/softly/AssertSoftly.kt | 77 ++++++++ .../time/instant/ShouldBeAfterShould.kt | 2 +- .../time/localdate/ShouldBeAfterShould.kt | 2 +- .../ShouldBeAtLeastXDaysAfterShould.kt | 2 +- .../time/localdate/ShouldBeInMonthShould.kt | 2 +- .../ShouldBeAtLeastXMinutesAfterShould.kt | 2 +- .../ShouldBeAtMostXMinutesAfterShould.kt | 2 +- .../localtime/ShouldBeXMinutesAfterShould.kt | 2 +- .../tests/equivalency/ShouldBeEquivalentTo.kt | 2 +- .../kluent/internal/checkResultIsFailure.kt | 19 ++ 77 files changed, 490 insertions(+), 91 deletions(-) create mode 100644 docs/SoftlyAssertions.md create mode 100644 js/src/main/kotlin/org/amshove/kluent/internal/checkResultIsFailure.kt rename jvm/src/main/kotlin/org/amshove/kluent/{stacktraces.kt => StackTraces.kt} (92%) create mode 100644 jvm/src/main/kotlin/org/amshove/kluent/internal/checkResultIsFailure.kt create mode 100644 native/src/main/kotlin/org/amshove/kluent/internal/checkResultIsFailure.kt diff --git a/common/src/main/kotlin/org/amshove/kluent/Basic.kt b/common/src/main/kotlin/org/amshove/kluent/Basic.kt index 29c342e7..93ae236f 100644 --- a/common/src/main/kotlin/org/amshove/kluent/Basic.kt +++ b/common/src/main/kotlin/org/amshove/kluent/Basic.kt @@ -3,8 +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 @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 5201476c..ebd6f721 100644 --- a/common/src/main/kotlin/org/amshove/kluent/Collections.kt +++ b/common/src/main/kotlin/org/amshove/kluent/Collections.kt @@ -1,8 +1,6 @@ package org.amshove.kluent import org.amshove.kluent.internal.* -import kotlin.test.assertEquals -import kotlin.test.assertNotEquals 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/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/internal/Assertions.kt b/common/src/main/kotlin/org/amshove/kluent/internal/Assertions.kt index 9eb4acc7..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,6 +1,9 @@ package org.amshove.kluent.internal 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 fun assertTrue(actual: Boolean, message: String? = null) { @@ -123,3 +126,96 @@ fun assertSame(expected: Any?, actual: Any?) { 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 c2a95fbb..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(", ")}]" @@ -10,4 +12,10 @@ internal fun joinPairs(map: Map<*, *>) = "Pairs: [${map.map { it.toPair() }.join internal fun fail(message: String): Nothing { throw AssertionError(message) -} \ No newline at end of file +} + +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/tests/basic/ShouldBeDigitShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeDigitShould.kt index fd340d92..edcb704c 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeDigitShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeDigitShould.kt @@ -1,8 +1,8 @@ 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/tests/basic/ShouldBeFalseShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeFalseShould.kt index 60a7a58b..b52e192d 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeFalseShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeFalseShould.kt @@ -1,10 +1,9 @@ package org.amshove.kluent.tests.basic -import org.amshove.kluent.shouldBeFalse -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 diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeNullShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeNullShould.kt index a89b5e63..d85edc39 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeNullShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeNullShould.kt @@ -1,9 +1,9 @@ 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/tests/basic/ShouldBeShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeShould.kt index 9f80013c..08ecf46a 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.basic +import org.amshove.kluent.internal.assertFails import kotlin.test.Test import org.amshove.kluent.shouldBe import org.amshove.kluent.tests.Person -import kotlin.test.assertFails class ShouldBeShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeTrueShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeTrueShould.kt index 2195f82d..4b1c27ef 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeTrueShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldBeTrueShould.kt @@ -1,11 +1,9 @@ package org.amshove.kluent.tests.basic -import org.amshove.kluent.shouldBeTrue -import org.amshove.kluent.assertMessage import org.amshove.kluent.assertMessageContain -import org.amshove.kluent.shouldBeFalse +import org.amshove.kluent.internal.assertFails +import org.amshove.kluent.shouldBeTrue import kotlin.test.Test -import kotlin.test.assertFails class ShouldBeTrueShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldEqualShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldEqualShould.kt index 355dcb6f..fe7ff79b 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldEqualShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldEqualShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.basic +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/tests/basic/ShouldNotBeDigitShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeDigitShould.kt index 0dc39c90..d81b2872 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeDigitShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeDigitShould.kt @@ -1,8 +1,8 @@ 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/tests/basic/ShouldNotBeFalseShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeFalseShould.kt index 015f3c76..6db05b96 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeFalseShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeFalseShould.kt @@ -1,8 +1,8 @@ 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/tests/basic/ShouldNotBeNullShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeNullShould.kt index 69e569ae..d6d3acd3 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeNullShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeNullShould.kt @@ -1,20 +1,19 @@ 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/tests/basic/ShouldNotBeShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeShould.kt index 8c5cb701..247d5d0b 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.basic +import org.amshove.kluent.internal.assertFails import kotlin.test.Test import org.amshove.kluent.shouldNotBe import org.amshove.kluent.tests.Person -import kotlin.test.assertFails class ShouldNotBeShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeTrueShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeTrueShould.kt index 0236fe4e..9be15c8d 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeTrueShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotBeTrueShould.kt @@ -1,8 +1,8 @@ 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/tests/basic/ShouldNotEqualShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotEqualShould.kt index 156128fb..4be4fc95 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotEqualShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldNotEqualShould.kt @@ -1,10 +1,10 @@ package org.amshove.kluent.tests.basic +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/tests/basic/ShouldShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldShould.kt index 44194de1..f02ef16b 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/basic/ShouldShould.kt @@ -1,10 +1,10 @@ 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.should import org.amshove.kluent.tests.Person -import kotlin.test.assertFails -import kotlin.test.assertTrue 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/tests/charsequence/ShouldBeBlankShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldBeBlankShould.kt index 854677cc..cd528d65 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldBeBlankShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldBeBlankShould.kt @@ -1,8 +1,8 @@ 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/tests/charsequence/ShouldBeEmptyShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldBeEmptyShould.kt index 76358cfb..d61b3e89 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldBeEmptyShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldBeEmptyShould.kt @@ -1,8 +1,8 @@ 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/tests/charsequence/ShouldBeNullOrBlankShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldBeNullOrBlankShould.kt index 0bdec919..462988b8 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldBeNullOrBlankShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldBeNullOrBlankShould.kt @@ -1,8 +1,8 @@ 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/tests/charsequence/ShouldBeNullOrEmptyShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldBeNullOrEmptyShould.kt index 71920b21..78a1c287 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldBeNullOrEmptyShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldBeNullOrEmptyShould.kt @@ -1,8 +1,8 @@ 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/tests/charsequence/ShouldContainSomeShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldContainSomeShould.kt index 142943de..6ea8e508 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldContainSomeShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldContainSomeShould.kt @@ -1,12 +1,12 @@ 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/tests/charsequence/ShouldNotEndWithShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotEndWithShould.kt index c0fabb33..33c6b6b9 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotEndWithShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/charsequence/ShouldNotEndWithShould.kt @@ -1,8 +1,8 @@ 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/tests/collections/ShouldBeEmptyShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeEmptyShould.kt index 163b94b3..4b4607bb 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeEmptyShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeEmptyShould.kt @@ -1,8 +1,8 @@ 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/tests/collections/ShouldBeInRangeShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeInRangeShould.kt index 167ae854..f4649b01 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeInRangeShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeInRangeShould.kt @@ -1,8 +1,8 @@ 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/tests/collections/ShouldBeInShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeInShould.kt index 2ece9b2c..a09f00d1 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeInShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeInShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.collections +import org.amshove.kluent.internal.assertFails import kotlin.test.Test 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/tests/collections/ShouldBeSortedAccordingToShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeSortedAccordingToShould.kt index 9266f109..ddb333b6 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeSortedAccordingToShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldBeSortedAccordingToShould.kt @@ -1,10 +1,10 @@ package org.amshove.kluent.tests.collections +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/tests/collections/ShouldContainAllShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainAllShould.kt index 15428d24..b11747e2 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainAllShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainAllShould.kt @@ -1,8 +1,8 @@ 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/tests/collections/ShouldContainAnyShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainAnyShould.kt index 5627f47a..411d8d0d 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainAnyShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainAnyShould.kt @@ -2,8 +2,8 @@ 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/tests/collections/ShouldContainFalseShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainFalseShould.kt index 6c3542dc..e9abf8f5 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainFalseShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainFalseShould.kt @@ -1,9 +1,8 @@ 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/tests/collections/ShouldContainShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainShould.kt index 041f4733..f032a594 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.collections +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/tests/collections/ShouldContainSomeShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainSomeShould.kt index 3ba7a034..c2d05a5a 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainSomeShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldContainSomeShould.kt @@ -1,8 +1,8 @@ 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/tests/collections/ShouldHaveKeyShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldHaveKeyShould.kt index 985ad67d..55604b99 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldHaveKeyShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldHaveKeyShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.collections +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.shouldHaveKey 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/tests/collections/ShouldNotBeEmptyShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotBeEmptyShould.kt index f89fc884..bf508c43 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotBeEmptyShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotBeEmptyShould.kt @@ -1,8 +1,8 @@ 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/tests/collections/ShouldNotBeInRangeShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotBeInRangeShould.kt index 001d3b52..682eefdf 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotBeInRangeShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotBeInRangeShould.kt @@ -1,8 +1,8 @@ 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/tests/collections/ShouldNotEqualShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotEqualShould.kt index ae46dce0..bed2ec6b 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotEqualShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotEqualShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.collections +import org.amshove.kluent.internal.assertFails import org.amshove.kluent.tests.Person import org.amshove.kluent.shouldNotBeEqualTo import kotlin.test.Test -import kotlin.test.assertFails class ShouldNotEqualShould { @Test diff --git a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotEqualUnorderedShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotEqualUnorderedShould.kt index 24aeca6c..47b59c30 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotEqualUnorderedShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotEqualUnorderedShould.kt @@ -1,9 +1,9 @@ package org.amshove.kluent.tests.collections +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/tests/collections/ShouldNotHaveValueShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotHaveValueShould.kt index c0a72ac6..0e639a3b 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotHaveValueShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/collections/ShouldNotHaveValueShould.kt @@ -1,8 +1,8 @@ package org.amshove.kluent.tests.collections +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/tests/numerical/ShouldBeGreaterThanShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeGreaterThanShould.kt index 6da713b1..8076f130 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeGreaterThanShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeGreaterThanShould.kt @@ -1,7 +1,7 @@ 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/tests/numerical/ShouldBeLessOrEqualToShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeLessOrEqualToShould.kt index 9130cc4b..2390e7a1 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeLessOrEqualToShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldBeLessOrEqualToShould.kt @@ -1,8 +1,8 @@ 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/tests/numerical/ShouldNotBeGreaterOrEqualToShould.kt b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldNotBeGreaterOrEqualToShould.kt index 43b66092..41b2ce4b 100644 --- a/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldNotBeGreaterOrEqualToShould.kt +++ b/common/src/test/kotlin/org/amshove/kluent/tests/numerical/ShouldNotBeGreaterOrEqualToShould.kt @@ -1,8 +1,8 @@ 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/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..16180c3d --- /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/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/stacktraces.kt b/jvm/src/main/kotlin/org/amshove/kluent/StackTraces.kt similarity index 92% rename from jvm/src/main/kotlin/org/amshove/kluent/stacktraces.kt rename to jvm/src/main/kotlin/org/amshove/kluent/StackTraces.kt index 05567bf5..7bcc8e52 100644 --- a/jvm/src/main/kotlin/org/amshove/kluent/stacktraces.kt +++ b/jvm/src/main/kotlin/org/amshove/kluent/StackTraces.kt @@ -5,10 +5,10 @@ package org.amshove.kluent actual val stacktraces: StackTraces = object : StackTraces { override fun throwableLocation(t: Throwable): String? { - return throwableLocation(t, 1)?.firstOrNull() + return throwableLocation(t, 1).firstOrNull() } - override fun throwableLocation(t: Throwable, n: Int): List? { + 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() 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 index f2d89cd6..d873e154 100644 --- 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 @@ -82,4 +82,81 @@ class AssertSoftly { } } + @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/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/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 From 3fafddfad647105875021704b879f3d8c7eca48a Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Tue, 24 Nov 2020 09:31:24 +0100 Subject: [PATCH 5/5] Update SoftlyAssertions.md --- docs/SoftlyAssertions.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/SoftlyAssertions.md b/docs/SoftlyAssertions.md index 16180c3d..4c510a85 100644 --- a/docs/SoftlyAssertions.md +++ b/docs/SoftlyAssertions.md @@ -151,9 +151,9 @@ 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)* + *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)* + *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