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 17, 2019
1 parent f132521 commit a090ef5
Show file tree
Hide file tree
Showing 19 changed files with 159 additions and 850 deletions.
11 changes: 9 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<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>
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if WINDOWS_UAP
#if WINDOWS_UWP

using System;
using Xunit.Abstractions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if NETCOREAPP

using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -295,5 +293,3 @@ public string ResolveUnmanagedLibrary(string unmanagedLibraryName)
}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if NETCOREAPP

using System;
using System.IO;

Expand All @@ -19,5 +17,3 @@ private static string GetApplicationBasePath()
}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if NETCOREAPP

using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -106,5 +104,3 @@ public int GetHashCode(T obj)
}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if NETCOREAPP

using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -525,5 +523,3 @@ private struct LibraryStub
}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if NETCOREAPP

using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -128,5 +126,3 @@ private DependencyContext LoadAssemblyContext(Assembly assembly, IDependencyCont
}
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if NETCOREAPP

using System;
using System.IO;

Expand All @@ -10,5 +8,3 @@ internal interface IDependencyContextReader: IDisposable
DependencyContext Read(Stream stream);
}
}

#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#if NETCOREAPP

// Adapted from https://github.com/dotnet/core-setup/blob/652b680dff6b1afb9cd26cc3c2e883a664c209fd/src/managed/Microsoft.Extensions.DependencyModel/Resolution/PackageCompilationAssemblyResolver.cs

using System;
Expand Down Expand Up @@ -101,5 +99,3 @@ bool TryResolveFromPackagePath(CompilationLibrary library, string basePath, out
}
}
}

#endif
Loading

0 comments on commit a090ef5

Please sign in to comment.