Files
speckle.xunit.runner.wpf/xunit.runner.worker/RunUtil.cs
T
Jared Parsons d032f3e16d Don't use AppDomains
This is unnecessary overhead in the worker and makes the runner
significantly harder to debug.
2015-08-19 13:57:42 -07:00

78 lines
2.5 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using xunit.runner.data;
using Xunit;
using Xunit.Abstractions;
namespace xunit.runner.worker
{
internal sealed class RunUtil
{
private class TestRunVisitor : TestMessageVisitor<ITestAssemblyFinished>
{
private readonly BinaryWriter _writer;
private bool _continue = true;
public TestRunVisitor(BinaryWriter writer)
{
_writer = writer;
}
private void Process(string displayName, TestState state)
{
Console.WriteLine($"{state} - {displayName}");
var result = new TestResultData(displayName, state);
try
{
result.WriteTo(_writer);
}
catch (Exception ex)
{
// This happens during a rude shutdown from the client.
Console.Error.WriteLine(ex.Message);
_continue = false;
}
}
protected override bool Visit(ITestFailed testFailed)
{
Process(testFailed.TestCase.DisplayName, TestState.Failed);
return _continue;
}
protected override bool Visit(ITestPassed testPassed)
{
Process(testPassed.TestCase.DisplayName, TestState.Passed);
return _continue;
}
protected override bool Visit(ITestSkipped testSkipped)
{
Process(testSkipped.TestCase.DisplayName, TestState.Skipped);
return _continue;
}
}
internal static void Go(string assemblyPath, Stream stream)
{
using (AssemblyHelper.SubscribeResolve())
using (var xunit = new XunitFrontController(
assemblyFileName: assemblyPath,
useAppDomain: false,
shadowCopy: false,
diagnosticMessageSink: new MessageVisitor()))
using (var writer = new BinaryWriter(stream, Constants.Encoding, leaveOpen: true))
using (var testRunVisitor = new TestRunVisitor(writer))
{
xunit.RunAll(testRunVisitor, TestFrameworkOptions.ForDiscovery(), TestFrameworkOptions.ForExecution());
testRunVisitor.Finished.WaitOne();
}
}
}
}