Skip to content
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

Support Async<'Testable> & Task<'Testable> #694

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

brianrourkeboll
Copy link

@brianrourkeboll brianrourkeboll commented Jan 20, 2025

@kurtschelfthout This is basically just the code from my comment here. Upon further thought and experimentation, I think it might actually be valid, if not terribly elegant—but perhaps there is something that I still do not understand and that the tests do not cover. It essentially hinges on whether what I am doing with Shrink.getValue inside of Gen.promote (after applying runner) is valid in all scenarios.

Fixes #684.1

  • Add support for Async<'Testable> and Task<'Testable> as first-class testables.

    That is, Async<'Testable> and Task<'Testable> are now valid testables for any valid instantiation of 'Testable, just as Lazy<'Testable>, Gen<'Testable>, or 'Generatable -> 'Testable already were.

    [<Property>]
    let ``Unit - used to pass, still passes`` () = ()
    
    [<Property>]
    let ``Task<unit> - used to pass, still passes`` () = task { return () }
    
    [<Property>]
    let ``Task - used to pass, still passes`` () = task { return () } :> Task
    
    [<Property>]
    let ``Async<unit> - used to pass, still passes`` () = async { return () }
    
    [<Property>]
    let ``Property - used to fail, still fails`` b = (b && not b) |> Prop.label "b && not b"
    
    [<Property>]
    let ``Task<Property> - used to pass, now fails`` b = task { return (b && not b) |> Prop.label "b && not b" }
    
    [<Property>]
    let ``Async<Property> - used to pass, now fails`` b = async { return (b && not b) |> Prop.label "b && not b" }
    
    [<Property>]
    let ``Task<Lazy<bool>> - used to pass, now fails`` b = task { return lazy b }
    
    // Etc.

Footnotes

  1. Note that this is technically a breaking change in that it breaks the example added in Enable properties that return Task<'a> #634. An explicit upcast to non-generic Task (… :> Task) will now be needed for tests involving Task<'T> where 'T is not itself a testable type to pass. This matches the behavior for the unwrapped equivalent:

    [<Property>]
    let ``An int is not a testable`` (i : int) = i
    // System.Exception: No instances of class FsCheck.Testable+ITestable`1[T] for type System.Int32
    
    [<Property>]
    let ``An Async<int> is now also not a testable`` (i : int) = async { return i }
    // System.Exception: No instances of class FsCheck.Testable+ITestable`1[T] for type System.Int32
    
    [<Property>]
    let ``A Task<int> is now also not a testable`` (i : int) = task { return i }
    // System.Exception: No instances of class FsCheck.Testable+ITestable`1[T] for type System.Int32
    

    The behavior originally desired in Allow asynchronous tests to run on Task<'a> #633 for Task<unit> is, however, kept: an upcast from Task<unit> to Task is not required, since unit is a testable type.

@brianrourkeboll brianrourkeboll marked this pull request as ready for review January 20, 2025 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

boolTask<bool>, PropertyTask<Property>
1 participant