From 812903d0780feb256615457a4bea47d96fa105e9 Mon Sep 17 00:00:00 2001 From: Tyson Williams Date: Thu, 18 Nov 2021 20:00:56 -0600 Subject: [PATCH 1/2] Add test that fails when trying to print None (i.e. null) #381 --- tests/Hedgehog.Tests/PropertyTests.fs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/Hedgehog.Tests/PropertyTests.fs b/tests/Hedgehog.Tests/PropertyTests.fs index 66041a5a..125a97e7 100644 --- a/tests/Hedgehog.Tests/PropertyTests.fs +++ b/tests/Hedgehog.Tests/PropertyTests.fs @@ -51,4 +51,13 @@ let propertyTests = testList "Property tests" [ #else Expect.stringContains report guid "Missing counterexample text" #endif + + testCase "Report containing None renders without throwing an exception" <| fun () -> + property { + let! opt = Gen.constant () |> Gen.option + return opt.IsSome + } + |> Property.report + |> Report.render + |> ignore ] From f01d072e9a4221b9c27efe37ecf738c7a1d0164f Mon Sep 17 00:00:00 2001 From: Tyson Williams Date: Thu, 18 Nov 2021 20:04:49 -0600 Subject: [PATCH 2/2] Fix bug preventing rendering of reports containing None #381 --- CHANGELOG.md | 5 +++++ src/Hedgehog/Property.fs | 17 ++++++++++------- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dad3368e..1ca87bba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## Version 0.12.0 - Add Property.failOnFalse ([#380][380], [@TysonMN][TysonMN]) +- Fix bug [#381][381] that prevents rendering of reports containing `None` ([#382][382], [@TysonMN][TysonMN]) ## Version 0.11.0 (2021-09-22) @@ -175,6 +176,10 @@ [porges]: https://github.com/porges +[382]: + https://github.com/hedgehogqa/fsharp-hedgehog/pull/382 +[381]: + https://github.com/hedgehogqa/fsharp-hedgehog/pull/381 [380]: https://github.com/hedgehogqa/fsharp-hedgehog/pull/380 [363]: diff --git a/src/Hedgehog/Property.fs b/src/Hedgehog/Property.fs index ee75890d..20004775 100644 --- a/src/Hedgehog/Property.fs +++ b/src/Hedgehog/Property.fs @@ -109,13 +109,16 @@ module Property = #if FABLE_COMPILER value #else - let t = value.GetType() - // have to use TypeInfo due to targeting netstandard 1.6 - let t = System.Reflection.IntrospectionExtensions.GetTypeInfo(t) - let isList = t.IsGenericType && t.GetGenericTypeDefinition() = typedefof> - if isList - then value :?> System.Collections.IEnumerable |> Seq.cast |> List.ofSeq :> obj - else value + if value = null then + value + else + let t = value.GetType() + // have to use TypeInfo due to targeting netstandard 1.6 + let t = System.Reflection.IntrospectionExtensions.GetTypeInfo(t) + let isList = t.IsGenericType && t.GetGenericTypeDefinition() = typedefof> + if isList + then value :?> System.Collections.IEnumerable |> Seq.cast |> List.ofSeq :> obj + else value #endif value |> prepareForPrinting |> sprintf "%A"