Skip to content

Commit

Permalink
fixing Fun0Spec; show again representation of ListGroup within explan…
Browse files Browse the repository at this point in the history
…atory
  • Loading branch information
robstoll committed Nov 14, 2024
1 parent c68cb2d commit bf546a5
Show file tree
Hide file tree
Showing 16 changed files with 235 additions and 85 deletions.
51 changes: 26 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ I expected subject : () -> kotlin.Nothing (readme.examples.ToThrowExample
• java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
• java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
• java.base/java.lang.reflect.Method.invoke(Method.java:566)
» cause :
» cause : java.lang.RuntimeException
» message : "a cause"
» stacktrace :
• readme.examples.ToThrowExamples$ex-notToThrow$1.invoke(ToThrowExamples.kt:42)
Expand Down Expand Up @@ -1724,7 +1724,7 @@ expect(listOf(1, 2, 3, -1)).toHaveElementsAndAll {
}
}
```
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/main/misc/tools/readme-examples/src/test/kotlin/readme/examples/ThirdPartyExamples.kt#L24)</sub> ↓ <sub>[Output](#ex-third-party-1)</sub>
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/main/misc/tools/readme-examples/src/test/kotlin/readme/examples/ThirdPartyExamples.kt#L25)</sub> ↓ <sub>[Output](#ex-third-party-1)</sub>
<a name="ex-third-party-1"></a>
```text
I expected subject : [1, 2, 3, -1] (java.util.Arrays.ArrayList <1234789>)
Expand Down Expand Up @@ -1757,7 +1757,7 @@ fun <T : Number> Expect<T>.notToBeNegative() =

