diff --git a/src/Hedgehog.Xunit/InternalLogic.fs b/src/Hedgehog.Xunit/InternalLogic.fs index ddb20a2..44270ae 100644 --- a/src/Hedgehog.Xunit/InternalLogic.fs +++ b/src/Hedgehog.Xunit/InternalLogic.fs @@ -16,12 +16,6 @@ open System.Reflection open System open Hedgehog.Xunit -// https://github.com/dotnet/fsharp/blob/b9942004e8ba19bf73862b69b2d71151a98975ba/src/FSharp.Core/list.fs#L861-L865 -let listTryExactlyOne (list: _ list) = - match list with - | [ x ] -> Some x - | _ -> None - // https://github.com/dotnet/fsharp/blob/b9942004e8ba19bf73862b69b2d71151a98975ba/src/FSharp.Core/seqcore.fs#L172-L174 let inline checkNonNull argName arg = if isNull arg then @@ -118,17 +112,12 @@ let rec yieldAndCheckReturnValue (x: obj) = | :? Task as t -> Async.AwaitTask t |> yieldAndCheckReturnValue | :? Task as t -> Async.AwaitTask t |> yieldAndCheckReturnValue | _ when x <> null && x.GetType().IsGenericType && x.GetType().GetGenericTypeDefinition().IsSubclassOf typeof -> - let genType = x.GetType().GetGenericTypeDefinition() - if not genType.ContainsGenericParameters then - let t = x :?> Task - Async.AwaitTask t |> yieldAndCheckReturnValue - else - typeof - .GetMethods() - .First(fun x -> x.Name = "AwaitTask" && x.IsGenericMethod) - .MakeGenericMethod(x.GetType().GetGenericArguments()) - .Invoke(null, [|x|]) - |> yieldAndCheckReturnValue + typeof + .GetMethods() + .First(fun x -> x.Name = "AwaitTask" && x.IsGenericMethod) + .MakeGenericMethod(x.GetType().GetGenericArguments().First()) + .Invoke(null, [|x|]) + |> yieldAndCheckReturnValue | :? Task as t -> Async.AwaitTask t |> yieldAndCheckReturnValue | :? Async as a -> Async.RunSynchronously(a, cancellationToken = CancellationToken.None) |> yieldAndCheckReturnValue | _ when x <> null && x.GetType().IsGenericType && x.GetType().GetGenericTypeDefinition() = typedefof> -> @@ -162,30 +151,29 @@ let withShrinks = function let report (testMethod:MethodInfo) testClass testClassInstance = let getAttributeGenerator (parameterInfo: ParameterInfo) = - let attributes = parameterInfo.GetCustomAttributes() - if Seq.isEmpty attributes then - None - else - attributes - |> Seq.tryPick(fun x -> - let attType = x.GetType().BaseType - if attType.IsGenericType && attType.GetGenericTypeDefinition().IsAssignableFrom(typedefof>) then - let method = attType.GetMethods() |> Array.pick(fun x -> if x.Name = "Box" then Some x else None) - method.Invoke(x, null) :?> Gen |> Some - else - None - ) + parameterInfo.GetCustomAttributes() + |> Seq.tryPick(fun attr -> + let attrType = attr.GetType().BaseType + if attrType.IsGenericType && attrType.GetGenericTypeDefinition().IsAssignableFrom(typedefof>) then + attrType + .GetMethods() + .First(fun x -> x.Name = "Box") + .Invoke(attr, null) + :?> Gen |> Some + else + None + ) let config, tests, shrinks, recheck, size = parseAttributes testMethod testClass let gens = testMethod.GetParameters() |> Array.map (fun p -> match (getAttributeGenerator p, p.ParameterType.ContainsGenericParameters) with | (Some gen, _) -> gen - | (_ , true) -> Gen.constant Unchecked.defaultof<_> - | _ -> genxAutoBoxWithMethodInfo - .MakeGenericMethod(p.ParameterType) - .Invoke(null, [|config|]) - :?> Gen) + | (_ , true) -> Gen.constant Unchecked.defaultof<_> + | (_ , false) -> genxAutoBoxWithMethodInfo + .MakeGenericMethod(p.ParameterType) + .Invoke(null, [|config|]) + :?> Gen) |> List.ofArray |> ListGen.sequence let gens = diff --git a/tests/Hedgehog.Xunit.Tests.FSharp/PropertyTests.fs b/tests/Hedgehog.Xunit.Tests.FSharp/PropertyTests.fs index 995eae1..7ad469f 100644 --- a/tests/Hedgehog.Xunit.Tests.FSharp/PropertyTests.fs +++ b/tests/Hedgehog.Xunit.Tests.FSharp/PropertyTests.fs @@ -349,7 +349,7 @@ module ``Asynchronous tests`` = let ``Returning Task with exception fails, skipped`` (i: int) : Task = if i > 10 then Exception() |> Task.FromException - else Task.Delay 100 + else FooAsync() [] let ``Returning Task with exception fails`` () = assertShrunk (nameof ``Returning Task with exception fails, skipped``) "[11]" @@ -765,6 +765,12 @@ module ``GenAttribute Tests`` = let ``can restrict on range`` ([] i) = i >= 0 && i <= 5 + type OtherAttribute() = inherit Attribute() + + [] + let ``Doesn't error with OtherAttribute`` ([][] i) = + i = 5 + [)>] module ``GenAttribute with Properties Tests`` =