Merge stamps and labels in And/Or property combinators #729
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When combining properties with
.&.(And) or.|.(Or), only the left operand's statistics (collect,classify) and labels were propagated. This made it impossible to see test data distribution for both sides of a combined property.Example
Changes
Result.ResAnd/ResOr: MergeStampandLabelswhen both sides have the same outcome (both Passed or both Failed)Result.MergeStampsAndLabels: Extract merge logic to avoid duplicationMerging on failure ensures that when multiple sub-properties fail, all their labels are visible in the error output, improving debuggability.
Original prompt
This section details on the original issue you should resolve
<issue_title>Using
CollectandClassifyin conjunction withAndorOr</issue_title><issue_description>Hello,
When I try to
collectand /orclassifytwo or more properties only the left hand side of theandororoperator seems to propagate its statistics.I am not sure if this is a bug or intended behavior?
Using FsCheck
2.16.5.Output:
If I add a failing prop3
1 = 3, the correct label is shown:Output:
But this happens probably because it 'fails fast'.
</issue_description>
<agent_instructions>Read the issue carefully - should be relatively straightforward to fix. Add tests.</agent_instructions>
Comments on the Issue (you are @copilot in this section)
@kurtschelfthout Hm yes good point. Probably a bug here:https://github.com/fscheck/FsCheck/blob/master/src/FsCheck/Testable.fs#L22
Some (all?) of those match arms should merge labels. (labels is where things like
collectandclassifyadd a string per test case)</comment_new><comment_new>@kurtschelfthout
Yes, that sounds right.</comment_new>
<comment_new>@kurtschelfthout
I think we should merge in all cases, including or. One use of these stats is determining what sort of data coverage generator and tests are getting. since FsCheck is not short circuiting, we shouldn’t pretend it is. On 4 Mar 2025, at 23:35, Calum Sieppert @.***> wrote:
How about this
--- a/src/FsCheck/Testable.fs
+++ b/src/FsCheck/Testable.fs
@@ -21,23 +21,26 @@ open FsCheck.Internals
{ Outcome : Outcome
Stamp : list
Labels : Set
Arguments : list }
///Returns a new result that is Passed if and only if both this
///and the given Result are Passed.
static member internal ResAnd(l, r) =
match (l.Outcome,r.Outcome) with
| (Outcome.Failed ,) -> l //here a potential Failed in r is thrown away...
| (_,Outcome.Failed _) -> r
match (l.Outcome, r.Outcome) with
| (Outcome.Failed ,) -> r
| (,Outcome.Failed ) -> l
| (Outcome.Passed,) -> l
| (,Outcome.Passed) -> r
| (Outcome.Rejected,Outcome.Rejected) -> l //or r, whatever
I don't think OR needs any change, the current code should keep the stamps from the first passing property, which I think would be the desired behaviour, to mimic short-circuiting?—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>
rynoV left a comment (#629)
How about this
--- a/src/FsCheck/Testable.fs
+++ b/src/FsCheck/Testable.fs
...
CollectandClassifyin conjunction withAndorOr#629💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.