Skip to content

Commit

Permalink
Use the ported runner sources for XUnitRunnerUap
Browse files Browse the repository at this point in the history
  • Loading branch information
ViktorHofer committed Jan 18, 2019
1 parent f132521 commit 3bdfe07
Show file tree
Hide file tree
Showing 53 changed files with 189 additions and 968 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,62 @@
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>
<ItemGroup>
<Compile Include="CommandLine.cs" />
<Compile Include="DictionaryExtensions.cs" />
<Compile Include="Program.cs" />
<Compile Include="..\..\Microsoft.DotNet.XUnitConsoleRunner\src\CommandLine.cs">
<Link>CommandLine.cs</Link>
</Compile>
<Compile Include="..\..\Microsoft.DotNet.XUnitConsoleRunner\src\ConsoleRunner.cs">
<Link>ConsoleRunner.cs</Link>
</Compile>
<Compile Include="..\..\Microsoft.DotNet.XUnitConsoleRunner\src\ParallelismOption.cs">
<Link>ParallelismOption.cs</Link>
</Compile>
<Compile Include="..\..\Microsoft.DotNet.XUnitConsoleRunner\src\Program.cs">
<Link>Program.cs</Link>
</Compile>
<Compile Include="..\..\Microsoft.DotNet.XUnitConsoleRunner\src\RemoteExecutor.cs">
<Link>RemoteExecutor.cs</Link>
</Compile>
<Compile Include="..\..\Microsoft.DotNet.XUnitConsoleRunner\src\Sinks\DiagnosticMessageSink.cs">
<Link>Sinks\DiagnosticMessageSink.cs</Link>
</Compile>
<Compile Include="..\..\Microsoft.DotNet.XUnitConsoleRunner\src\Utility\Transform.cs">
<Link>Utility\Transform.cs</Link>
</Compile>
<Compile Include="..\..\Microsoft.DotNet.XUnitConsoleRunner\src\Utility\TransformFactory.cs">
<Link>Utility\TransformFactory.cs</Link>
</Compile>
<Compile Include="..\..\Microsoft.DotNet.XUnitConsoleRunner\src\Utility\ConsoleRunnerLogger.cs">
<Link>Utility\ConsoleRunnerLogger.cs</Link>
</Compile>
<Compile Include="..\..\Microsoft.DotNet.XUnitConsoleRunner\src\common\ConsoleHelper.cs">
<Link>common\ConsoleHelper.cs</Link>
</Compile>
<Compile Include="..\..\Microsoft.DotNet.XUnitConsoleRunner\src\common\DictionaryExtensions.cs">
<Link>common\DictionaryExtensions.cs</Link>
</Compile>
<Compile Include="..\..\Microsoft.DotNet.XUnitConsoleRunner\src\common\Json.cs">
<Link>common\Json.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RemoteExecutor.cs" />
<Compile Include="StandardUapVisitor.cs" />
</ItemGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
</ItemGroup>
<ItemGroup>
<EmbeddedContent Include="..\..\Microsoft.DotNet.XUnitConsoleRunner\src\HTML.xslt">
<Link>HTML.xslt</Link>
</EmbeddedContent>
<EmbeddedContent Include="..\..\Microsoft.DotNet.XUnitConsoleRunner\src\JUnitXml.xslt">
<Link>JUnitXml.xslt</Link>
</EmbeddedContent>
<EmbeddedContent Include="..\..\Microsoft.DotNet.XUnitConsoleRunner\src\NUnitXml.xslt">
<Link>NUnitXml.xslt</Link>
</EmbeddedContent>
<EmbeddedContent Include="..\..\Microsoft.DotNet.XUnitConsoleRunner\src\xUnit1.xslt">
<Link>xUnit1.xslt</Link>
</EmbeddedContent>
<Content Include="Properties\Default.rd.xml" />
<Content Include="Assets\Square310x310Logo.png" />
<Content Include="Assets\Square44x44Logo.png" />
Expand All @@ -149,8 +192,13 @@
<Content Include="Assets\Wide310x150Logo.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Net.Native.Compiler">
<Version>2.2.1</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
<Version>6.2.0-Preview1-26502-02</Version>
<Version>6.2.0-preview1-26926-04</Version>
</PackageReference>
<PackageReference Include="xunit">
<Version>2.4.1-pre.build.4059</Version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Supported platforms:
- ARM and ARM64 tools installed
- Windows 10 >= v10.0.17134 (April 2018 Update)