expect(-10).notToBeNegative()
```
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/main/misc/tools/readme-examples/src/test/kotlin/readme/examples/ThirdPartyExamples.kt#L34)</sub> ↓ <sub>[Output](#ex-third-party-2)</sub>
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/main/misc/tools/readme-examples/src/test/kotlin/readme/examples/ThirdPartyExamples.kt#L35)</sub> ↓ <sub>[Output](#ex-third-party-2)</sub>
<a name="ex-third-party-2"></a>
```text
I expected subject : -10
Expand All @@ -1772,10 +1772,10 @@ I expected subject : -10
"""
» stacktrace :
• readme.examples.ThirdPartyExamples$ex-third-party-2$notToBeNegative$1.invoke(ThirdPartyExamples.kt:38)
• readme.examples.ThirdPartyExamples$ex-third-party-2$notToBeNegative$1.invoke(ThirdPartyExamples.kt:36)
• readme.examples.ThirdPartyExamples.ex_third_party_2$notToBeNegative(ThirdPartyExamples.kt:36)
• readme.examples.ThirdPartyExamples.ex-third-party-2(ThirdPartyExamples.kt:48)
• readme.examples.ThirdPartyExamples$ex-third-party-2$notToBeNegative$1.invoke(ThirdPartyExamples.kt:39)
• readme.examples.ThirdPartyExamples$ex-third-party-2$notToBeNegative$1.invoke(ThirdPartyExamples.kt:37)
• readme.examples.ThirdPartyExamples.ex_third_party_2$notToBeNegative(ThirdPartyExamples.kt:37)
• readme.examples.ThirdPartyExamples.ex-third-party-2(ThirdPartyExamples.kt:49)
• java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
• java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
• java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Expand All @@ -1793,7 +1793,7 @@ Atrium (and create a PR so that others benefit as well 😉):
import ch.tutteli.atrium.logic._logic

fun <T : Number> Expect<T>.notToBeNegative() =
_logic.createAndAppend("not to be", Text("negative")) { subject ->
_core.createAndAppend("not to be", Text("negative")) { subject ->
when (subject) {
is Int -> subject.sign >= 0
is Long -> subject.sign >= 0
Expand All @@ -1807,7 +1807,7 @@ fun <T : Number> Expect<T>.notToBeNegative() =

expect(-10).notToBeNegative()
```
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/main/misc/tools/readme-examples/src/test/kotlin/readme/examples/ThirdPartyExamples.kt#L52)</sub> ↓ <sub>[Output](#ex-third-party-3)</sub>
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/main/misc/tools/readme-examples/src/test/kotlin/readme/examples/ThirdPartyExamples.kt#L53)</sub> ↓ <sub>[Output](#ex-third-party-3)</sub>
<a name="ex-third-party-3"></a>
```text
I expected subject : -10
Expand Down Expand Up @@ -1989,7 +1989,7 @@ my expectations :
✘ calling myFun with -2147483648 :
✘ ▶ I expected subject : null
» to contain :
• value :
• value : "min"
» but no match was found
✘ calling myFun with 2147483647 :
✘ ▶ I expected subject : "2147483647"
Expand Down Expand Up @@ -2110,7 +2110,7 @@ I expected subject : () -> kotlin.Nothing (readme.examples.MostExamples$e
» ▶ message :
• not to equal: null but to be an instance of : String (kotlin.String) -- Class: java.lang.String
• to contain :
• value :
• value : "no no no"
» but no match was found
ℹ️ Properties of the unexpected IllegalArgumentException
» message : "no no no..."
Expand All @@ -2122,7 +2122,7 @@ I expected subject : () -> kotlin.Nothing (readme.examples.MostExamples$e
• java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
• java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
• java.base/java.lang.reflect.Method.invoke(Method.java:566)
» cause :
» cause : java.lang.UnsupportedOperationException
» message : "not supported"
» stacktrace :
• readme.examples.MostExamples$ex-add-info-3$1.invoke(MostExamples.kt:115)
Expand Down Expand Up @@ -2217,7 +2217,7 @@ This is kind of the simplest way of defining expectation functions. Following an
import ch.tutteli.atrium.logic._logic

fun Expect<Int>.toBeAMultipleOf(base: Int) =
_logic.createAndAppend("is multiple of", base) { it % base == 0 }
_core.createAndAppend("is multiple of", base) { it % base == 0 }
```
</code-own-boolean-1>

Expand All @@ -2228,7 +2228,7 @@ and its usage:
```kotlin
expect(12).toBeAMultipleOf(5)
```
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/main/misc/tools/readme-examples/src/test/kotlin/readme/examples/OwnExpectationFunctions.kt#L33)</sub> ↓ <sub>[Output](#ex-own-boolean-1)</sub>
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/main/misc/tools/readme-examples/src/test/kotlin/readme/examples/OwnExpectationFunctions.kt#L34)</sub> ↓ <sub>[Output](#ex-own-boolean-1)</sub>
<a name="ex-own-boolean-1"></a>
```text
I expected subject : 12
Expand Down Expand Up @@ -2263,7 +2263,7 @@ Consider the following expectation function:
import ch.tutteli.atrium.logic._logic

fun Expect<Int>.toBeEven() =
_logic.createAndAppend("is", Text("an even number")) { it % 2 == 0 }
_core.createAndAppend("is", Text("an even number")) { it % 2 == 0 }
```
</code-own-boolean-2>

Expand All @@ -2276,7 +2276,7 @@ Its usage looks then as follows:
```kotlin
expect(13).toBeEven()
```
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/main/misc/tools/readme-examples/src/test/kotlin/readme/examples/OwnExpectationFunctions.kt#L48)</sub> ↓ <sub>[Output](#ex-own-boolean-2)</sub>
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/main/misc/tools/readme-examples/src/test/kotlin/readme/examples/OwnExpectationFunctions.kt#L49)</sub> ↓ <sub>[Output](#ex-own-boolean-2)</sub>
<a name="ex-own-boolean-2"></a>
```text
I expected subject : 13
Expand Down Expand Up @@ -2305,19 +2305,19 @@ fun Expect<MyDomainModel>.toComplyValidation() =

expect(MyDomainModel(alpha1 = 1204)).toComplyValidation()
```
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/main/misc/tools/readme-examples/src/test/kotlin/readme/examples/ThirdPartyExamples.kt#L79)</sub> ↓ <sub>[Output](#ex-third-party-10)</sub>
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/main/misc/tools/readme-examples/src/test/kotlin/readme/examples/ThirdPartyExamples.kt#L80)</sub> ↓ <sub>[Output](#ex-third-party-10)</sub>
<a name="ex-third-party-10"></a>
```text
I expected subject : MyDomainModel(alpha1=1204) (readme.examples.ThirdPartyExamples.MyDomainModel <1234789>)
✘ to comply : validation
ℹ️ Properties of the unexpected IllegalStateException
» message : "threshold value for alpha1 exceeded, expected <= 1000, was 1204"
» stacktrace :
• readme.examples.ThirdPartyExamples.validateMaxThreshold(ThirdPartyExamples.kt:75)
• readme.examples.ThirdPartyExamples$ex-third-party-10$toComplyValidation$1.invoke(ThirdPartyExamples.kt:83)
• readme.examples.ThirdPartyExamples$ex-third-party-10$toComplyValidation$1.invoke(ThirdPartyExamples.kt:81)
• readme.examples.ThirdPartyExamples.ex_third_party_10$toComplyValidation(ThirdPartyExamples.kt:81)
• readme.examples.ThirdPartyExamples.ex-third-party-10(ThirdPartyExamples.kt:87)
• readme.examples.ThirdPartyExamples.validateMaxThreshold(ThirdPartyExamples.kt:76)
• readme.examples.ThirdPartyExamples$ex-third-party-10$toComplyValidation$1.invoke(ThirdPartyExamples.kt:84)
• readme.examples.ThirdPartyExamples$ex-third-party-10$toComplyValidation$1.invoke(ThirdPartyExamples.kt:82)
• readme.examples.ThirdPartyExamples.ex_third_party_10$toComplyValidation(ThirdPartyExamples.kt:82)
• readme.examples.ThirdPartyExamples.ex-third-party-10(ThirdPartyExamples.kt:88)
• java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
• java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
• java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Expand Down Expand Up @@ -2412,7 +2412,7 @@ Its usage is then as follows:
expect(Person("Susanne", "Whitley", 43, emptyList()))
.toHaveNumberOfChildren(2)
```
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/main/misc/tools/readme-examples/src/test/kotlin/readme/examples/OwnExpectationFunctions.kt#L67)</sub> ↓ <sub>[Output](#ex-own-compose-3)</sub>
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/main/misc/tools/readme-examples/src/test/kotlin/readme/examples/OwnExpectationFunctions.kt#L68)</sub> ↓ <sub>[Output](#ex-own-compose-3)</sub>
<a name="ex-own-compose-3"></a>
```text
I expected subject : Person(firstName=Susanne, lastName=Whitley, age=43, children=[]) (readme.examples.Person <1234789>)
Expand Down Expand Up @@ -2448,7 +2448,7 @@ I.e. it fails for a `Person` with 0 children, because such a person does not hav
expect(Person("Susanne", "Whitley", 43, emptyList()))
.toHaveAdultChildren()
```
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/main/misc/tools/readme-examples/src/test/kotlin/readme/examples/OwnExpectationFunctions.kt#L86)</sub> ↓ <sub>[Output](#ex-own-compose-4)</sub>
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/main/misc/tools/readme-examples/src/test/kotlin/readme/examples/OwnExpectationFunctions.kt#L87)</sub> ↓ <sub>[Output](#ex-own-compose-4)</sub>
<a name="ex-own-compose-4"></a>
```text
I expected subject : Person(firstName=Susanne, lastName=Whitley, age=43, children=[]) (readme.examples.Person <1234789>)
Expand Down Expand Up @@ -2494,7 +2494,7 @@ expect(Person("Susanne", "Whitley", 43, listOf(Person("Petra", "Whitley", 12, em
feature { f(it::age) }.toBeGreaterThan(18)
}
```
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/main/misc/tools/readme-examples/src/test/kotlin/readme/examples/OwnExpectationFunctions.kt#L97)</sub> ↓ <sub>[Output](#ex-own-compose-5)</sub>
↑ <sub>[Example](https://github.com/robstoll/atrium/tree/main/misc/tools/readme-examples/src/test/kotlin/readme/examples/OwnExpectationFunctions.kt#L98)</sub> ↓ <sub>[Output](#ex-own-compose-5)</sub>
<a name="ex-own-compose-5"></a>
```text
I expected subject : Person(firstName=Susanne, lastName=Whitley, age=43, children=[Person(firstName=Petra, lastName=Whitley, age=12, children=[])]) (readme.examples.Person <1234789>)
Expand All @@ -2521,6 +2521,7 @@ because Kotlin cannot infer the types automatically.
<code-own-compose-6>

```kotlin
import ch.tutteli.atrium._core
import ch.tutteli.atrium.logic.utils.mapArguments

fun <T : List<Pair<String, String>>> Expect<T>.areNamesOf(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@file:Suppress("UNUSED_PARAMETER", "unused")

package ch.tutteli.atrium.api.fluent.en_GB

Expand All @@ -15,13 +14,12 @@ class WorstCase {
fun overloaded(b: Boolean): Int = 1
}


@Suppress(/* requires new type inference */ "RemoveExplicitTypeArguments")
// we don't run any tests in here but check that the compiler does not report any ambiguities
fun testOverloadAmbiguity() {
expect(WorstCase()) {
feature { p<Int>(it::propAndFun) }
feature { f0<Int>(it::propAndFun) }
feature { f0<Int>(it::overloaded) }
feature { f1<Boolean, Int>(it::overloaded, true) }
feature { p(it::propAndFun) }
feature { f0(it::propAndFun) }
feature { f0(it::overloaded) }
feature { f1(it::overloaded, true) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ fun <T> ProofContainer<T>.buildProof(init: EntryPointProofBuilder<T>.() -> Unit)
@DslMarker
annotation class ProofBuilderMarker

//TODO 1.4.0 also introduce a DslMarker for Atrium as such to prevent scenarios as the following:
// expect{ .. }.toThrow<...> {
// message { message { } }
// }
// makes it look like `message` has again a `message` feature where in reality its the same,
// a DslMarker should prevent this

//TODO 1.3.0 remove again?
typealias AnyBuilder = BaseGroupBuilder<*, *, *>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private fun AnyBuilder.addHints(
private fun AnyBuilder.addMessageHint(throwable: Throwable) =
row {
column(OCCURRED_EXCEPTION_MESSAGE)
column(throwable.message?.let { Text(it) } ?: Text.NULL)
column(Reportable.representation(throwable.message))
}

private fun AnyBuilder.addStackTraceHint(
Expand All @@ -64,7 +64,7 @@ private fun AnyBuilder.addStackTraceHint(
throwable.stackBacktrace.asSequence()
}
stackTrace.forEach {
add(Text(it))
text(it)
}
}
}
Expand All @@ -89,7 +89,7 @@ fun AnyBuilder.addChildHint(
) {
val secondStackTrace = takeIf(throwable.stackBacktrace.size > 1) { throwable.stackBacktrace[1] }

reportableGroup(childDescription, Text.EMPTY) {
reportableGroup(childDescription, child) {
addHints(child, secondStackTrace)
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package ch.tutteli.atrium.reporting.prerendering.text.impl

import ch.tutteli.atrium.creating.proofs.ProofGroupWithDesignation
import ch.tutteli.atrium.reporting.reportables.Icon
import ch.tutteli.atrium.reporting.prerendering.text.TextPreRenderControlObject
import ch.tutteli.atrium.reporting.prerendering.text.OutputNode
import ch.tutteli.atrium.reporting.prerendering.text.TextPreRenderControlObject
import ch.tutteli.atrium.reporting.prerendering.text.TypedTextPreRenderer
import ch.tutteli.atrium.reporting.prerendering.text.transformSubProofGroup
import ch.tutteli.atrium.reporting.reportables.Icon
import ch.tutteli.atrium.reporting.reportables.ReportableGroupWithDesignation

internal class DefaultFallbackReportableGroupWithDesignationTextPreRenderer :
TypedTextPreRenderer<ProofGroupWithDesignation>(ProofGroupWithDesignation::class) {
TypedTextPreRenderer<ReportableGroupWithDesignation>(ReportableGroupWithDesignation::class) {
override fun transformIt(
reportable: ProofGroupWithDesignation,
reportable: ReportableGroupWithDesignation,
controlObject: TextPreRenderControlObject
): List<OutputNode> {
val newControlObject =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//TODO 2.0.0 remove file
@file:Suppress("DEPRECATION")

package ch.tutteli.atrium.reporting.prerendering.text.impl.assertion

import ch.tutteli.atrium.assertions.*
import ch.tutteli.atrium.creating.proofs.Proof
import ch.tutteli.atrium.reporting.Text
import ch.tutteli.atrium.reporting.filters.ReportableFilter
import ch.tutteli.atrium.reporting.reportables.Icon
import ch.tutteli.atrium.reporting.prerendering.text.TextPreRenderControlObject
Expand Down Expand Up @@ -62,7 +64,22 @@ class DefaultAssertionGroupTextPreRenderer(private val iconStyler: TextIconStyle
}

is ListAssertionGroupType ->
controlObject.transformSubProofGroup(reportable, controlObject, Icon.LIST_BULLET_POINT)
if (controlObject.explainsProof && assertionGroup.representation != Text.EMPTY) {
// if we are in an ExplanatoryAssertionGroup, and the listGroup has a representation,
// then we want to show it in reporting (with proofs, a debugGroup never consists of proofs
// and hence this
controlObject.transformSubProofGroup(reportable, controlObject.copy(explainsProof = false)) { child ->
val newControlObject = determineChildControlObject(
controlObject,
child,
Icon.LIST_BULLET_POINT,
additionalIndent = 1
)
controlObject.transformChildIncludingIndentationAndPrefix(child, newControlObject)
}
} else {
controlObject.transformSubProofGroup(reportable, controlObject, Icon.LIST_BULLET_POINT)
}

is SummaryAssertionGroupType -> controlObject.transformSubProofGroup(
reportable,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ch.tutteli.atrium.reporting.reportables

import ch.tutteli.atrium.creating.proofs.InvisibleProofGroup
import ch.tutteli.atrium.creating.proofs.Proof
import ch.tutteli.atrium.creating.proofs.unwrapInvisibleGroup
import ch.tutteli.atrium.reporting.HorizontalAlignment
import ch.tutteli.atrium.reporting.Text
import ch.tutteli.atrium.reporting.reportables.impl.*
Expand Down
Loading

0 comments on commit bf546a5

Please sign in to comment.