-
Notifications
You must be signed in to change notification settings - Fork 70
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
limiting liftIO for better testing #172
Comments
I think that the fact that things like reactimate :: MonadFramework m => Event (IO ()) -> m () or something. My suggestion is to change all |
@ocharles Would you accept a patch that made this change? If so, I'm happy to help. |
I would, but I would like @HeinrichApfelmus to review before applying. Maybe it's worth having him confirm my API is sensible. @joeyh, would my proposed API work for you? |
I think the trouble with replacing the concrete data type If I understand the issue correctly, this is mainly about testing. When designing the library, I thought that testing should be done on pure combinators only, using |
Perhaps I'm missing a way to use interpret. I am using combinators like
accumB that operate in MonadMoment, and connecting them up to multiple
Event sources obtained with fromAddHandler, which is MomentIO, and I want to
test with a given sequence of events and check that the Behavior always
does the right thing.
An example of what I'm doing is here:
http://hackage.haskell.org/package/reactive-banana-automation-0.5.0/docs/Reactive-Banana-Automation.html#t:Automation
and testing it here:
http://hackage.haskell.org/package/reactive-banana-automation-0.5.0/docs/Reactive-Banana-Automation.html#v:observeAutomation
I don't see a way to use interpret to test a MonadMoment or MomentIO
computation. I could use interpretFrameworks, but it allows IO side effects
in the Behavior being tested.
…--
see shy jo
|
Code in MomentIO can liftIO so there's no good way to mock out the IO parts for testing it.
In my reactive-banana-automation library, I found it useful to wrap MomentIO, producing a MomentAutomation monad that is not an instance of MonadIO. Thus the IO is limited to a few wrapper functions around fromAddHandler, reactimate, stepper, and changes. That allows me to run code like this, and know that it has no external dependencies and should give the same result each time (barring something unexpected in those IO actions).
I'm not sure how well-founded my hope is that this lets me reproducibly test a reactive-banana event network?
Anyway, I think it would be great if reactive-banana had a limited monad like my MomentAutomation to allow fully mocked testing of event networks like this.
The text was updated successfully, but these errors were encountered: