Sigh, probably not worth it

This commit is contained in:
Smaug123
2024-06-23 19:16:20 +01:00
parent c09eb93b5e
commit 71d340d33a
3 changed files with 21 additions and 2 deletions

View File

@@ -7,8 +7,9 @@ open NUnit.Framework
module TestContext =
[<TestCase 3>]
let ``Context has appropriate values`` (_ : int) =
TestContext.Progress.WriteLine "hi!"
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"
@@ -22,4 +23,5 @@ module 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)));