Skip to content

Commit d06b579

Browse files
authored
Merge pull request #382 from TysonMN/381_fix
Fix bug preventing rendering of reports containing None
2 parents 44bfe70 + f01d072 commit d06b579

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Version 0.12.0
22

33
- Add Property.failOnFalse ([#380][380], [@TysonMN][TysonMN])
4+
- Fix bug [#381][381] that prevents rendering of reports containing `None` ([#382][382], [@TysonMN][TysonMN])
45

56
## Version 0.11.0 (2021-09-22)
67

@@ -175,6 +176,10 @@
175176
[porges]:
176177
https://github.com/porges
177178

179+
[382]:
180+
https://github.com/hedgehogqa/fsharp-hedgehog/pull/382
181+
[381]:
182+
https://github.com/hedgehogqa/fsharp-hedgehog/pull/381
178183
[380]:
179184
https://github.com/hedgehogqa/fsharp-hedgehog/pull/380
180185
[363]:

src/Hedgehog/Property.fs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,16 @@ module Property =
109109
#if FABLE_COMPILER
110110
value
111111
#else
112-
let t = value.GetType()
113-
// have to use TypeInfo due to targeting netstandard 1.6
114-
let t = System.Reflection.IntrospectionExtensions.GetTypeInfo(t)
115-
let isList = t.IsGenericType && t.GetGenericTypeDefinition() = typedefof<ResizeArray<_>>
116-
if isList
117-
then value :?> System.Collections.IEnumerable |> Seq.cast<obj> |> List.ofSeq :> obj
118-
else value
112+
if value = null then
113+
value
114+
else
115+
let t = value.GetType()
116+
// have to use TypeInfo due to targeting netstandard 1.6
117+
let t = System.Reflection.IntrospectionExtensions.GetTypeInfo(t)
118+
let isList = t.IsGenericType && t.GetGenericTypeDefinition() = typedefof<ResizeArray<_>>
119+
if isList
120+
then value :?> System.Collections.IEnumerable |> Seq.cast<obj> |> List.ofSeq :> obj
121+
else value
119122
#endif
120123

121124
value |> prepareForPrinting |> sprintf "%A"

tests/Hedgehog.Tests/PropertyTests.fs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,13 @@ let propertyTests = testList "Property tests" [
5151
#else
5252
Expect.stringContains report guid "Missing counterexample text"
5353
#endif
54+
55+
testCase "Report containing None renders without throwing an exception" <| fun () ->
56+
property {
57+
let! opt = Gen.constant () |> Gen.option
58+
return opt.IsSome
59+
}
60+
|> Property.report
61+
|> Report.render
62+
|> ignore
5463
]

0 commit comments

Comments
 (0)