-
Notifications
You must be signed in to change notification settings - Fork 0
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
Initial Prototype #1
base: main
Are you sure you want to change the base?
Conversation
Using When we had With context receivers we need to setup a context to get the test compiling/executing, and need to capture the error path to validate it; happy-path result verification is cleaner as it's simply the return value. This is one mechanism to make this work (see below for ideas on improvement):
...with a few helper shims its a bit cleaner:
It would be ideal if Kotest tests using Arrow/Either/context-receivers were symmetrical with raw Kotlin code w/ exceptions, specifically: a) There would be a mechanism to execute code in a context w/o having to explicitly (and repeatedly) establish that context; Perhaps parts of this exist already and my evolving Arrow journey hasn't taken me there yet. |
@cloudshiftchris Very insightful. I've added |
@kyay10 thanks for the quick turnaround! Dropped those implementations in to compare against what we've stubbed out internally - comparison w/ commentary on a few actual tests below. Don't think we're there yet - the mixing of "providing a context" with "checking assertions" is somewhat problematic. This is syntactically ideal - separating context receiver from assertion - with unknowns (for me) on how to have kotest provide a context receiver:
Comparison:
|
This is closer - adding Shifts the "provide me a context to run in" to
|
@cloudshiftchris Check the new commit! Thank you for the great suggestions! Hopefully, kotest can support something similar to |
@kyay10 amazing. thank you for the context (pun intended) around Raise - had dug into it a bit and figured it was special. On that same topic (of requiring a specific Raise instance) - not sure if this is solvable but ran into a few challenges (of my own making) that took a bit to figure out, perhaps Arrow/compiler could help somehow. This is a working test:
...however, I struggled to get it working, having accidentally done this (note the second type parameter on
...because the types are all in the same hierarchy the compiler never blinked; at runtime, where New code looks great! A small amount of code that goes a long way. Only a minor naming consistency item, if we desire symmetry with kotest's I've asked on the #kotest slack channel around context-receiver options: https://kotlinlang.slack.com/archives/CT0G9SD7Z/p1705370189026969. |
@cloudshiftchris with the risk of slightly derailing the conversation, I want to point out that you can define a Edit: See latest commit! |
… with `@TestingRaiseDsl`.
@kyay10 thanks for the guidance & commit showing how that would work. Back-ported for Arrow 1.2 / Kotlin 1.9.x - works well, will a minor annoyance of failure messages being nested due to two levels or Raise (
|
|
🤦 yep, overthought the heck out of that one ;) thank you. That wasn't actually the issue, however: the messages are still nested - this likely due to my code raising an error internally, which is immediately turned into an AssertionError, however, that is in a Not seeing a clean way around that, short of |
This addresses it - leaving raised errors intact until the end of the context scope (i.e. letting them bubble up as they normally would), then (if present) fail the test.
|
This PR is here to track feedback on the initial prototype so far. API, possible suggestions, etc are very welcome! The aim is to make this library a temporary companion to
arrow-core
until context receivers are fully released on every platform (so that there are no pre-release binaries). Pointers to APIs in Arrow or Kotlin Stdlib that would benefit from contexts are welcome as well.