To build and bundle the runner and launcher for deployment invoke the `buildAndUpdate.bat` script as following: `.\buildAndUpdate.bat src Launcher bin`. This will create an output directory (third parameter) which can be copied into the existing nuget package `Microsoft.DotNet.Uap.TestTools` for updates.
To build and bundle the runner and launcher for deployment invoke the `buildAndUpdate.bat` script as following: `.\buildAndUpdate.bat Microsoft.DotNet.XUnitRunnerUap WindowsStoreAppLauncher ..\Microsoft.DotNet.XUnitConsoleRunner\src bin\microsoft.dotnet.uap.testtools`. This will create an output directory (third parameter) which can be copied into the existing nuget package `Microsoft.DotNet.Uap.TestTools` for updates.

## Microsoft.DotNet.XUnitRunnerUap

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ setlocal
echo off
set RunnerSourceFolder=%1
set LauncherSourceFolder=%2
set DestinationFolder=%3
set XUnitConsoleRunnerFolder=%3
set DestinationFolder=%4

call :LauncherMain x86
call :RunnerMain x86
Expand All @@ -16,6 +17,8 @@ setlocal
call :LauncherMain arm64
call :RunnerMain arm64

call :XUnitConsoleRunner

echo on
goto :EOF

Expand All @@ -26,7 +29,15 @@ setlocal
msbuild /t:rebuild "%LauncherSourceFolder%\WindowsStoreAppLauncher.vcxproj" /p:Platform=%_platform% /p:Configuration=Release

REM Copy the launcher executable
xcopy /y "%LauncherSourceFolder%\bin\%_platform%\Release\WindowsStoreAppLauncher.exe" "%DestinationFolder%\%_platform%\Launcher\"
xcopy /y "%LauncherSourceFolder%\bin\%_platform%\Release\WindowsStoreAppLauncher.exe" "%DestinationFolder%\Tools\%_platform%\Launcher\"
GOTO :EOF

:XUnitConsoleRunner
REM Rebuild the runner
msbuild /t:rebuild "%XUnitConsoleRunnerFolder%\Microsoft.DotNet.XUnitConsoleRunner.csproj" /p:DefineConstants="WINDOWS_UWP" /p:OutputPath="bin\WINDOWS_UWP"

REM Copy the runner executable
xcopy /y "%XUnitConsoleRunnerFolder%\bin\WINDOWS_UWP\*" "%DestinationFolder%\lib\netcoreapp2.0\"
GOTO :EOF

