Skip to content

Commit

Permalink
Merge pull request #382 from TysonMN/381_fix
Browse files Browse the repository at this point in the history
Fix bug preventing rendering of reports containing None
  • Loading branch information
TysonMN authored Nov 19, 2021
2 parents 44bfe70 + f01d072 commit d06b579
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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]:
Expand Down
17 changes: 10 additions & 7 deletions src/Hedgehog/Property.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ResizeArray<_>>
if isList
then value :?> System.Collections.IEnumerable |> Seq.cast<obj> |> 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<ResizeArray<_>>
if isList
then value :?> System.Collections.IEnumerable |> Seq.cast<obj> |> List.ofSeq :> obj
else value
#endif

value |> prepareForPrinting |> sprintf "%A"
Expand Down
9 changes: 9 additions & 0 deletions tests/Hedgehog.Tests/PropertyTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
]

0 comments on commit d06b579

Please sign in to comment.