-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add TaskSeq.takeWhile
, takeWhileAsync
, takeWhileInclusive
, takeWhileInclusiveAsync
#126
Conversation
4f79c0e
to
b6cbd79
Compare
c514766
to
463aaae
Compare
Remaining question is how/whether to cover the Immutability/Side-effecting aspects for the Inclusive variants Seriously though, rather than duplicating L99-135 with Don't really have other ideas as to how to cover both variants beyond either |
Thanks for this! What I usually do for testing side-effects where the "run all elements" doesn't suffice, is to just add something like: [<Fact>]
let myTest() =
let mutable x = 0
let ts = taskSeq {
x <- x + 1
yield x
x <- x + 1 // ensure we don't execute this
yield x
}
let res = TaskSeq.takeWhileInclusive (fun _ -> false)
x |> should equal 1
res |> TaskSeq.exactlyOne |> should equal 1
} And: [<Fact>]
let myTest() =
let mutable x = 0
let ts = taskSeq {
x <- x + 1
yield x
x <- x + 1
yield x
}
let res = TaskSeq.takeWhile(fun _ -> false)
x |> should be 1
res |> TaskSeq.isEmpty |> should be 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.
Great work, I like it that you're following the same patterns that were there. Thanks for this. See my comments below. Nothing major:
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.
One more nit:
I have not looked at the rest of the test codebase enough to make a full call on this so would appreciate your candid response (tbh the FsUnit style stuff is not something I'm well versed in - I tend to use unquote and computation expressions only for my tests)... I could revisit the tests to do side-effecting of counters/markers and validating the presence/absence of same in line with your suggestion instead of having the exceptions acting as guards. Happy to do a reorg to follow house style (or only final tweaks based on staying with the throwing) based on your call. |
I'm ok with everything so far, I can add the mutability tests (just before/after what's supposed to be yielded) myself as well. The A simple example of what I mean can be found in the House style: I think you pretty much nailed that one already! :) And some variation in style w.r.t. tests is never problematic. Using unquote: this code relies heavily on resumable code, valuetasks, tasks and asyncs, and unless it is fixed now, |
9ba564d
to
6ddf16e
Compare
Good suggestions; added tests that I hope cover the intent sufficiently. Happy to tweak re any comments you may have, but equally happy if you want to express it as a commit and/or fix it afterwards.
I was referring more to the use of unquote to express the assertions, in lieu of the matcher stuff. In general I'd have any use of Task/Async and such elements confined to the Act phase so I believe your main concern would not arise. Examples of the benefits of that would be
In short, I believe Unquote's assertions provide a balance of properties that would suit a project like this:-
Articles:
I appreciate that having >1 assertion DSLs in a project is not a good idea, so definitely another day's discussion |
7d1d52b
to
86c4adc
Compare
I've used Unquote with (rambling: this is a high-end library with lots of cutting edge code that only few programmers will be able to actually modify/maintain, notably the CE stuff, so using a low-end lib for testing doesn't really add anything: people working on this will have been around the block) Since we're slowly moving out of the prototype phase, I may actually rewrite tests in Unquote at some point. Whether it'll really be more concise in the long run, I don't know. FYI: Currently, running all tests in CI takes some 10 min. Locally around 1 min (in parallel). This is in part because there are deliberate delays to force the "thread yield" behavior. Otherwise, the tests wouldn't really test any thread-switching and all Appreciate your thoughts, always good to share insights. I'll have a moment later today to go over your changes, thanks! |
Yes, saw a thread in the FSSF Slack immediately after that makes that abundantly clear, sorry for getting the wrong end of the stick I would not expect unquote to make the assertions all that more concise.
True (though I tend to sidestep using stuff other than xunit and unquote) I personally have not run into FsUnit for ages, but it really does depend on where you look. There's definitely plenty higher value things than esp you can do than porting assertions to unquote. If you make a task for it, you might tempt me on one of these dark winter nights, but again: I doubt it's a true deal breaker for contributions to this repo. However I won't bring it up again unless you signal desire by doing that ;) |
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.
Excellent work, thanks for this! I'll make a few final tweaks, see my comments below, and merge it in. Hope that's ok with you (that I hijack your PR a little bit).
Async.takeWhile
, takeWhileAsync
, takeWhileInclusive
, takeWhileInclusiveAsync
…t function-choice is now lifted
…, and remove a few branching tests
…red by all four new functions
@bartelink I made a few changes, see above. If you are ok with these, I'll go ahead and merge it in. |
Changes look great, go for the merge (though note the |
Yep, agreed. Will be part of a revamp of the tests in general. |
@bartelink thanks for all your work and patience with this, it is much appreciated! Will be part of the next version of |
Thanks! No rush of any kind on the release (but I'll definitely use it when it hits nuget) |
Async.takeWhile
, takeWhileAsync
, takeWhileInclusive
, takeWhileInclusiveAsync
TaskSeq.takeWhile
, takeWhileAsync
, takeWhileInclusive
, takeWhileInclusiveAsync
Fixes: #122 (edit: see also #235)
takeWhileInclusive
takeWhileInclusive(Async)?
wrt Immutability/Side effects ?