:RunnerMain
Expand All @@ -42,12 +53,13 @@ setlocal
IF "%_platform%" == "arm64" (
makeappx unpack /l /o /p "%RunnerSourceFolder%\bin\AppPackages\Microsoft.DotNet.XUnitRunnerUap_1.0.0.0_%_platform%_Debug_Test\Dependencies\%_platform%\Microsoft.VCLibs.%_platform%.14.00.appx" /d "%RunnerSourceFolder%\bin\unpack\Microsoft.VCLibs.%_platform%.Debug.14.00\%_platform%"
) ELSE (
makeappx unpack /l /o /p "%RunnerSourceFolder%\bin\AppPackages\Microsoft.DotNet.XUnitRunnerUap_1.0.0.0_%_platform%_Debug_Test\Dependencies\%_platform%\Microsoft.NET.CoreRuntime.2.1.appx" /d "%RunnerSourceFolder%\bin\unpack\Microsoft.NET.CoreRuntime.2.1\%_platform%"
makeappx unpack /l /o /p "%RunnerSourceFolder%\bin\AppPackages\Microsoft.DotNet.XUnitRunnerUap_1.0.0.0_%_platform%_Debug_Test\Dependencies\%_platform%\Microsoft.NET.CoreRuntime.2.2.appx" /d "%RunnerSourceFolder%\bin\unpack\Microsoft.NET.CoreRuntime.2.2\%_platform%"
makeappx unpack /l /o /p "%RunnerSourceFolder%\bin\AppPackages\Microsoft.DotNet.XUnitRunnerUap_1.0.0.0_%_platform%_Debug_Test\Dependencies\%_platform%\Microsoft.NET.CoreFramework.Debug.2.2.appx" /d "%RunnerSourceFolder%\bin\unpack\Microsoft.NET.CoreFramework.Debug.2.2\%_platform%"
makeappx unpack /l /o /p "%RunnerSourceFolder%\bin\AppPackages\Microsoft.DotNet.XUnitRunnerUap_1.0.0.0_%_platform%_Debug_Test\Dependencies\%_platform%\Microsoft.VCLibs.%_platform%.Debug.14.00.appx" /d "%RunnerSourceFolder%\bin\unpack\Microsoft.VCLibs.%_platform%.Debug.14.00\%_platform%"
)

REM Copy the files we care about from the unpacked folder
call :RunnerCopy "%RunnerSourceFolder%\bin\unpack" "%DestinationFolder%\%_platform%\Runner"
call :RunnerCopy "%RunnerSourceFolder%\bin\unpack" "%DestinationFolder%\Tools\%_platform%\Runner"
GOTO :EOF

:RunnerCopy
Expand All @@ -71,27 +83,24 @@ setlocal
IF "%_platform%" == "arm64" (
xcopy /y %_mainSource%\clrcompression.dll %_dest%\
xcopy /y %_mainSource%\Microsoft.DotNet.XUnitRunnerUap.dll %_dest%\
xcopy /y %_mainSource%\mrt100.dll %_dest%\
xcopy /y %_mainSource%\mrt100_app.dll %_dest%\
xcopy /y %_mainSource%\vcruntime140_app.dll %_dest%\
) ELSE (
xcopy /y %_mainSource%\entrypoint\Microsoft.DotNet.XUnitRunnerUap.exe %_dest%\entrypoint\
xcopy /y %_mainSource%\Properties\Default.rd.xml %_dest%\Properties\
xcopy /y %_mainSource%\WinMetadata\Windows.winmd %_dest%\WinMetadata\
xcopy /y %_mainSource%\System.ServiceModel.dll %_dest%\
xcopy /y %_mainSource%\System.ServiceModel.Duplex.dll %_dest%\
xcopy /y %_mainSource%\System.ServiceModel.Http.dll %_dest%\
xcopy /y %_mainSource%\System.ServiceModel.NetTcp.dll %_dest%\
xcopy /y %_mainSource%\System.ServiceModel.Primitives.dll %_dest%\
xcopy /y %_mainSource%\System.ServiceModel.Security.dll %_dest%\
xcopy /y %_mainSource%\System.ServiceModel.Web.dll %_dest%\
xcopy /y %_mainSource%\System.ServiceProcess.dll %_dest%\
xcopy /y "%_source%\Microsoft.NET.CoreFramework.Debug.2.2\%_platform%\System.ServiceModel.dll" %_dest%\
xcopy /y "%_source%\Microsoft.NET.CoreFramework.Debug.2.2\%_platform%\System.ServiceModel.Duplex.dll" %_dest%\
xcopy /y "%_source%\Microsoft.NET.CoreFramework.Debug.2.2\%_platform%\System.ServiceModel.Http.dll" %_dest%\
xcopy /y "%_source%\Microsoft.NET.CoreFramework.Debug.2.2\%_platform%\System.ServiceModel.NetTcp.dll" %_dest%\
xcopy /y "%_source%\Microsoft.NET.CoreFramework.Debug.2.2\%_platform%\System.ServiceModel.Primitives.dll" %_dest%\
xcopy /y "%_source%\Microsoft.NET.CoreFramework.Debug.2.2\%_platform%\System.ServiceModel.Security.dll" %_dest%\
xcopy /y "%_source%\Microsoft.NET.CoreFramework.Debug.2.2\%_platform%\System.ServiceModel.Web.dll" %_dest%\
xcopy /y "%_source%\Microsoft.NET.CoreFramework.Debug.2.2\%_platform%\System.ServiceProcess.dll" %_dest%\
xcopy /y %_mainSource%\xunit.abstractions.dll %_dest%\
xcopy /y %_mainSource%\xunit.assert.dll %_dest%\
xcopy /y %_mainSource%\xunit.core.dll %_dest%\
xcopy /y %_mainSource%\xunit.execution.dotnet.dll %_dest%\
xcopy /y %_mainSource%\xunit.runner.utility.uwp10.dll %_dest%\
xcopy /y "%_source%\Microsoft.NET.CoreRuntime.2.1\%_platform%\uwphost.dll" "%_dest%\"
xcopy /y "%_source%\Microsoft.NET.CoreRuntime.2.2\%_platform%\uwphost.dll" "%_dest%\"
)

