One thing I don’t like about the API is that `asse...
# konsist
One thing I don’t like about the API is that
fails when called on an empty list. If I have a rule checking something about all functions in a class, then some classes are going to have no functions and that’s fine, obviously they can’t violate the rules, it’s vacuously true. I’d expect it to behave the same as calling
.all { ... }
on an empty collection - it returns true because no element violates the predicate.
👍 3
Please drop a snippet to demonstrate this (I need a bit more context to make sure I got it 100% right). Ae you talking about non-being able to assert the empty declaration lit ("Declaration list is empty. Please make sure that list of declarations contain items...")?
Yes that’s it. If the declaration list is empty I would expect the assertion to pass, not fail.
We’ve been thinking about this issue and find this exception helpful - especially when you’re starting out with Konsist. It can detect invalid tests (e.g. when we want to check
, but in test we write
etc.). But we will consider this problem again and try to solve it 🙂
We are thinking about two options: • adding another
method that will behave as you said before (we don’t have a good name for this “new” assertion - maybe
?) • adding an additional parameter to our
- then developer will be able to choose what behaviour he expects What do you think about it? Maybe you have another idea?
The normal recommended red/green process for writing tests is covering this: you see the test fail (even on purpose), and then you fix the failing code - ensuring the test actually works, as opposed to passing because of a mistake. There is also the "print" method Konsist provides that already makes it easy to confirm you are matching what you want, before you add the actual assertion. This is consistent with other test assertion libraries, for example in Kotest Assertions
passes when the collection is empty. I think that should be the default behaviour, and failing on an empty collection could be another
to chain if needed.
Thx for sharing. I like the
we will address this with the next release
This is the current API proposal: Deprecate methods:
Copy code
Add methods with a new behaviour where an empty list will pass. Add
strict = false
) param (if someone wants this strict verification e.g for debugging):
Copy code
assertTrue (strict = true)
assertFalse (strict = true)