Skip to content

Commit

Permalink
Update xunit and fix #682.
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtschelfthout committed Jan 2, 2025
1 parent 00ab875 commit 2eb1cf5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
<PackageVersion Include="xunit.core" Version="[2.4.1, 3.0.0)" />
<PackageVersion Include="xunit.extensibility.core" Version="[2.4.1, 3.0.0)" />
<PackageVersion Include="xunit.extensibility.execution" Version="[2.4.1, 3.0.0)" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.7" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
<PackageReference Include="xunit.runner.visualstudio">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FSharp.Core" />
</ItemGroup>
</Project>
21 changes: 16 additions & 5 deletions src/FsCheck.Xunit/PropertyAttribute.fs
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,22 @@ type PropertyTestCase(diagnosticMessageSink:IMessageSink, defaultMethodDisplay:T
override this.RunAsync(diagnosticMessageSink:IMessageSink, messageBus:IMessageBus, constructorArguments:obj [], aggregator:ExceptionAggregator, cancellationTokenSource:Threading.CancellationTokenSource) =
let test = XunitTest(this, this.DisplayName)
let summary = RunSummary(Total = 1);
let outputHelper =
constructorArguments
|> Array.tryFind (fun x -> x :? TestOutputHelper)
|> Option.map (fun x -> x :?> TestOutputHelper)
|> Option.defaultValue (new TestOutputHelper())

// 1. We always need an initialized TestOutputHelper so we can write output.
// 2. xunit supports test classes that have a constructor that takes a TestOutputHelper, which we need to pass along.
// xunit has two different ways of passing us the TestOutputHelper.
// pre-2.9.0: as a TestOutputHelper constructor argument
// post-2.9.0: as a Func<TestOutputHelper> constructor argument https://github.com/xunit/xunit/issues/2996#issuecomment-2271764192
// The below code handles both cases.
let mutable outputHelper = TestOutputHelper()
for i in 0..constructorArguments.Length-1 do
match constructorArguments[i] with
| :? TestOutputHelper as foundHelper ->
outputHelper <- foundHelper
| :? Func<TestOutputHelper> as foundHelperFunc ->
outputHelper <- foundHelperFunc.Invoke()
constructorArguments.[i] <- outputHelper
| _ -> ()
outputHelper.Initialize(messageBus, test)

let dispose testClass =
Expand Down

0 comments on commit 2eb1cf5

Please sign in to comment.