From d923d416d191bc7f26ab0364e8a5e98fd3a517d5 Mon Sep 17 00:00:00 2001 From: Ed Date: Fri, 11 Jun 2021 09:40:59 -0700 Subject: [PATCH 1/4] Fail explanatory assertion group on empty assertionCreator --- .../impl/InAnyOrderEntriesAssertionCreator.kt | 25 ------------------- .../atrium/logic/impl/containsHelpers.kt | 13 +++++++++- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/creating/iterable/contains/creators/impl/InAnyOrderEntriesAssertionCreator.kt b/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/creating/iterable/contains/creators/impl/InAnyOrderEntriesAssertionCreator.kt index 87a4d35462..797686d20c 100644 --- a/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/creating/iterable/contains/creators/impl/InAnyOrderEntriesAssertionCreator.kt +++ b/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/creating/iterable/contains/creators/impl/InAnyOrderEntriesAssertionCreator.kt @@ -94,8 +94,6 @@ class InAnyOrderEntriesAssertionCreator( val featureAssertion = featureFactory(count, DescriptionIterableAssertion.NUMBER_OF_OCCURRENCES) val assertions = mutableListOf(explanatoryGroup) if (searchBehaviour is NotSearchBehaviour) { - createEmptyAssertionHintIfNecessary(multiConsumableContainer, searchCriterion, count) - ?.let { assertions.add(it) } val mismatches = createIndexAssertions(list) { (_, element) -> allCreatedAssertionsHold(multiConsumableContainer, element, searchCriterion) } @@ -118,27 +116,4 @@ class InAnyOrderEntriesAssertionCreator( val count = list.count { allCreatedAssertionsHold(container, it, assertionCreatorOrNull) } return group to count } - - //TODO 0.18.0 check if this is still state of the art to add a hint that no assertion was created - // in the assertionCreator-lambda, maybe it is a special case and needs to be handled like this, - // maybe it would be enough to collect - @Suppress("DEPRECATION" /* OptIn is only available since 1.3.70 which we cannot use if we want to support 1.2 */) - @UseExperimental(ExperimentalComponentFactoryContainer::class) - private fun createEmptyAssertionHintIfNecessary( - container: AssertionContainer<*>, - searchCriterion: (Expect.() -> Unit)?, - count: Int - ): Assertion? { - if (searchCriterion != null && count == 0) { - val collectingExpect = CollectingExpect(None, container.components) - // not using addAssertionsCreatedBy on purpose so that we don't append a failing assertion - collectingExpect.searchCriterion() - val collectedAssertions = collectingExpect.getAssertions() - if (collectedAssertions.isEmpty()) { - // no assertion created in the lambda, so return the failing assertion containing the hint - return container.collectBasedOnSubject(None, searchCriterion) - } - } - return null - } } diff --git a/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/impl/containsHelpers.kt b/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/impl/containsHelpers.kt index 7b03327df1..828ad02375 100644 --- a/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/impl/containsHelpers.kt +++ b/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/impl/containsHelpers.kt @@ -8,7 +8,9 @@ import ch.tutteli.atrium.core.Some import ch.tutteli.atrium.core.falseProvider import ch.tutteli.atrium.core.trueProvider import ch.tutteli.atrium.creating.AssertionContainer +import ch.tutteli.atrium.creating.CollectingExpect import ch.tutteli.atrium.creating.Expect +import ch.tutteli.atrium.creating.ExperimentalComponentFactoryContainer import ch.tutteli.atrium.logic.collectBasedOnSubject import ch.tutteli.atrium.logic.creating.collectors.collectAssertions import ch.tutteli.atrium.reporting.Text @@ -36,6 +38,8 @@ internal fun allCreatedAssertionsHold( else -> assertionCreator != null && container.collectBasedOnSubject(Some(subject), assertionCreator).holds() } +@Suppress("DEPRECATION" /* OptIn is only available since 1.3.70 which we cannot use if we want to support 1.2 */) +@UseExperimental(ExperimentalComponentFactoryContainer::class) internal fun createExplanatoryAssertionGroup( container: AssertionContainer<*>, assertionCreatorOrNull: (Expect.() -> Unit)? @@ -46,7 +50,14 @@ internal fun createExplanatoryAssertionGroup( //TODO 0.18.0 looks a lot like toBeNullIfNullGiven if (assertionCreatorOrNull != null) { // we don't use a subject, we will not show it anyway - it.collectAssertions(container, None, assertionCreatorOrNull) + val collectingExpect = CollectingExpect(None, container.components) + // not using addAssertionsCreatedBy on purpose so that we don't append a failing assertion + collectingExpect.assertionCreatorOrNull() + if(collectingExpect.getAssertions().isEmpty()) { + it.collectAssertions(container, None, assertionCreatorOrNull).failing + } else { + it.collectAssertions(container, None, assertionCreatorOrNull) + } } else { it.withAssertion( // it is for an explanatoryGroup where it does not matter if the assertion holds or not From 17c726012bfb4c03c27e1b80798a209b48f685c6 Mon Sep 17 00:00:00 2001 From: Ed Date: Mon, 21 Jun 2021 16:01:25 -0700 Subject: [PATCH 2/4] Make collectAssertions fail with empty assertionsCreator lambda --- .../AssertionsOptionExplantoryExtensions.kt | 19 +++++++++++++++++-- .../atrium/logic/impl/containsHelpers.kt | 13 +------------ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/creating/collectors/AssertionsOptionExplantoryExtensions.kt b/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/creating/collectors/AssertionsOptionExplantoryExtensions.kt index 9ebdc449f2..ef8ff0451c 100644 --- a/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/creating/collectors/AssertionsOptionExplantoryExtensions.kt +++ b/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/creating/collectors/AssertionsOptionExplantoryExtensions.kt @@ -3,9 +3,13 @@ package ch.tutteli.atrium.logic.creating.collectors import ch.tutteli.atrium.assertions.AssertionGroup import ch.tutteli.atrium.assertions.ExplanatoryAssertionGroupType import ch.tutteli.atrium.assertions.builders.AssertionsOption +import ch.tutteli.atrium.assertions.builders.ExplanatoryAssertionGroupFinalStep +import ch.tutteli.atrium.core.None import ch.tutteli.atrium.core.Option import ch.tutteli.atrium.creating.AssertionContainer +import ch.tutteli.atrium.creating.CollectingExpect import ch.tutteli.atrium.creating.Expect +import ch.tutteli.atrium.creating.ExperimentalComponentFactoryContainer import ch.tutteli.atrium.logic.collectForCompositionBasedOnSubject /** @@ -13,8 +17,19 @@ import ch.tutteli.atrium.logic.collectForCompositionBasedOnSubject * * //TODO 0.18.0 in case we somehow incorporate the current container in AssertionsOptions, then remove container as parameter */ -fun AssertionsOption.collectAssertions( +@Suppress("DEPRECATION" /* OptIn is only available since 1.3.70 which we cannot use if we want to support 1.2 */) +@UseExperimental(ExperimentalComponentFactoryContainer::class) +fun AssertionsOption.collectAssertions( container: AssertionContainer<*>, maybeSubject: Option, assertionCreator: Expect.() -> Unit -): R = withAssertions(container.collectForCompositionBasedOnSubject(maybeSubject, assertionCreator)) +): ExplanatoryAssertionGroupFinalStep { + val collectingExpect = CollectingExpect(None, container.components) + // not using addAssertionsCreatedBy on purpose so that we don't append a failing assertion + collectingExpect.assertionCreator() + return withAssertions(container.collectForCompositionBasedOnSubject(maybeSubject, assertionCreator)) + .let { + if(collectingExpect.getAssertions().isEmpty()) it.failing + else it + } +} diff --git a/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/impl/containsHelpers.kt b/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/impl/containsHelpers.kt index 828ad02375..7b03327df1 100644 --- a/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/impl/containsHelpers.kt +++ b/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/impl/containsHelpers.kt @@ -8,9 +8,7 @@ import ch.tutteli.atrium.core.Some import ch.tutteli.atrium.core.falseProvider import ch.tutteli.atrium.core.trueProvider import ch.tutteli.atrium.creating.AssertionContainer -import ch.tutteli.atrium.creating.CollectingExpect import ch.tutteli.atrium.creating.Expect -import ch.tutteli.atrium.creating.ExperimentalComponentFactoryContainer import ch.tutteli.atrium.logic.collectBasedOnSubject import ch.tutteli.atrium.logic.creating.collectors.collectAssertions import ch.tutteli.atrium.reporting.Text @@ -38,8 +36,6 @@ internal fun allCreatedAssertionsHold( else -> assertionCreator != null && container.collectBasedOnSubject(Some(subject), assertionCreator).holds() } -@Suppress("DEPRECATION" /* OptIn is only available since 1.3.70 which we cannot use if we want to support 1.2 */) -@UseExperimental(ExperimentalComponentFactoryContainer::class) internal fun createExplanatoryAssertionGroup( container: AssertionContainer<*>, assertionCreatorOrNull: (Expect.() -> Unit)? @@ -50,14 +46,7 @@ internal fun createExplanatoryAssertionGroup( //TODO 0.18.0 looks a lot like toBeNullIfNullGiven if (assertionCreatorOrNull != null) { // we don't use a subject, we will not show it anyway - val collectingExpect = CollectingExpect(None, container.components) - // not using addAssertionsCreatedBy on purpose so that we don't append a failing assertion - collectingExpect.assertionCreatorOrNull() - if(collectingExpect.getAssertions().isEmpty()) { - it.collectAssertions(container, None, assertionCreatorOrNull).failing - } else { - it.collectAssertions(container, None, assertionCreatorOrNull) - } + it.collectAssertions(container, None, assertionCreatorOrNull) } else { it.withAssertion( // it is for an explanatoryGroup where it does not matter if the assertion holds or not From 45519af5f557d8a268cff687f7574e1e60c7b39d Mon Sep 17 00:00:00 2001 From: Ed Date: Mon, 21 Jun 2021 16:03:02 -0700 Subject: [PATCH 3/4] Note use of deprecated type with TODO --- .../creating/collectors/AssertionsOptionExplantoryExtensions.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/creating/collectors/AssertionsOptionExplantoryExtensions.kt b/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/creating/collectors/AssertionsOptionExplantoryExtensions.kt index ef8ff0451c..3c92d2aa6e 100644 --- a/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/creating/collectors/AssertionsOptionExplantoryExtensions.kt +++ b/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/creating/collectors/AssertionsOptionExplantoryExtensions.kt @@ -16,6 +16,8 @@ import ch.tutteli.atrium.logic.collectForCompositionBasedOnSubject * Collects the assertions [assertionCreator] creates and uses them as [AssertionGroup.assertions]. * * //TODO 0.18.0 in case we somehow incorporate the current container in AssertionsOptions, then remove container as parameter + * + * TODO 1.0.0 at the latest: use type ExplanatoryGroup.FinalStep when ExplanatoryAssertionGroupFinalStep is removed */ @Suppress("DEPRECATION" /* OptIn is only available since 1.3.70 which we cannot use if we want to support 1.2 */) @UseExperimental(ExperimentalComponentFactoryContainer::class) From 568a1bf9888c4e1b4e36c089e19cf06eab4e9a7d Mon Sep 17 00:00:00 2001 From: Ed Date: Wed, 30 Jun 2021 18:15:30 -0700 Subject: [PATCH 4/4] Suppress deprecation warning for ExplanatoryAssertionGroupFinalStep --- .../collectors/AssertionsOptionExplantoryExtensions.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/creating/collectors/AssertionsOptionExplantoryExtensions.kt b/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/creating/collectors/AssertionsOptionExplantoryExtensions.kt index 3c92d2aa6e..4133facd42 100644 --- a/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/creating/collectors/AssertionsOptionExplantoryExtensions.kt +++ b/logic/atrium-logic-common/src/main/kotlin/ch/tutteli/atrium/logic/creating/collectors/AssertionsOptionExplantoryExtensions.kt @@ -1,3 +1,6 @@ +// TODO 1.0.0 at the latest: use type ExplanatoryGroup.FinalStep when ExplanatoryAssertionGroupFinalStep is removed +@file:Suppress("DEPRECATION") + package ch.tutteli.atrium.logic.creating.collectors import ch.tutteli.atrium.assertions.AssertionGroup