Skip to content

Commit

Permalink
recheck runs once passes
Browse files Browse the repository at this point in the history
resolves #7
  • Loading branch information
dharmaturtle committed Jul 31, 2022
1 parent baf1c58 commit bd81548
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/Hedgehog.Xunit/Exceptions.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Hedgehog.Xunit

// This exists to make it clear to users that the exception is in the return of their test.
// Raising System.Exception isn't descriptive enough.
// Using Xunit.Assert.True could be confusing since it may resemble a user's assertion.
type internal TestReturnedFalseException() =
inherit System.Exception("Test returned `false`.")
1 change: 1 addition & 0 deletions src/Hedgehog.Xunit/Hedgehog.Xunit.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Docs at https://github.com/dharmaturtle/fsharp-hedgehog-xunit
</ItemGroup>

<ItemGroup>
<Compile Include="Exceptions.fs" />
<Compile Include="Attributes.fs" />
<Compile Include="InternalLogic.fs" />
<Compile Include="XunitOverrides.fs" />
Expand Down
6 changes: 3 additions & 3 deletions src/Hedgehog.Xunit/InternalLogic.fs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ open System.Linq

let rec toProperty (x: obj) =
match x with
| :? bool as b -> Property.ofBool b
| :? bool as b -> if not b then TestReturnedFalseException() |> raise
| :? Task<unit> as t -> Async.AwaitTask t |> toProperty
| _ when x <> null && x.GetType().IsGenericType && x.GetType().GetGenericTypeDefinition().IsSubclassOf typeof<Task> ->
typeof<Async>
Expand All @@ -115,7 +115,7 @@ let rec toProperty (x: obj) =
.MakeGenericMethod(x.GetType().GetGenericArguments())
.Invoke(null, [|x|])
|> toProperty
| _ -> Property.success ()
| _ -> ()

let dispose (o:obj) =
match o with
Expand Down Expand Up @@ -166,7 +166,7 @@ let report (testMethod:MethodInfo) testClass testClassInstance =
PropertyConfig.defaultConfig
|> withTests tests
|> withShrinks shrinks
Property.forAll invoke gens
PropertyBuilder.property.BindReturn(gens, invoke)
|> match recheck with
| Some recheckData -> Property.reportRecheckWith recheckData config
| None -> Property.reportWith config
Expand Down
6 changes: 4 additions & 2 deletions tests/Hedgehog.Xunit.Tests/PropertyTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,9 @@ module ``tryRaise tests`` =
let report = InternalLogic.report (nameof ``always fails, skipped`` |> getMethod) typeof<Marker>.DeclaringType null
let actual = Assert.Throws<Exception>(fun () -> InternalLogic.tryRaise report)
let expectedMessage = """*** Failed! Falsifiable (after 1 test):
[]
[]"""
actual.Message.Contains(expectedMessage) |> Assert.True
let expectedMessage = """
This failure can be reproduced by running:
> Property.recheck "0_"""
actual.Message.StartsWith(expectedMessage) |> Assert.True
actual.Message.Contains(expectedMessage) |> Assert.True

0 comments on commit bd81548

Please sign in to comment.