Compare commits

...

2 Commits

Author SHA1 Message Date
Smaug123
71d340d33a Sigh, probably not worth it 2024-06-23 19:16:20 +01:00
Smaug123
c09eb93b5e Add failing test 2024-06-23 18:40:27 +01:00
4 changed files with 45 additions and 0 deletions

View File

@@ -10,6 +10,7 @@
<Compile Include="NoAttribute.fs" />
<Compile Include="Inconclusive.fs" />
<Compile Include="RunSubProcess.fs" />
<Compile Include="TestContext.fs" />
<Compile Include="TestNonParallel.fs" />
<Compile Include="TestParallel.fs" />
<Compile Include="TestStdout.fs" />

27
Consumer/TestContext.fs Normal file
View File

@@ -0,0 +1,27 @@
namespace Consumer
open FsUnitTyped
open NUnit.Framework
[<TestFixture>]
module TestContext =
[<TestCase 3>]
let ``Context has appropriate values`` (i : int) =
// We explicitly cannot support this (https://github.com/dotnet/dotnet-api-docs/pull/3869/files).
// TestContext.Progress.WriteLine "hi!"
TestContext.CurrentContext.Test.MethodName
|> shouldEqual "Context has appropriate values"
TestContext.CurrentContext.Test.Name
|> shouldEqual "Context has appropriate values(3)"
TestContext.CurrentContext.Test.Namespace |> shouldEqual "Consumer"
TestContext.CurrentContext.Test.ClassName |> shouldEqual "Consumer.TestContext"
TestContext.CurrentContext.Test.FullName
|> shouldEqual "Consumer.TestContext.Context has appropriate values(3)"
i |> shouldEqual 3
TestContext.CurrentContext.Test.Arguments |> List.ofArray |> shouldEqual [ 3 ]

View File

@@ -14,3 +14,8 @@ However, we would recommend phrasing some of them differently, for maximum peace
WoofWare.NUnitTestRunner has *limited* support for parallelism.
By default, we run tests serially; we may or may not respect the NUnit parallelism attributes to any given extent (but we will never incorrectly run tests in parallel).
For example, as of this writing, we do not run any tests in parallel (but the internal infrastructure is set up so that we will be able to do this soon).
## `TestContext`
WoofWare.NUnitTestRunner has partial support for NUnit's `TestContext`.
See [the test file](./Consumer/TestContext.fs) for everything we expect to work.

View File

@@ -71,6 +71,18 @@ public class StartupHookLogic
using var contexts = TestContexts.Empty();
Console.SetOut(contexts.Stdout);
Console.SetError(contexts.Stderr);
var nunitAssembly = Assembly.Load("NUnit.Framework");
if (object.ReferenceEquals(nunitAssembly, null))
{
throw new Exception("Could not load NUnit.Framework");
}
var testContext = nunitAssembly.DefinedTypes.First(t => t.FullName == "NUnit.Framework.TestContext") ?? throw new Exception("Could not find TestContext type");
var currentContextField = testContext.GetField("CurrentContext", BindingFlags.Static | BindingFlags.Public) ?? throw new Exception("Could not find CurrentContext field on TestContext");
var currentContext = currentContextField.GetValue(null) ?? throw new Exception("Could not obtain value of CurrentContext");
currentContextField.SetValue(currentContext, currentContext);
var results =
Task.WhenAll(testFixtures.Select(x =>
TestFixtureModule.run(contexts, par, TestProgress.toWriter(normalErr), filter, x)));