You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The behavior added in #634 to address #633 feels confusing to me when contrasted with the behavior of tests that return Task<bool>, especially for xUnit/NUnit tests annotated with PropertyAttribute.
That is:
Tests marked with PropertyAttribute that return boolfail when the bool is false.
Tests marked with PropertyAttribute that return Task<bool>fail when the bool is false.
Tests marked with PropertyAttribute that return Propertyfail when the Property is falsy.
Tests marked with PropertyAttribute that return Task<Property>pass when the Property is falsy.
I would expect 4 to fail just as 1–3 do.
// Fails as expected.[Property]publicboolTest(boolb)=>b&&!b;// Fails as expected.[Property]publicPropertyTest(boolb)=>Prop.Label(b&&!b,"Some label.");// Fails as expected.[Property]publicTask<bool>Test(boolb)=>Task.FromResult(b&&!b);// Passes. I would expect this to fail.[Property]publicTask<Property>Test(boolb)=>Task.FromResult(Prop.Label(b&&!b,"Some label."));// Passes. I would expect this to fail.[Property]publicTask<Property>Test(boolb)=>Task.FromResult(Prop.ToProperty(b).And(!b));
// Fails as expected.[<Property>]lettest1 b =
b &¬ b
// Fails as expected.[<Property>]lettest2 b =(b &¬ b)|> Prop.label "Some label."// Fails as expected.[<Property>]lettest3 b =
Task.FromResult (b &¬ b)// Passes. I would expect this to fail.[<Property>]lettest4 b =
Task.FromResult ((b &¬ b)|> Prop.label "Some label.")// Passes. I would expect this to fail.[<Property>]lettest5 b =
Task.FromResult (b .&.not b)
I understand the original desire not to need to explicitly upcast Task<unit> to Task, but the difference in treatment between Task<bool> and Task<Property> is dangerous, because it is far too easy to write a test that returns Task<Property> and have it pass for the wrong reason.
That is, a developer might expect the test to fail if the Property inside the returned Task<Property> was falsy, just as such a test would fail for a false or falsy bool, Task<bool>, or Property — but the test returning Task<Property> would actually always pass as long as no exceptions were thrown.
Is there is any chance we could make Task<Property> behave like Task<bool> and Property here? Or, ideally, Task<'T> when 'T is testable behave like 'T?
Sounds very reasonable to me. I think that would amount to not upcasting to Task in testable, and writing a Prop.ofTaskT which also looks at the result of the Task<T> to determine test outcome.
The behavior added in #634 to address #633 feels confusing to me when contrasted with the behavior of tests that return
Task<bool>
, especially for xUnit/NUnit tests annotated withPropertyAttribute
.That is:
PropertyAttribute
that returnbool
fail when thebool
isfalse
.PropertyAttribute
that returnTask<bool>
fail when thebool
isfalse
.PropertyAttribute
that returnProperty
fail when theProperty
is falsy.PropertyAttribute
that returnTask<Property>
pass when theProperty
is falsy.I would expect 4 to fail just as 1–3 do.
I understand the original desire not to need to explicitly upcast
Task<unit>
toTask
, but the difference in treatment betweenTask<bool>
andTask<Property>
is dangerous, because it is far too easy to write a test that returnsTask<Property>
and have it pass for the wrong reason.That is, a developer might expect the test to fail if the
Property
inside the returnedTask<Property>
was falsy, just as such a test would fail for afalse
or falsybool
,Task<bool>
, orProperty
— but the test returningTask<Property>
would actually always pass as long as no exceptions were thrown.Is there is any chance we could make
Task<Property>
behave likeTask<bool>
andProperty
here? Or, ideally,Task<'T>
when'T
is testable behave like'T
?I'd be willing to open a PR.
CC @ploeh, @kurtschelfthout.
The text was updated successfully, but these errors were encountered: