From 77808a780524bb4c61bbb45a0ea4d3e9c3ce1123 Mon Sep 17 00:00:00 2001 From: Robert Stoll Date: Tue, 13 Jul 2021 20:32:40 +0200 Subject: [PATCH] mention report optiosn for in order only in README --- README.md | 91 ++++++++++++------- .../mapLikeContainsInOrderOnlyCreators.kt | 3 +- .../readme/examples/MostExamplesSpec.kt | 8 ++ 3 files changed, 70 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index f5490a41e..1f666491c 100644 --- a/README.md +++ b/README.md @@ -374,7 +374,7 @@ expected that subject: () -> kotlin.Nothing (readme.examples.MostExamples » stacktrace: ⚬ readme.examples.MostExamplesSpec$1$7$1.invoke(MostExamplesSpec.kt:67) ⚬ readme.examples.MostExamplesSpec$1$7$1.invoke(MostExamplesSpec.kt:22) - ⚬ readme.examples.MostExamplesSpec$1$7.invoke(MostExamplesSpec.kt:272) + ⚬ readme.examples.MostExamplesSpec$1$7.invoke(MostExamplesSpec.kt:280) ⚬ readme.examples.MostExamplesSpec$1$7.invoke(MostExamplesSpec.kt:22) ``` @@ -1158,7 +1158,7 @@ expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789> ``` -Since we have chosen the `only` option, Atrium shows us a summary where we see three things: +Since we have chosen the `only` option, Atrium shows us a summary1 where we see three things: - Whether a specified `assertionCreator`-lambda matched (signified by `✔` or `✘`) the corresponding element or not (e.g. `✘ ▶ entry 1:` was `2` and we expected, it `is less than 2`) - Whether the expected size was correct or not (`✘ ▶ size:` was `4`, we expected it, `to be: 2` -- see also [Property Assertions](#property-assertions)) @@ -1167,13 +1167,42 @@ Since we have chosen the `only` option, Atrium shows us a summary where we see t 😍 We are pretty sure you are going to love this feature as well. Please star Atrium if you like using it. -
-💬 too verbose? + +1 Atrium shows a summary up to 10 elements, if the Iterable contains more elements, +then only failing expectations are shown. + +
+💬 Show only failing expectations/elements earlier than 10 elements? + +You can use the `report` option to specify when Atrium shall start to show only failing expectations. +Following an example changing the limit to 3 elements by using `showOnlyFailingIfMoreElementsThan` : + + + +```kotlin +expect(listOf(1, 2, 2, 4)).toContainExactly( + { toBeLessThan(3) }, + { toBeLessThan(2) }, + { toBeGreaterThan(1) }, + report = { showOnlyFailingIfMoreElementsThan(3) } +) +``` +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L154)[Output](#ex-collection-reportOptions-1) + +```text +expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>) +◆ ▶ size: 4 (kotlin.Int <1234789>) + ◾ equals: 3 (kotlin.Int <1234789>) +◆ contains only, in order: + ⚬ ▶ element 1: 2 (kotlin.Int <1234789>) + ◾ is less than: 2 (kotlin.Int <1234789>) + ❗❗ additional elements detected: + ⚬ element 3: 4 (kotlin.Int <1234789>) +``` + + +Likewise, you can use `showOnlyFailing()` to set the limit to 0 and `showAlwaysSummary()` to set the limit to Int.MAX_VALUE -As side notice, in case you are dealing with large `Iterable` and do not want such a verbose output, -then let use know by up-voting https://github.com/robstoll/atrium/issues/292 -So far the verbose output was always handy for us, but you might have other test cases than we have. -Also notice, that Atrium will not deal with infinite `Iterable`s, i.e. you need to use `take(100)` or the like first.
@@ -1189,7 +1218,7 @@ and we happily answer your question there. ```kotlin expect(listOf(1, 2, 2, 4)).toContain.inOrder.only.values(1, 2, 2, 3, 4) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L154)[Output](#ex-collection-builder-2) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L162)[Output](#ex-collection-builder-2) ```text expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>) @@ -1214,7 +1243,7 @@ expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789> ```kotlin expect(listOf(1, 2, 2, 4)).toContain.inAnyOrder.atLeast(1).butAtMost(2).entries({ toBeLessThan(3) }) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L157)[Output](#ex-collection-builder-3) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L165)[Output](#ex-collection-builder-3) ```text expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>) @@ -1231,7 +1260,7 @@ expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789> ```kotlin expect(listOf(1, 2, 2, 4)).toContain.inAnyOrder.only.values(1, 2, 3, 4) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L160)[Output](#ex-collection-builder-4) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L168)[Output](#ex-collection-builder-4) ```text expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>) @@ -1250,7 +1279,7 @@ expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789> ```kotlin expect(listOf(1, 2, 2, 4)).toContain.inAnyOrder.only.values(4, 3, 2, 2, 1) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L163)[Output](#ex-collection-builder-5) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L171)[Output](#ex-collection-builder-5) ```text expected that subject: [1, 2, 2, 4] (java.util.Arrays.ArrayList <1234789>) @@ -1280,7 +1309,7 @@ and more [Sophisticated Assertion Builder](#sophisticated-assertion-builders-1) ```kotlin expect(mapOf("a" to 1, "b" to 2)).toContain("c" to 2, "a" to 1, "b" to 1) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L167)[Output](#ex-map-1) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L175)[Output](#ex-map-1) ```text expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>) @@ -1304,7 +1333,7 @@ expect(mapOf("a" to 1, "b" to 2)).toContain( KeyValue("b") { toBeLessThan(2) } ) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L170)[Output](#ex-map-2) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L178)[Output](#ex-map-2) ```text expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>) @@ -1326,7 +1355,7 @@ Again both overloads are provided, one for key-value `Pair`s: ```kotlin expect(mapOf("a" to 1, "b" to 2)).toContainOnly("b" to 2) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L178)[Output](#ex-map-only-1) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L186)[Output](#ex-map-only-1) ```text expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>) @@ -1351,7 +1380,7 @@ expect(mapOf("a" to 1, "b" to 2)).toContainOnly( KeyValue("b") { toBeLessThan(2) } ) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L181)[Output](#ex-map-only-2) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L189)[Output](#ex-map-only-2) ```text expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>) @@ -1379,7 +1408,7 @@ again provide two overloads, one expecting key-value `Pair`s: ```kotlin expect(mapOf("a" to 1, "b" to 2)).toContain.inOrder.only.entries("b" to 2, "a" to 1) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L189)[Output](#ex-map-builder-1) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L197)[Output](#ex-map-builder-1) ```text expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>) @@ -1406,7 +1435,7 @@ expect(mapOf("a" to 1, "b" to 2)).toContain.inOrder.only.entries( KeyValue("a") { toBeLessThan(2) }, KeyValue("b") { toBeLessThan(2) }) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L192)[Output](#ex-map-builder-2) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L200)[Output](#ex-map-builder-2) ```text expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>) @@ -1443,7 +1472,7 @@ expect(mapOf("bernstein" to bernstein)) feature { f(it::firstName) }.toEqual("Albert") } ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L202)[Output](#ex-map-3) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L210)[Output](#ex-map-3) ```text expected that subject: {bernstein=Person(firstName=Leonard, lastName=Bernstein, age=50)} (java.util.Collections.SingletonMap <1234789>) @@ -1463,7 +1492,7 @@ expect(mapOf("a" to 1, "b" to 2)) { values { toHaveElementsAndNone { toBeGreaterThan(1) } } } ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L214)[Output](#ex-map-4) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L222)[Output](#ex-map-4) ```text expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>) @@ -1499,7 +1528,7 @@ expect(linkedMapOf("a" to 1, "b" to 2)).asEntries().toContain.inOrder.only.entri } ) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L220)[Output](#ex-map-5) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L228)[Output](#ex-map-5) ```text expected that subject: {a=1, b=2} (java.util.LinkedHashMap <1234789>) @@ -1595,7 +1624,7 @@ expect("filename?") notToContain("?") } ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L230)[Output](#ex-because-1) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L238)[Output](#ex-because-1) ```text expected that subject: "filename?" <1234789> @@ -1871,10 +1900,10 @@ expect { } }.toThrow { messageToContain("no no no") } ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L243)[Output](#ex-add-info-3) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L251)[Output](#ex-add-info-3) ```text -expected that subject: () -> kotlin.Nothing (readme.examples.MostExamplesSpec$1$39$1 <1234789>) +expected that subject: () -> kotlin.Nothing (readme.examples.MostExamplesSpec$1$40$1 <1234789>) ◆ ▶ thrown exception when called: java.lang.IllegalArgumentException ◾ is instance of type: IllegalStateException (java.lang.IllegalStateException) » ▶ message: @@ -1885,14 +1914,14 @@ expected that subject: () -> kotlin.Nothing (readme.examples.MostExamples ℹ Properties of the unexpected IllegalArgumentException » message: "no no no..." <1234789> » stacktrace: - ⚬ readme.examples.MostExamplesSpec$1$39$1.invoke(MostExamplesSpec.kt:248) - ⚬ readme.examples.MostExamplesSpec$1$39$1.invoke(MostExamplesSpec.kt:22) - ⚬ readme.examples.MostExamplesSpec$1$39.invoke(MostExamplesSpec.kt:272) - ⚬ readme.examples.MostExamplesSpec$1$39.invoke(MostExamplesSpec.kt:22) + ⚬ readme.examples.MostExamplesSpec$1$40$1.invoke(MostExamplesSpec.kt:256) + ⚬ readme.examples.MostExamplesSpec$1$40$1.invoke(MostExamplesSpec.kt:22) + ⚬ readme.examples.MostExamplesSpec$1$40.invoke(MostExamplesSpec.kt:280) + ⚬ readme.examples.MostExamplesSpec$1$40.invoke(MostExamplesSpec.kt:22) » cause: java.lang.UnsupportedOperationException » message: "not supported" <1234789> » stacktrace: - ⚬ readme.examples.MostExamplesSpec$1$39$1.invoke(MostExamplesSpec.kt:246) + ⚬ readme.examples.MostExamplesSpec$1$40$1.invoke(MostExamplesSpec.kt:254) ``` @@ -1913,7 +1942,7 @@ then Atrium reminds us of the possible pitfall. For instance: ```kotlin expect(BigDecimal.TEN).toEqualIncludingScale(BigDecimal("10.0")) ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L253)[Output](#ex-pitfall-1) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L261)[Output](#ex-pitfall-1) ```text expected that subject: 10 (java.math.BigDecimal <1234789>) @@ -1931,7 +1960,7 @@ For instance: ```kotlin expect(listOf(1)).get(0) {} ``` -↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L256)[Output](#ex-pitfall-2) +↑ [Example](https://github.com/robstoll/atrium/tree/master/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt#L264)[Output](#ex-pitfall-2) ```text expected that subject: [1] (java.util.Collections.SingletonList <1234789>) diff --git a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/mapLikeContainsInOrderOnlyCreators.kt b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/mapLikeContainsInOrderOnlyCreators.kt index 7099c4e43..3fa61ea80 100644 --- a/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/mapLikeContainsInOrderOnlyCreators.kt +++ b/apis/fluent-en_GB/atrium-api-fluent-en_GB-common/src/main/kotlin/ch/tutteli/atrium/api/fluent/en_GB/mapLikeContainsInOrderOnlyCreators.kt @@ -62,7 +62,6 @@ inline fun EntryPointStep ): Expect = entries(keyValue) -// TODO 0.17.0 implement https://github.com/robstoll/atrium/issues/292 for the new function in ...Expectations.kt file7 /** * Finishes the specification of the sophisticated `contains` assertion where the subject (a [MapLike]) * needs to contain only the given [keyValue] as well as the [otherKeyValues] in the specified order -- an entry @@ -78,6 +77,8 @@ inline fun EntryPointStep EntryPointStep.entries( keyValue: KeyValue, vararg otherKeyValues: KeyValue + //TODO 0.18.0 add the following + //report: InOrderOnlyReportingOptions.() -> Unit = {} ): Expect = entries(V::class, keyValue glue otherKeyValues) @PublishedApi // in order that _logic does not become part of the API we have this extra function diff --git a/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt b/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt index 6ff63b8d3..f62e15046 100644 --- a/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt +++ b/misc/tools/readme-examples/src/main/kotlin/readme/examples/MostExamplesSpec.kt @@ -151,6 +151,14 @@ class MostExamplesSpec : Spek({ test("ex-collection-builder-1") { expect(listOf(1, 2, 2, 4)).toContain.inOrder.only.entries({ toBeLessThan(3) }, { toBeLessThan(2) }) } + test("ex-collection-reportOptions-1") { + expect(listOf(1, 2, 2, 4)).toContainExactly( + { toBeLessThan(3) }, + { toBeLessThan(2) }, + { toBeGreaterThan(1) }, + report = { showOnlyFailingIfMoreElementsThan(3) } + ) + } test("ex-collection-builder-2") { expect(listOf(1, 2, 2, 4)).toContain.inOrder.only.values(1, 2, 2, 3, 4) }