Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.

Commit 9266732

Browse files
authored
[Touch.Client] Add support for macOS. (#80)
1 parent 2d556a5 commit 9266732

File tree

7 files changed

+269
-8
lines changed

7 files changed

+269
-8
lines changed

NUnitLite/TouchRunner/MacRunner.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Reflection;
5+
using System.Threading.Tasks;
6+
7+
using AppKit;
8+
using Foundation;
9+
10+
namespace MonoTouch.NUnit.UI {
11+
public class MacRunner : BaseTouchRunner {
12+
public static async Task<int> MainAsync (IList<string> arguments, params Assembly[] assemblies)
13+
{
14+
NSApplication.Init ();
15+
16+
var options = new TouchOptions (arguments);
17+
TouchOptions.Current = options;
18+
return await RunTestsAsync (options, assemblies) ? 0 : 1;
19+
}
20+
21+
static async Task<bool> RunTestsAsync (TouchOptions options, Assembly[] assemblies)
22+
{
23+
var runner = new MacRunner ();
24+
if (assemblies == null || assemblies.Length == 0)
25+
assemblies = AppDomain.CurrentDomain.GetAssemblies ();
26+
27+
foreach (var asm in assemblies)
28+
runner.Load (asm);
29+
30+
await runner.RunAsync ();
31+
32+
return !runner.Result.IsFailure ();
33+
}
34+
35+
protected override void WriteDeviceInformation (TextWriter writer)
36+
{
37+
var piinfo = NSProcessInfo.ProcessInfo;
38+
writer.WriteLine ("[macOS: {0}]", piinfo.OperatingSystemVersionString);
39+
}
40+
}
41+
}

NUnitLite/TouchRunner/TcpTextWriter.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
using System.Net.Sockets;
88
using System.Text;
99

10+
#if __IOS__
1011
using UIKit;
12+
#endif
1113

1214
namespace MonoTouch.NUnit {
1315

NUnitLite/TouchRunner/TouchOptions.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@
1919
//
2020

2121
using System;
22+
using System.Collections.Generic;
2223

2324
using Foundation;
25+
#if !__MACOS__
2426
using UIKit;
27+
#endif
2528

26-
#if !__WATCHOS__
29+
#if !__WATCHOS__ && !__MACOS__
2730
using MonoTouch.Dialog;
2831
#endif
2932

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

4447
public class TouchOptions {
4548

46-
static public TouchOptions Current = new TouchOptions ();
49+
static TouchOptions current;
50+
static public TouchOptions Current {
51+
get {
52+
if (current == null)
53+
current = new TouchOptions ();
54+
return current;
55+
}
56+
set {
57+
current = value;
58+
}
59+
}
4760

48-
public TouchOptions ()
61+
public TouchOptions (IList<string> arguments)
4962
{
5063
var defaults = NSUserDefaults.StandardUserDefaults;
5164
TerminateAfterExecution = defaults.BoolForKey ("execution.autoexit");
@@ -103,11 +116,16 @@ public TouchOptions ()
103116
};
104117

105118
try {
106-
os.Parse (Environment.GetCommandLineArgs ());
119+
os.Parse (arguments);
107120
} catch (OptionException oe) {
108121
Console.WriteLine ("{0} for options '{1}'", oe.Message, oe.OptionName);
109122
}
110123
}
124+
125+
public TouchOptions ()
126+
: this (Environment.GetCommandLineArgs ())
127+
{
128+
}
111129

112130
private bool EnableNetwork { get; set; }
113131

@@ -137,7 +155,7 @@ public bool ShowUseNetworkLogger {
137155

138156
public bool SortNames { get; set; }
139157

140-
#if !__WATCHOS__
158+
#if !__WATCHOS__ && !__MACOS__
141159
public UIViewController GetViewController ()
142160
{
143161
#if TVOS

NUnitLite/TouchRunner/TouchRunner.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@
3030

3131
using Foundation;
3232
using ObjCRuntime;
33+
#if !__MACOS__
3334
using UIKit;
35+
#endif
3436
using Constants = global::ObjCRuntime.Constants;
3537

36-
#if !__WATCHOS__
38+
#if !__WATCHOS__ && !__MACOS__
3739
using MonoTouch.Dialog;
3840
#endif
3941

@@ -202,6 +204,12 @@ public void AutoRun ()
202204
});
203205
}
204206

207+
public Task RunAsync ()
208+
{
209+
Run ();
210+
return Task.CompletedTask;
211+
}
212+
205213
bool running;
206214
public void Run ()
207215
{
@@ -387,7 +395,7 @@ public bool OpenWriter (string message)
387395
// returns true if test run should still start
388396
bool ShowConnectionErrorAlert (string hostname, int port, Exception ex)
389397
{
390-
#if __TVOS__ || __WATCHOS__
398+
#if __TVOS__ || __WATCHOS__ || __MACOS__
391399
return true;
392400
#else
393401
// Don't show any alerts if we're running automated.
@@ -652,7 +660,7 @@ protected override void WriteDeviceInformation (TextWriter writer)
652660
}
653661
#endif
654662

655-
#if !__WATCHOS__
663+
#if !__WATCHOS__ && !__MACOS__
656664
public class ConsoleRunner : BaseTouchRunner {
657665
protected override void WriteDeviceInformation (TextWriter writer)
658666
{
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProjectGuid>{A1209F3A-3876-4EAC-ADA7-99F660002AB6}</ProjectGuid>
7+
<ProjectTypeGuids>{A3F8F2AB-B479-4A4A-A458-A89E7DC349F1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
8+
<OutputType>Library</OutputType>
9+
<RootNamespace>Touch.Client</RootNamespace>
10+
<MonoMacResourcePrefix>Resources</MonoMacResourcePrefix>
11+
<AssemblyName>Touch.Client</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<UseXamMacFullFramework>true</UseXamMacFullFramework>
14+
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
17+
<OutputPath>bin\Debug</OutputPath>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<DefineConstants>DEBUG;NUNITLITE_NUGET</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
26+
<OutputPath>bin\Release</OutputPath>
27+
<DebugType>full</DebugType>
28+
<Optimize>true</Optimize>
29+
<DefineConstants>NUNITLITE_NUGET</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
<MtouchVerbosity></MtouchVerbosity>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="System" />
36+
<Reference Include="System.Xml" />
37+
<Reference Include="System.Core" />
38+
<Reference Include="Xamarin.Mac" />
39+
</ItemGroup>
40+
<ItemGroup>
41+
<Folder Include="Resources\" />
42+
</ItemGroup>
43+
<ItemGroup>
44+
<Compile Include="..\..\..\NUnitLite\TouchRunner\HttpTextWriter.cs">
45+
<Link>HttpTextWriter.cs</Link>
46+
</Compile>
47+
<Compile Include="..\..\..\NUnitLite\TouchRunner\NUnitOutputTextWriter.cs">
48+
<Link>NUnitOutputTextWriter.cs</Link>
49+
</Compile>
50+
<Compile Include="..\..\..\NUnitLite\TouchRunner\Options.cs">
51+
<Link>Options.cs</Link>
52+
</Compile>
53+
<Compile Include="..\..\..\NUnitLite\TouchRunner\TcpTextWriter.cs">
54+
<Link>TcpTextWriter.cs</Link>
55+
</Compile>
56+
<Compile Include="..\..\..\NUnitLite\TouchRunner\TestRocks.cs">
57+
<Link>TestRocks.cs</Link>
58+
</Compile>
59+
<Compile Include="..\..\..\NUnitLite\TouchRunner\TouchOptions.cs">
60+
<Link>TouchOptions.cs</Link>
61+
</Compile>
62+
<Compile Include="..\..\..\NUnitLite\TouchRunner\TouchRunner.cs">
63+
<Link>TouchRunner.cs</Link>
64+
</Compile>
65+
<Compile Include="..\..\..\NUnitLite\TouchRunner\MacRunner.cs">
66+
<Link>MacRunner.cs</Link>
67+
</Compile>
68+
</ItemGroup>
69+
<ItemGroup>
70+
<PackageReference Include="NUnitLite">
71+
<Version>3.12.0</Version>
72+
</PackageReference>
73+
<PackageReference Include="NUnit.Extension.NUnitV2ResultWriter">
74+
<Version>3.6.0</Version>
75+
</PackageReference>
76+
</ItemGroup>
77+
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Mac\Xamarin.Mac.CSharp.targets" />
78+
</Project>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProjectGuid>{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}</ProjectGuid>
7+
<ProjectTypeGuids>{A3F8F2AB-B479-4A4A-A458-A89E7DC349F1};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
8+
<OutputType>Library</OutputType>
9+
<RootNamespace>Touch.Client</RootNamespace>
10+
<MonoMacResourcePrefix>Resources</MonoMacResourcePrefix>
11+
<AssemblyName>Touch.Client</AssemblyName>
12+
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
13+
<TargetFrameworkIdentifier>Xamarin.Mac</TargetFrameworkIdentifier>
14+
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
17+
<OutputPath>bin\Debug</OutputPath>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<DefineConstants>DEBUG;NUNITLITE_NUGET</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
26+
<OutputPath>bin\Release</OutputPath>
27+
<DebugType>full</DebugType>
28+
<Optimize>true</Optimize>
29+
<DefineConstants>NUNITLITE_NUGET</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
<MtouchVerbosity></MtouchVerbosity>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="System" />
36+
<Reference Include="System.Xml" />
37+
<Reference Include="System.Core" />
38+
<Reference Include="Xamarin.Mac" />
39+
</ItemGroup>
40+
<ItemGroup>
41+
<Folder Include="Resources\" />
42+
</ItemGroup>
43+
<ItemGroup>
44+
<Compile Include="..\..\..\NUnitLite\TouchRunner\HttpTextWriter.cs">
45+
<Link>HttpTextWriter.cs</Link>
46+
</Compile>
47+
<Compile Include="..\..\..\NUnitLite\TouchRunner\NUnitOutputTextWriter.cs">
48+
<Link>NUnitOutputTextWriter.cs</Link>
49+
</Compile>
50+
<Compile Include="..\..\..\NUnitLite\TouchRunner\Options.cs">
51+
<Link>Options.cs</Link>
52+
</Compile>
53+
<Compile Include="..\..\..\NUnitLite\TouchRunner\TcpTextWriter.cs">
54+
<Link>TcpTextWriter.cs</Link>
55+
</Compile>
56+
<Compile Include="..\..\..\NUnitLite\TouchRunner\TestRocks.cs">
57+
<Link>TestRocks.cs</Link>
58+
</Compile>
59+
<Compile Include="..\..\..\NUnitLite\TouchRunner\TouchOptions.cs">
60+
<Link>TouchOptions.cs</Link>
61+
</Compile>
62+
<Compile Include="..\..\..\NUnitLite\TouchRunner\TouchRunner.cs">
63+
<Link>TouchRunner.cs</Link>
64+
</Compile>
65+
<Compile Include="..\..\..\NUnitLite\TouchRunner\MacRunner.cs">
66+
<Link>MacRunner.cs</Link>
67+
</Compile>
68+
</ItemGroup>
69+
<ItemGroup>
70+
<PackageReference Include="NUnitLite">
71+
<Version>3.12.0</Version>
72+
</PackageReference>
73+
<PackageReference Include="NUnit.Extension.NUnitV2ResultWriter">
74+
<Version>3.6.0</Version>
75+
</PackageReference>
76+
</ItemGroup>
77+
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Mac\Xamarin.Mac.CSharp.targets" />
78+
</Project>

Touch.Unit.sln

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Touch.Client-iOS", "Touch.C
1414
EndProject
1515
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Touch.Client-watchOS", "Touch.Client\watchOS\Touch.Client-watchOS.csproj", "{5A3AB2C1-17A9-40C0-B889-2B5795C1C10E}"
1616
EndProject
17+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Touch.Client-macOS-mobile", "Touch.Client\macOS\mobile\Touch.Client-macOS-mobile.csproj", "{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}"
18+
EndProject
19+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Touch.Client-macOS-full", "Touch.Client\macOS\full\Touch.Client-macOS-full.csproj", "{A1209F3A-3876-4EAC-ADA7-99F660002AB6}"
20+
EndProject
1721
Global
1822
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1923
Debug|iPhoneSimulator = Debug|iPhoneSimulator
@@ -138,6 +142,38 @@ Global
138142
{5A3AB2C1-17A9-40C0-B889-2B5795C1C10E}.AdHoc|iPhone.Build.0 = Debug|Any CPU
139143
{5A3AB2C1-17A9-40C0-B889-2B5795C1C10E}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
140144
{5A3AB2C1-17A9-40C0-B889-2B5795C1C10E}.AppStore|iPhone.Build.0 = Debug|Any CPU
145+
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
146+
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
147+
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
148+
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
149+
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.Debug|iPhone.ActiveCfg = Debug|Any CPU
150+
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.Debug|iPhone.Build.0 = Debug|Any CPU
151+
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.Release|iPhone.ActiveCfg = Release|Any CPU
152+
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.Release|iPhone.Build.0 = Release|Any CPU
153+
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.AdHoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
154+
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.AdHoc|iPhoneSimulator.Build.0 = Debug|Any CPU
155+
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
156+
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
157+
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.AdHoc|iPhone.ActiveCfg = Debug|Any CPU
158+
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.AdHoc|iPhone.Build.0 = Debug|Any CPU
159+
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
160+
{88A8A1AC-0829-4C98-8F4A-9FC23DC42A06}.AppStore|iPhone.Build.0 = Debug|Any CPU
161+
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU
162+
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU
163+
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
164+
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
165+
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.Debug|iPhone.ActiveCfg = Debug|Any CPU
166+
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.Debug|iPhone.Build.0 = Debug|Any CPU
167+
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.Release|iPhone.ActiveCfg = Release|Any CPU
168+
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.Release|iPhone.Build.0 = Release|Any CPU
169+
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.AdHoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU
170+
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.AdHoc|iPhoneSimulator.Build.0 = Debug|Any CPU
171+
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU
172+
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU
173+
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.AdHoc|iPhone.ActiveCfg = Debug|Any CPU
174+
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.AdHoc|iPhone.Build.0 = Debug|Any CPU
175+
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.AppStore|iPhone.ActiveCfg = Debug|Any CPU
176+
{A1209F3A-3876-4EAC-ADA7-99F660002AB6}.AppStore|iPhone.Build.0 = Debug|Any CPU
141177
EndGlobalSection
142178
GlobalSection(MonoDevelopProperties) = preSolution
143179
StartupItem = Touch.Unit.csproj

0 commit comments

Comments
 (0)