GOTO:EOF
Expand Down
13 changes: 11 additions & 2 deletions src/Microsoft.DotNet.XUnitConsoleRunner/src/ConsoleRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ public ConsoleRunner(object consoleLock)

public int EntryPoint(string[] args)
{
#if WINDOWS_UWP
// Handle RemoteExecutor
if (args.Length > 0 && args[0] == "remote")
{
return RemoteExecutor.Execute(args.Skip(1).ToArray());
}
#endif

commandLine = CommandLine.Parse(args);

try
Expand Down Expand Up @@ -169,9 +177,8 @@ List<IRunnerReporter> GetAvailableRunnerReporters()
void PrintHeader()
{
var platform = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;
var versionAttribute = typeof(ConsoleRunner).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>();

Console.WriteLine($"xUnit.net Console Runner v{versionAttribute.InformationalVersion} ({IntPtr.Size * 8}-bit {platform})");
Console.WriteLine($"Microsoft.DotNet.XUnitConsoleRunner v2.5.0 ({IntPtr.Size * 8}-bit {platform})");
}

void PrintUsage(IReadOnlyList<IRunnerReporter> reporters)
Expand Down Expand Up @@ -355,7 +362,9 @@ XElement ExecuteAssembly(object consoleLock,
var shadowCopy = assembly.Configuration.ShadowCopyOrDefault;
var longRunningSeconds = assembly.Configuration.LongRunningTestSecondsOrDefault;

#if !WINDOWS_UWP
using (AssemblyHelper.SubscribeResolveForAssembly(assembly.AssemblyFilename, internalDiagnosticsMessageSink))
#endif
using (var controller = new XunitFrontController(appDomainSupport, assembly.AssemblyFilename, assembly.ConfigFilename, shadowCopy, diagnosticMessageSink: diagnosticMessageSink))
using (var discoverySink = new TestDiscoverySink(() => cancel))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<OutputType>Exe</OutputType>
<RootNamespace>Xunit.ConsoleClient</RootNamespace>
<TargetFrameworks>netcoreapp2.0</TargetFrameworks>
<TargetFramework>netcoreapp2.0</TargetFramework>
<IsPackable>true</IsPackable>
<VersionPrefix>2.5.0</VersionPrefix>
<LangVersion>latest</LangVersion>
<DefaultItemExcludes Condition="'$(DefineConstants)' == 'WINDOWS_UWP'">$(DefaultItemExcludes);common\AssemblyResolution\*.cs</DefaultItemExcludes>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/Microsoft.DotNet.XUnitConsoleRunner/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public static int Main(string[] args)
var consoleLock = new object();
var internalDiagnosticsMessageSink = DiagnosticMessageSink.ForInternalDiagnostics(consoleLock, args.Contains("-internaldiagnostics"), args.Contains("-nocolor"));

#if !WINDOWS_UWP
using (AssemblyHelper.SubscribeResolveForAssembly(typeof(Program), internalDiagnosticsMessageSink))
#endif
return new ConsoleRunner(consoleLock).EntryPoint(args);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#if WINDOWS_UWP

using System;
using System.IO;
using System.Reflection;
Expand All @@ -10,7 +12,7 @@
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;

namespace Microsoft.DotNet.XUnitRunnerUap
namespace Xunit.ConsoleClient
{
/// <summary>
/// Provides an entry point in a new process that will load a specified method and invoke it.
Expand Down Expand Up @@ -113,22 +115,6 @@ public static int Execute(string[] args)
return exitCode;
}

private static MethodInfo GetMethod(this Type type, string methodName)
{
Type t = type;
while (t != null)
{
TypeInfo ti = t.GetTypeInfo();
MethodInfo mi = ti.GetDeclaredMethod(methodName);
if (mi != null)
{
return mi;
}
t = ti.BaseType;
}
return null;
}

private static T[] Subarray<T>(this T[] arr, int offset, int count)
{
var newArr = new T[count];
Expand All @@ -137,3 +123,5 @@ private static T[] Subarray<T>(this T[] arr, int offset, int count)
}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#if WINDOWS_UWP

using System;

namespace Xunit.ConsoleClient
{
/// <summary>
/// An implementation of <see cref="IRunnerLogger"/> which logs messages
/// to <see cref="Console"/> and <see cref="Console.Error"/>.
/// </summary>
public class ConsoleRunnerLogger : IRunnerLogger
{
readonly object lockObject;
readonly bool useColors;

/// <summary>
/// Initializes a new instance of the <see cref="ConsoleRunnerLogger"/> class.
/// </summary>
/// <param name="useColors">A flag to indicate whether colors should be used when
/// logging messages.</param>
public ConsoleRunnerLogger(bool useColors) : this(useColors, new object()) { }

/// <summary>
/// Initializes a new instance of the <see cref="ConsoleRunnerLogger"/> class.
/// </summary>
/// <param name="useColors">A flag to indicate whether colors should be used when
/// logging messages.</param>
/// <param name="lockObject">The lock object used to prevent console clashes.</param>
public ConsoleRunnerLogger(bool useColors, object lockObject)
{
this.useColors = useColors;
this.lockObject = lockObject;
}

/// <inheritdoc/>
public object LockObject => lockObject;

/// <inheritdoc/>
public void LogError(StackFrameInfo stackFrame, string message)
{
using (SetColor(ConsoleColor.Red))
lock (LockObject)
Console.Error.WriteLine(message);
}

/// <inheritdoc/>
public void LogImportantMessage(StackFrameInfo stackFrame, string message)
{
using (SetColor(ConsoleColor.Gray))
lock (LockObject)
Console.WriteLine(message);
}

/// <inheritdoc/>
public void LogMessage(StackFrameInfo stackFrame, string message)
{
using (SetColor(ConsoleColor.DarkGray))
lock (LockObject)
Console.WriteLine(message);
}

/// <inheritdoc/>
public void LogWarning(StackFrameInfo stackFrame, string message)
{
using (SetColor(ConsoleColor.Yellow))
lock (LockObject)
Console.WriteLine(message);
}

IDisposable SetColor(ConsoleColor color)
=> useColors ? new ColorRestorer(color) : null;

class ColorRestorer : IDisposable
{
public ColorRestorer(ConsoleColor color)
=> ConsoleHelper.SetForegroundColor(color);

public void Dispose()
=> ConsoleHelper.ResetColor();
}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if NETCOREAPP

using System;
using System.IO;
using System.Reflection;
Expand Down Expand Up @@ -103,5 +101,3 @@ public static IDisposable SubscribeResolveForAssembly(Type typeInAssembly, IMess
=> new AssemblyHelper(typeInAssembly.GetTypeInfo().Assembly.Location, internalDiagnosticsMessageSink);
}
}

#endif
Loading

0 comments on commit 3bdfe07

Please sign in to comment.