Skip to content

Commit

Permalink
[Touch.Client] Add support for macOS. (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfbjarne committed Jul 17, 2020
1 parent 2d556a5 commit 9266732
Show file tree
Hide file tree
Showing 7 changed files with 269 additions and 8 deletions.
41 changes: 41 additions & 0 deletions NUnitLite/TouchRunner/MacRunner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;

using AppKit;
using Foundation;

namespace MonoTouch.NUnit.UI {
public class MacRunner : BaseTouchRunner {
public static async Task<int> MainAsync (IList<string> arguments, params Assembly[] assemblies)
{
NSApplication.Init ();

var options = new TouchOptions (arguments);
TouchOptions.Current = options;
return await RunTestsAsync (options, assemblies) ? 0 : 1;
}

static async Task<bool> RunTestsAsync (TouchOptions options, Assembly[] assemblies)
{
var runner = new MacRunner ();
if (assemblies == null || assemblies.Length == 0)
assemblies = AppDomain.CurrentDomain.GetAssemblies ();

foreach (var asm in assemblies)
runner.Load (asm);

await runner.RunAsync ();

return !runner.Result.IsFailure ();
}

protected override void WriteDeviceInformation (TextWriter writer)
{
var piinfo = NSProcessInfo.ProcessInfo;
writer.WriteLine ("[macOS: {0}]", piinfo.OperatingSystemVersionString);
}
}
}
2 changes: 2 additions & 0 deletions NUnitLite/TouchRunner/TcpTextWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
using System.Net.Sockets;
using System.Text;

#if __IOS__
using UIKit;
#endif

namespace MonoTouch.NUnit {

Expand Down
28 changes: 23 additions & 5 deletions NUnitLite/TouchRunner/TouchOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@
//

using System;
using System.Collections.Generic;

using Foundation;
#if !__MACOS__
using UIKit;
#endif

#if !__WATCHOS__
#if !__WATCHOS__ && !__MACOS__
using MonoTouch.Dialog;
#endif

Expand All @@ -43,9 +46,19 @@ public enum XmlVersion {

public class TouchOptions {

static public TouchOptions Current = new TouchOptions ();
static TouchOptions current;
static public TouchOptions Current {
get {
if (current == null)
current = new TouchOptions ();
return current;
}
set {
current = value;
}
}

public TouchOptions ()
public TouchOptions (IList<string> arguments)
{
var defaults = NSUserDefaults.StandardUserDefaults;
TerminateAfterExecution = defaults.BoolForKey ("execution.autoexit");
Expand Down Expand Up @@ -103,11 +116,16 @@ public TouchOptions ()
};

try {
os.Parse (Environment.GetCommandLineArgs ());
os.Parse (arguments);
} catch (OptionException oe) {
Console.WriteLine ("{0} for options '{1}'", oe.Message, oe.OptionName);
}
}

public TouchOptions ()
: this (Environment.GetCommandLineArgs ())
{
}

private bool EnableNetwork { get; set; }

Expand Down Expand Up @@ -137,7 +155,7 @@ public bool ShowUseNetworkLogger {

public bool SortNames { get; set; }

#if !__WATCHOS__
#if !__WATCHOS__ && !__MACOS__
public UIViewController GetViewController ()
{
#if TVOS
Expand Down
14 changes: 11 additions & 3 deletions NUnitLite/TouchRunner/TouchRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@

using Foundation;
using ObjCRuntime;
#if !__MACOS__
using UIKit;
#endif
using Constants = global::ObjCRuntime.Constants;

#if !__WATCHOS__
#if !__WATCHOS__ && !__MACOS__
using MonoTouch.Dialog;
#endif

Expand Down Expand Up @@ -202,6 +204,12 @@ public void AutoRun ()
});
}

public Task RunAsync ()
{
Run ();
return Task.CompletedTask;
}

bool running;
public void Run ()
{
Expand Down Expand Up @@ -387,7 +395,7 @@ public bool OpenWriter (string message)
// returns true if test run should still start
bool ShowConnectionErrorAlert (string hostname, int port, Exception ex)
{
#if __TVOS__ || __WATCHOS__
#if __TVOS__ || __WATCHOS__ || __MACOS__
return true;
#else
// Don't show any alerts if we're running automated.
Expand Down Expand Up @@ -652,7 +660,7 @@ protected override void WriteDeviceInformation (TextWriter writer)
}
#endif

#if !__WATCHOS__
#if !__WATCHOS__ && !__MACOS__
public class ConsoleRunner : BaseTouchRunner {
protected override void WriteDeviceInformation (TextWriter writer)
{
Expand Down
78 changes: 78 additions & 0 deletions Touch.Client/macOS/full/Touch.Client-macOS-full.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A1209F3A-3876-4EAC-ADA7-99F660002AB6}</ProjectGuid>
<ProjectTypeGuids>{A3F8F2AB-B479-4A4A-A458-A89E7DC349F1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<RootNamespace>Touch.Client</RootNamespace>
<MonoMacResourcePrefix>Resources</MonoMacResourcePrefix>
<AssemblyName>Touch.Client</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<UseXamMacFullFramework>true</UseXamMacFullFramework>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug</OutputPath>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<DefineConstants>DEBUG;NUNITLITE_NUGET</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release</OutputPath>
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<DefineConstants>NUNITLITE_NUGET</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<MtouchVerbosity></MtouchVerbosity>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="Xamarin.Mac" />
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\NUnitLite\TouchRunner\HttpTextWriter.cs">
<Link>HttpTextWriter.cs</Link>
</Compile>
<Compile Include="..\..\..\NUnitLite\TouchRunner\NUnitOutputTextWriter.cs">
<Link>NUnitOutputTextWriter.cs</Link>
</Compile>
<Compile Include="..\..\..\NUnitLite\TouchRunner\Options.cs">
<Link>Options.cs</Link>
</Compile>
<Compile Include="..\..\..\NUnitLite\TouchRunner\TcpTextWriter.cs">
<Link>TcpTextWriter.cs</Link>
</Compile>
<Compile Include="..\..\..\NUnitLite\TouchRunner\TestRocks.cs">
<Link>TestRocks.cs</Link>
</Compile>
<Compile Include="..\..\..\NUnitLite\TouchRunner\TouchOptions.cs">
<Link>TouchOptions.cs</Link>
</Compile>
<Compile Include="..\..\..\NUnitLite\TouchRunner\TouchRunner.cs">
<Link>TouchRunner.cs</Link>
</Compile>
<Compile Include="..\..\..\NUnitLite\TouchRunner\MacRunner.cs">
<Link>MacRunner.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<PackageReference Include="NUnitLite">
<Version>3.12.0</Version>
</PackageReference>
<PackageReference Include="NUnit.Extension.NUnitV2ResultWriter">
<Version>3.6.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Mac\Xamarin.Mac.CSharp.targets" />
</Project>
78 changes: 78 additions & 0 deletions Touch.Client/macOS/mobile/Touch.Client-macOS-mobile.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}</ProjectGuid>
<ProjectTypeGuids>{A3F8F2AB-B479-4A4A-A458-A89E7DC349F1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<RootNamespace>Touch.Client</RootNamespace>
<MonoMacResourcePrefix>Resources</MonoMacResourcePrefix>
<AssemblyName>Touch.Client</AssemblyName>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<TargetFrameworkIdentifier>Xamarin.Mac</TargetFrameworkIdentifier>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug</OutputPath>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<DefineConstants>DEBUG;NUNITLITE_NUGET</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release</OutputPath>
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<DefineConstants>NUNITLITE_NUGET</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<MtouchVerbosity></MtouchVerbosity>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="Xamarin.Mac" />
</ItemGroup>
<ItemGroup>
<Folder Include="Resources\" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\..\..\NUnitLite\TouchRunner\HttpTextWriter.cs">
<Link>HttpTextWriter.cs</Link>
</Compile>
<Compile Include="..\..\..\NUnitLite\TouchRunner\NUnitOutputTextWriter.cs">
<Link>NUnitOutputTextWriter.cs</Link>
</Compile>
<Compile Include="..\..\..\NUnitLite\TouchRunner\Options.cs">
<Link>Options.cs</Link>
</Compile>
<Compile Include="..\..\..\NUnitLite\TouchRunner\TcpTextWriter.cs">
<Link>TcpTextWriter.cs</Link>
</Compile>
<Compile Include="..\..\..\NUnitLite\TouchRunner\TestRocks.cs">
<Link>TestRocks.cs</Link>
</Compile>
<Compile Include="..\..\..\NUnitLite\TouchRunner\TouchOptions.cs">
<Link>TouchOptions.cs</Link>
</Compile>
<Compile Include="..\..\..\NUnitLite\TouchRunner\TouchRunner.cs">
<Link>TouchRunner.cs</Link>
</Compile>
<Compile Include="..\..\..\NUnitLite\TouchRunner\MacRunner.cs">
<Link>MacRunner.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
<PackageReference Include="NUnitLite">
<Version>3.12.0</Version>
</PackageReference>
<PackageReference Include="NUnit.Extension.NUnitV2ResultWriter">
<Version>3.6.0</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Mac\Xamarin.Mac.CSharp.targets" />
</Project>
36 changes: 36 additions & 0 deletions Touch.Unit.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Touch.Client-iOS", "Touch.C
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Touch.Client-watchOS", "Touch.Client\watchOS\Touch.Client-watchOS.csproj", "{5A3AB2C1-17A9-40C0-B889-2B5795C1C10E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Touch.Client-macOS-mobile", "Touch.Client\macOS\mobile\Touch.Client-macOS-mobile.csproj", "{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Touch.Client-macOS-full", "Touch.Client\macOS\full\Touch.Client-macOS-full.csproj", "{A1209F3A-3876-4EAC-ADA7-99F660002AB6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|iPhoneSimulator = Debug|iPhoneSimulator
Expand Down Expand Up @@ -138,6 +142,38 @@ Global
{5A3AB2C1-17A9-40C0-B889-2B5795C1C10E}.AdHoc|iPhone.Build.0 = Debug|Any CPU
{5A3AB2C1-17A9-40C0-B889-2B5795C1C10E}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
{5A3AB2C1-17A9-40C0-B889-2B5795C1C10E}.AppStore|iPhone.Build.0 = Debug|Any CPU
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.Debug|iPhone.Build.0 = Debug|Any CPU
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.Release|iPhone.ActiveCfg = Release|Any CPU
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.Release|iPhone.Build.0 = Release|Any CPU
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.AdHoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.AdHoc|iPhoneSimulator.Build.0 = Debug|Any CPU
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.AdHoc|iPhone.ActiveCfg = Debug|Any CPU
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.AdHoc|iPhone.Build.0 = Debug|Any CPU
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.AppStore|iPhone.Build.0 = Debug|Any CPU
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.Debug|iPhone.ActiveCfg = Debug|Any CPU
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.Debug|iPhone.Build.0 = Debug|Any CPU
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.Release|iPhone.ActiveCfg = Release|Any CPU
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.Release|iPhone.Build.0 = Release|Any CPU
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.AdHoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.AdHoc|iPhoneSimulator.Build.0 = Debug|Any CPU
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.AdHoc|iPhone.ActiveCfg = Debug|Any CPU
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.AdHoc|iPhone.Build.0 = Debug|Any CPU
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.AppStore|iPhone.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = Touch.Unit.csproj
Expand Down

0 comments on commit 9266732

Please sign in to comment.