-
Notifications
You must be signed in to change notification settings - Fork 59
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
single() assertion causes test that should fail to pass instead (example inside) #243
Comments
Upon further investigation: the @Test
fun thisWillActuallyPass() {
val list = listOf("hello", "foo")
expectThat(list) {
hasSize(3)
get { this.filter { it == "foo" } }.hasSize(1)
}
} ... which uses
So |
Unfortunately, the same holds true if we use @Test
fun thisWillActuallyPassToo() {
val list = listOf("hello", "foo")
expectThat(list) {
get { this.filter { it == "foo" } }.hasSize(1)[0]
get { this.filter { it == "bar" } }.hasSize(1)[0] // "bar" is not even in the list - yet the test passes!
}
} This passes :( |
@robfletcher any chance you could have a look at this? This one is really critical for my team... |
I'm doing some investigations on this, using the code on your current main branch. The following test case: @Test
fun thisWillActuallyPass() {
val list = listOf("hello", "foo")
expectThat(list) {
hasSize(3) // we have 2 items in the list, yet the test passes
get { this.filter { it == "foo" } }.single()
}
} ... produces the following output when I log the "status" of the tree and the two chains during
I think the key observation here is that
Note that "pending" is checked first. And we do have one pending child. However, one child has also already failed. Yet, here we return if (tree.status is Failed) {
throw CompoundAssertionFailure( ... ) Well, the status isn't "failed", it's "pending". Unfortunately this lets our test pass. This raises several questions:
|
The intention is that it's something you'd use to get an I'll see if I can free up some time to take a look at this ASAP. |
Thanks for the analysis. This was pretty straightforward to fix. v0.30.1 is releasing now. |
@robfletcher thanks for looking into it. The way I read your commit is that That leaves one weird case: assume that you only have one child, and the child is |
Yep, I certainly need to put some more thought into this. First wanted to get a quick fix out. |
@robfletcher thank you for taking care of this! I think that throwing an exception when the assertion status ends up as Pending during the evaluation is the best course of action. |
I've witnessed a very strange behavior of strikt 0.29.0 (as well as 0.30.0) today. Please consider the following self-contained test:
To my amazement, the second and third test will actually pass. Even though the
list
certainly doesn't match all of the given criteria.I can't explain why that's the case. Did I do something horribly wrong with the API? Did I mis-interpret some of the methods?
The text was updated successfully, but these errors were encountered: