Skip to content

Commit

Permalink
Add FsCheck.Xunit.TestOutputRunner.
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtschelfthout committed Aug 31, 2021
1 parent 1b82d77 commit d57ba75
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/FsCheck.Xunit/FsCheck.Xunit.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="Runner.fs" />
<Compile Include="PropertyAttribute.fs" />
<Compile Include="CheckExtensions.fs" />
</ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion src/FsCheck.Xunit/PropertyAttribute.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ open System
open System.Reflection
open System.Threading.Tasks

open FsCheck
open Xunit
open Xunit.Sdk
open Xunit.Abstractions

open FsCheck

type PropertyFailedException =
inherit Exception
new (testResult:FsCheck.TestResult) = {
Expand Down
20 changes: 20 additions & 0 deletions src/FsCheck.Xunit/Runner.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace FsCheck.Xunit

open FsCheck

/// A runner for FsCheck (i.e. that you can use as Config.Runner) which outputs
/// to Xunit's given ITestOutputHelper.
/// For example, { Config.QuickThrowOnFailure with Runner = TestOutputRunner(output) }
type TestOutputRunner(output: Xunit.Abstractions.ITestOutputHelper) =
interface IRunner with
member _.OnStartFixture t =
output.WriteLine (Runner.onStartFixtureToString t)
member _.OnArguments (ntest, args, every) =
output.WriteLine (every ntest args)
member _.OnShrink(args, everyShrink) =
output.WriteLine (everyShrink args)
member _.OnFinished(name,testResult) =
let resultText = Runner.onFinishedToString name testResult
match testResult with
| TestResult.True _ -> resultText |> output.WriteLine
| _ -> failwithf "%s" resultText

0 comments on commit d57ba75

Please sign in to comment.