-
Notifications
You must be signed in to change notification settings - Fork 627
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
forAll displays all errors at once, even when they are too many #929
- Loading branch information
Showing
13 changed files
with
134 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 12 additions & 7 deletions
19
kotest-assertions/src/commonMain/kotlin/io/kotest/assertions/exceptionToMessage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
package io.kotest.assertions | ||
|
||
/** | ||
* Returns a string error message from the given throwable. | ||
* If the type is an [AssertionError] then the message is taken from the exceptions own message, | ||
* otherwise the exception is converted to a string. | ||
*/ | ||
fun exceptionToMessage(t: Throwable): String = | ||
when (t) { | ||
is AssertionError -> when (t.message) { | ||
null -> t.toString() | ||
else -> t.message!! | ||
} | ||
else -> t.toString() | ||
} | ||
when (t) { | ||
is AssertionError -> when (t.message) { | ||
null -> t.toString() | ||
else -> t.message!! | ||
} | ||
else -> t.toString() | ||
} |
3 changes: 3 additions & 0 deletions
3
kotest-assertions/src/commonMain/kotlin/io/kotest/assertions/sysprop.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package io.kotest.assertions | ||
|
||
expect fun sysprop(name: String): String? |
48 changes: 48 additions & 0 deletions
48
kotest-assertions/src/commonMain/kotlin/io/kotest/inspectors/error.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.kotest.inspectors | ||
|
||
import io.kotest.assertions.Failures | ||
import io.kotest.assertions.exceptionToMessage | ||
import io.kotest.assertions.show.show | ||
import io.kotest.assertions.sysprop | ||
|
||
/** | ||
* Build assertion error message. | ||
* | ||
* Show 10 passed and failed results by default. You can change the number of output results by setting the | ||
* system property `kotlintest.assertions.output.max=20`. | ||
* | ||
* E.g.: | ||
* | ||
* ``` | ||
* -Dkotlintest.assertions.output.max=20 | ||
* ``` | ||
*/ | ||
fun <T> buildAssertionError(msg: String, results: List<ElementResult<T>>): String { | ||
|
||
val maxResults = sysprop("kotlintest.assertions.output.max")?.toInt() ?: 10 | ||
|
||
val passed = results.filterIsInstance<ElementPass<T>>() | ||
val failed = results.filterIsInstance<ElementFail<T>>() | ||
|
||
val builder = StringBuilder(msg) | ||
builder.append("\n\nThe following elements passed:\n") | ||
if (passed.isEmpty()) { | ||
builder.append("--none--") | ||
} else { | ||
builder.append(passed.take(maxResults).map { it.t }.joinToString("\n")) | ||
if (passed.size > maxResults) { | ||
builder.append("\n... and ${passed.size - maxResults} more passed elements") | ||
} | ||
} | ||
builder.append("\n\nThe following elements failed:\n") | ||
if (failed.isEmpty()) { | ||
builder.append("--none--") | ||
} else { | ||
builder.append(failed.take(maxResults).joinToString("\n") { it.t.show() + " => " + exceptionToMessage(it.throwable) }) | ||
if (failed.size > maxResults) { | ||
builder.append("\n... and ${failed.size - maxResults} more failed elements") | ||
} | ||
} | ||
throw Failures.failure(builder.toString()) | ||
} | ||
|
29 changes: 0 additions & 29 deletions
29
kotest-assertions/src/commonMain/kotlin/io/kotest/inspectors/funcs.kt
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
kotest-assertions/src/jsMain/kotlin/io/kotest/assertions/sysprop.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package io.kotest.assertions | ||
|
||
actual fun sysprop(name: String): String? = null |
3 changes: 3 additions & 0 deletions
3
kotest-assertions/src/jvmMain/kotlin/io/kotest/assertions/sysprop.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package io.kotest.assertions | ||
|
||
actual fun sysprop(name: String): String? = System.getProperty(name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.