Worker can now run tests
This commit is contained in:
@@ -10,5 +10,7 @@ namespace xunit.runner.data
|
||||
{
|
||||
public const string PipeName = "xunit.runners.pipe";
|
||||
public const string ActionDiscover = "discover";
|
||||
public const string ActionRun = "run";
|
||||
public static readonly Encoding Encoding = Encoding.UTF8;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace xunit.runner.data
|
||||
{
|
||||
public enum TestState
|
||||
{
|
||||
Passed,
|
||||
Failed,
|
||||
Skipped
|
||||
}
|
||||
|
||||
public sealed class TestResultData
|
||||
{
|
||||
public string TestCaseDisplayName { get; set; }
|
||||
public TestState TestState { get; set; }
|
||||
|
||||
public TestResultData(string displayName, TestState state)
|
||||
{
|
||||
TestCaseDisplayName = displayName;
|
||||
TestState = state;
|
||||
}
|
||||
|
||||
public static TestResultData ReadFrom(BinaryReader reader)
|
||||
{
|
||||
var displayName = reader.ReadString();
|
||||
var state = (TestState)reader.ReadInt32();
|
||||
return new TestResultData(displayName, state);
|
||||
}
|
||||
|
||||
public void WriteTo(BinaryWriter writer)
|
||||
{
|
||||
writer.Write(TestCaseDisplayName);
|
||||
writer.Write((int)TestState);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,7 @@
|
||||
<Compile Include="Constants.cs" />
|
||||
<Compile Include="TestCaseData.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="TestResultData.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
||||
@@ -36,20 +36,13 @@ namespace xunit.runner.worker
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class DiagnosticMessageVisitor : TestMessageVisitor
|
||||
{
|
||||
public override bool OnMessage(IMessageSinkMessage message)
|
||||
{
|
||||
return base.OnMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Go(string fileName, Stream stream)
|
||||
{
|
||||
using (AssemblyHelper.SubscribeResolve())
|
||||
using (var xunit = new XunitFrontController(
|
||||
useAppDomain: true,
|
||||
assemblyFileName: fileName,
|
||||
diagnosticMessageSink: new DiagnosticMessageVisitor(),
|
||||
diagnosticMessageSink: new MessageVisitor(),
|
||||
shadowCopy: false))
|
||||
using (var writer = new BinaryWriter(stream, Encoding.UTF8, leaveOpen: true))
|
||||
using (var impl = new Impl(xunit, writer))
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
namespace xunit.runner.worker
|
||||
{
|
||||
internal sealed class MessageVisitor : TestMessageVisitor
|
||||
{
|
||||
public override bool OnMessage(IMessageSinkMessage message)
|
||||
{
|
||||
return base.OnMessage(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,30 +22,47 @@ namespace xunit.runner.worker
|
||||
return ExitError;
|
||||
}
|
||||
|
||||
switch (args[0])
|
||||
Stream stream = null;
|
||||
try
|
||||
{
|
||||
case Constants.ActionDiscover:
|
||||
Discover(args[1]);
|
||||
break;
|
||||
default:
|
||||
Usage();
|
||||
return ExitError;
|
||||
var namedPipeServerStream = new NamedPipeServerStream(Constants.PipeName);
|
||||
namedPipeServerStream.WaitForConnection();
|
||||
stream = namedPipeServerStream;
|
||||
|
||||
switch (args[0])
|
||||
{
|
||||
case Constants.ActionDiscover:
|
||||
Discover(stream, args[1]);
|
||||
break;
|
||||
case Constants.ActionRun:
|
||||
Run(stream, args[1]);
|
||||
break;
|
||||
default:
|
||||
Usage();
|
||||
return ExitError;
|
||||
}
|
||||
|
||||
}
|
||||
finally
|
||||
{
|
||||
stream.Close();
|
||||
}
|
||||
|
||||
return ExitSuccess;
|
||||
}
|
||||
|
||||
private static void Discover(string assemblyPath)
|
||||
private static void Discover(Stream stream, string assemblyPath)
|
||||
{
|
||||
using (var namedPipeServer = new NamedPipeServerStream(Constants.PipeName))
|
||||
{
|
||||
namedPipeServer.WaitForConnection();
|
||||
Console.WriteLine($"discover started: {assemblyPath}");
|
||||
DiscoverUtil.Go(assemblyPath, namedPipeServer);
|
||||
DiscoverUtil.Go(assemblyPath, stream);
|
||||
Console.WriteLine("discover ended");
|
||||
namedPipeServer.Close();
|
||||
Console.WriteLine("pipe closed");
|
||||
}
|
||||
}
|
||||
|
||||
private static void Run(Stream stream, string assemblyPath)
|
||||
{
|
||||
Console.WriteLine($"run started: {assemblyPath}");
|
||||
RunUtil.Go(assemblyPath, stream);
|
||||
Console.WriteLine("run ended");
|
||||
}
|
||||
|
||||
private static void Usage()
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
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;
|
||||
|
||||
public TestRunVisitor(BinaryWriter writer)
|
||||
{
|
||||
_writer = writer;
|
||||
}
|
||||
|
||||
private void Process(string displayName, TestState state)
|
||||
{
|
||||
var result = new TestResultData(displayName, state);
|
||||
result.WriteTo(_writer);
|
||||
}
|
||||
|
||||
protected override bool Visit(ITestFailed testFailed)
|
||||
{
|
||||
Process(testFailed.TestCase.DisplayName, TestState.Failed);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool Visit(ITestPassed testPassed)
|
||||
{
|
||||
Process(testPassed.TestCase.DisplayName, TestState.Passed);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool Visit(ITestSkipped testSkipped)
|
||||
{
|
||||
Process(testSkipped.TestCase.DisplayName, TestState.Skipped);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Go(string assemblyPath, Stream stream)
|
||||
{
|
||||
using (AssemblyHelper.SubscribeResolve())
|
||||
using (var xunit = new XunitFrontController(
|
||||
assemblyFileName: assemblyPath,
|
||||
useAppDomain: true,
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,8 +50,10 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DiscoverUtil.cs" />
|
||||
<Compile Include="MessageVisitor.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RunUtil.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
|
||||
Reference in New Issue
Block a user