Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty assertionCreator lambda warning is added twice #933

Closed
wordhou opened this issue Jun 8, 2021 · 1 comment · Fixed by #938
Closed

Empty assertionCreator lambda warning is added twice #933

wordhou opened this issue Jun 8, 2021 · 1 comment · Fixed by #938
Assignees
Milestone

Comments

@wordhou
Copy link
Collaborator

wordhou commented Jun 8, 2021

Affected Version: 1.7
API (fluent-en_GB, infix-en_GB): both
Platform (jvm, js): logic
Extension (none, kotlin 1.3): none

expect(oneToSeven()).notToContainFun({})

produces

"expected that subject: kotlin.sequences.SequencesKt___SequencesKt$asIterable$$inlined$Iterable$1@5453dabb        (kotlin.sequences.SequencesKt___SequencesKt$asIterable$$inlined$Iterable$1 <1414781627>)
    ◆ does not contain: 
      ⚬ an element which: 
          » at least one assertion defined: false
              » You forgot to define assertions in the assertionCreator-lambda
              » Sometimes you can use an alternative to `{ }` For instance, instead of `toThrow<..> { }` you should use `toThrow<..>()`
        ✔ ▶ number of such entries: 0
            ◾ is: 0        (kotlin.Int <449752083>)
        ✔ ▶ has at least one element: true
            ◾ is: true
        ✘ at least one assertion defined: false
            » You forgot to define assertions in the assertionCreator-lambda
            » Sometimes you can use an alternative to `{ }` For instance, instead of `toThrow<..> { }` you should use `toThrow<..>()`"

and

expect(oneToSeven()).notToContainFun({}, {toBeLessThan(3.0)})

produces

expected that subject: kotlin.sequences.SequencesKt___SequencesKt$asIterable$$inlined$Iterable$1@1b2be2e2        (kotlin.sequences.SequencesKt___SequencesKt$asIterable$$inlined$Iterable$1 <455860962>)
    ◆ does not contain: 
      ⚬ an element which: 
          » at least one assertion defined: false
              » You forgot to define assertions in the assertionCreator-lambda
              » Sometimes you can use an alternative to `{ }` For instance, instead of `toThrow<..> { }` you should use `toThrow<..>()`
        ✔ ▶ number of such entries: 0
            ◾ is: 0        (kotlin.Int <449752083>)
        ✔ ▶ has at least one element: true
            ◾ is: true
        ✘ at least one assertion defined: false
            » You forgot to define assertions in the assertionCreator-lambda
            » Sometimes you can use an alternative to `{ }` For instance, instead of `toThrow<..> { }` you should use `toThrow<..>()`
      ⚬ an element which: 
          » is less than: 3.0        (kotlin.Double <888510275>)
        ✘ ▶ number of such entries: 2
            ◾ is: 0        (kotlin.Int <449752083>)
        ✔ ▶ has at least one element: true
            ◾ is: true

Describe the bug

On IterableLike notToContain.entry/entries the empty assertionCreator lambda is getting added twice. In InAnyOrderEntriesAssertionCreator it appears to be getting added once in addEmptyAssertionCreatorLambdaIfNeccessaryand once in createExplanatoryAssertionGroup.

I added a test in this branch to take a look at this issue:
https://github.com/wordhou/atrium/blob/empty-assertion-creator-issues/misc/specs/atrium-specs-common/src/main/kotlin/ch/tutteli/atrium/specs/integration/IterableNotToContainEntriesExpectationsSpec.kt#L106

@wordhou wordhou added the bug label Jun 8, 2021
@robstoll
Copy link
Owner

robstoll commented Jun 8, 2021

Good catch. I am going to remove bug as it is not something which needs to be fixed immediately IMO and thus change it to enhancement.
I am not even sure if we should fix it / invest time for it, knowing that this only occurs if the developer has forgotten to specify assertions.

In case someone is motivated to fix it, then go for it. But I think we should reduce it to a minimum effort as I don't think it is worth to add more complexity to the assertion function just for this particular case. Thus I suggest that we report the check differently if it is in an explanatory group, there it is not really necessary to show that information and a different text could be more helpful. This way we can keep the logic in the function the same. Something like the following:

expected that subject: kotlin.sequences.SequencesKt___SequencesKt$asIterable$$inlined$Iterable$1@5453dabb        (kotlin.sequences.SequencesKt___SequencesKt$asIterable$$inlined$Iterable$1 <1414781627>)
    ◆ does not contain: 
      ⚬ an element which: 
          » no assertion specified
        ✔ ▶ number of such entries: 0
            ◾ is: 0        (kotlin.Int <449752083>)
        ✔ ▶ has at least one element: true
            ◾ is: true
        ✘ at least one assertion defined: false
            » You forgot to define assertions in the assertionCreator-lambda
            » Sometimes you can use an alternative to `{ }` For instance, instead of `toThrow<..> { }` you should use `toThrow<..>()`"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants