-
Notifications
You must be signed in to change notification settings - Fork 15
Fix several tests relying on no-op assertion #46
Conversation
…ures Update Mvar read and take docs to explicitly detail if the value is removed or not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel we should change the implementation of equalUnderTheLaw
instead of changing all the tests, they all suffer from the same issue that resulted in this fix.
… ab/fix-mvar-tests
… ab/fix-mvar-tests
@@ -18,13 +18,13 @@ fun throwableEq() = Eq { a: Throwable, b -> | |||
data class Law(val name: String, val test: suspend TestContext.() -> Unit) | |||
|
|||
fun <A> A.equalUnderTheLaw(b: A, eq: Eq<A>): Boolean = | |||
eq.run { eqv(b) } | |||
shouldBeEq(b, eq).let { true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current test status:
|
…nd fix some IO comparisons
Cleanup test by generating EQ based on EqK
Rework Resource to have different states depending on constructor, similar as IO Add fold function to do tailrec recursion over Bind chains Make use function depend on fold Rework tailRecM function to operate over the different states, fixing the stack overflow issue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Just need to check the comment about CancelableMVar
… ab/fix-mvar-tests
… ab/fix-mvar-tests
# Conflicts: # arrow-fx/src/main/kotlin/arrow/fx/internal/CancellableMVar.kt # arrow-fx/src/test/kotlin/arrow/fx/KindConnectionTests.kt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks awesome! Great work! invoke
cannot be removed for 0.10.x, approved to unblock.
* A Map which tracks the insertion order of entries, so that entries may be | ||
* traversed in the order they were inserted. | ||
*/ | ||
internal class LinkedMap<K, V>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use LinkedHashMap
from kotlin.collections
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope AFAIK :D Actually the current MVar has already that kind of list
arrow-fx/src/main/kotlin/arrow/fx/internal/UncancellableMVar.kt
Outdated
Show resolved
Hide resolved
arrow-fx/src/main/kotlin/arrow/fx/internal/UncancellableMVar.kt
Outdated
Show resolved
Hide resolved
override fun <A> genK(gen: Gen<A>): Gen<Kind<ResourcePartialOf<ForIO, Throwable>, A>> = | ||
Gen.oneOf( | ||
gen.map { just(it, IO.bracket()) }, | ||
IO.genK().genK(gen).map { it.liftF(IO.bracket()) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you can see how the Gen
is build for Resource
in Cats effect.
It build Allocate
from Gen<Kind<F, A>>
and Gen<Kind<F, Unit>>
, it builds FlatMap
from the allocate Gen
and another for Suspend
.
The idea here is that if your Kind<F, A>
for example IO<A>
is a strong generator that also generates IO
at depths etc so it can cover all its cases.
@@ -300,3 +300,7 @@ internal fun <A> asyncContinuation(ctx: CoroutineContext, cc: (Either<Throwable, | |||
*/ | |||
internal fun <A> IOForkedStart(fa: IOOf<A>, ctx: CoroutineContext): IO<A> = | |||
IO.Bind(IO.ContinueOn(IO.unit, ctx)) { fa.fix() } | |||
|
|||
@Suppress("UNCHECKED_CAST") | |||
internal fun <A, B> A.unsafeCast(): B = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
onOutput: (A) -> Kind<F, B>, | ||
onRelease: (Kind<F, Unit>) -> Kind<F, Unit> | ||
): Kind<F, B> { | ||
// Interpreter that knows how to evaluate a Resource data structure | ||
// Maintains its own stack for dealing with Bind chains | ||
tailrec fun loop(current: Resource<F, E, Any>, stack: List<(Any) -> Resource<F, E, Any>>): Kind<F, Any?> = | ||
tailrec fun loop(current: Resource<F, E, A>, stack: List<(A) -> Resource<F, E, A>>): Kind<F, B> = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work @aballano!!! 👏 👏 👏
BREAKING: Make
equalUnderTheLaw
throw an exception when the evaluation is false. With this we want to make sure that all tests are verifying something, otherwise non-boolean tests (all tests not usingforAll/Few
) can naively callequalUnderTheLaw
at the end but fail to remember to verify the condition as the name doesn't suggest it. This therefore caused different kind of failures:equalUnderTheLaw
, either with a boolean condition or withshouldBe
-> Simply fixed them by using a more appropriate assertionAll changes are explained below:
equalUnderTheLaw
to rely onshouldBeEq
and throw on failureshouldBeEq
impl as it tries to print the values after the assertion and it causes a stack overflow due to the chained stack.