Skip to content

Commit

Permalink
Collect code coverage, Stage 1
Browse files Browse the repository at this point in the history
  • Loading branch information
nxtn committed Dec 23, 2019
1 parent b9ab198 commit 85ec468
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 1 deletion.
82 changes: 81 additions & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,4 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>

<PropertyGroup>
<ServerHandleValue />
<ClientHandleValue />
</PropertyGroup>

<Target Name="BeforeCollectCodeCoverage" BeforeTargets="RunTests">
<BeforeCollectCodeCoverageTask TestAssembly="%(TestToRun.Identity)">
<Output TaskParameter="ServerHandleValue" PropertyName="ServerHandleValue" />
<Output TaskParameter="ClientHandleValue" PropertyName="ClientHandleValue" />
</BeforeCollectCodeCoverageTask>
</Target>

<Target Name="AfterCollectCodeCoverage" AfterTargets="RunTests">
<AfterCollectCodeCoverageTask ServerHandleValue="$(ServerHandleValue)" ClientHandleValue="$(ClientHandleValue)" />
</Target>

<UsingTask
TaskName="BeforeCollectCodeCoverageTask"
TaskFactory="RoslynCodeTaskFactory"
AssemblyName="Microsoft.Build.Tasks.Core">

<ParameterGroup>
<TestAssembly ParameterType="System.String" Required="true" />
<ServerHandleValue ParameterType="System.Int64" Output="true" />
<ClientHandleValue ParameterType="System.Int64" Output="true" />
</ParameterGroup>

<Task>
<Using Namespace="System.Diagnostics" />
<Using Namespace="System.IO" />
<Using Namespace="System.IO.Pipes" />
<Using Namespace="Microsoft.Win32.SafeHandles" />
<Code>
using var server = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable);

ServerHandleValue = server.SafePipeHandle.DangerousGetHandle().ToInt64();
ClientHandleValue = server.ClientSafePipeHandle.DangerousGetHandle().ToInt64();

using var coverlet = Process.Start(@"$(DotNetTool)", $"tool run coverlet {TestAssembly} --target pwsh --targetargs \"-NoExit -Command [System.IO.Pipes.AnonymousPipeClientStream]::new([System.IO.Pipes.PipeDirection]::In, [Microsoft.Win32.SafeHandles.SafePipeHandle]::new({ClientHandleValue}, $true)).ReadByte()\"");

var success = false;
server.SafePipeHandle.DangerousAddRef(ref success);

// TODO
System.Threading.Thread.Sleep(10000);
</Code>
</Task>

</UsingTask>

<UsingTask
TaskName="AfterCollectCodeCoverageTask"
TaskFactory="RoslynCodeTaskFactory"
AssemblyName="Microsoft.Build.Tasks.Core">

<ParameterGroup>
<ServerHandleValue ParameterType="System.Int64" Required="true" />
<ClientHandleValue ParameterType="System.Int64" Required="true" />
</ParameterGroup>

<Task>
<Using Namespace="System.IO.Pipes" />
<Using Namespace="Microsoft.Win32.SafeHandles" />
<Code>
using var server = new AnonymousPipeServerStream(
PipeDirection.Out,
new SafePipeHandle(new IntPtr(ServerHandleValue), true),
new SafePipeHandle(new IntPtr(ClientHandleValue), true));

server.WriteByte(1);
server.DisposeLocalCopyOfClientHandle();

// TODO
System.Threading.Thread.Sleep(10000);
</Code>
</Task>

</UsingTask>

<Import Project="Sdk.targets" Sdk="Microsoft.DotNet.Arcade.Sdk" />
</Project>
</Project>
12 changes: 12 additions & 0 deletions dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"coverlet.console": {
"version": "1.6.0",
"commands": [
"coverlet"
]
}
}
}

0 comments on commit 85ec468

Please sign in to comment.