Skip to content

Commit d85b7ea

Browse files
committed
[tests] Make the template watchOS extension use Touch.Client's API to exclude tests based on categories.
This also removes the ability to filter tests based on the first character of a test name, but we don't use this ability anymore.
1 parent f79efc2 commit d85b7ea

File tree

2 files changed

+27
-49
lines changed

2 files changed

+27
-49
lines changed

tests/templates/WatchExtension/InterfaceController.cs

+13-44
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
using System;
2-
using System.Collections;
3-
using System.Linq;
2+
using System.Collections.Generic;
43
using System.Threading;
54

65
using WatchKit;
76
using Foundation;
87

9-
using NUnit.Framework.Internal.Filters;
108
using MonoTouch.NUnit.UI;
119

1210
public static partial class TestLoader
@@ -70,16 +68,19 @@ public override void Awake (NSObject context)
7068

7169
void LoadTests ()
7270
{
71+
var excludeCategories = new [] {
72+
"MobileNotWorking",
73+
"NotOnMac",
74+
"NotWorking",
75+
"ValueAdd",
76+
"CAS",
77+
"InetAccess",
78+
"NotWorkingLinqInterpreter",
79+
"RequiresBSDSockets",
80+
"BitcodeNotSupported",
81+
};
7382
runner = new WatchOSRunner ();
74-
var categoryFilter = new NotFilter (new CategoryExpression ("MobileNotWorking,NotOnMac,NotWorking,ValueAdd,CAS,InetAccess,NotWorkingLinqInterpreter,RequiresBSDSockets,BitcodeNotSupported").Filter);
75-
if (!string.IsNullOrEmpty (Environment.GetEnvironmentVariable ("NUNIT_FILTER_START"))) {
76-
var firstChar = Environment.GetEnvironmentVariable ("NUNIT_FILTER_START") [0];
77-
var lastChar = Environment.GetEnvironmentVariable ("NUNIT_FILTER_END") [0];
78-
var nameFilter = new NameStartsWithFilter () { FirstChar = firstChar, LastChar = lastChar };
79-
runner.Filter = new AndFilter (categoryFilter, nameFilter);
80-
} else {
81-
runner.Filter = categoryFilter;
82-
}
83+
runner.ExcludedCategories = new HashSet<string> (excludeCategories);
8384
runner.Add (GetType ().Assembly);
8485
TestLoader.AddTestAssemblies (runner);
8586
ThreadPool.QueueUserWorkItem ((v) =>
@@ -153,35 +154,3 @@ partial void RunTests (NSObject obj)
153154
}
154155
}
155156
}
156-
157-
class NameStartsWithFilter : NUnit.Framework.Internal.TestFilter
158-
{
159-
public char FirstChar;
160-
public char LastChar;
161-
162-
public override bool Match (NUnit.Framework.Api.ITest test)
163-
{
164-
if (test is NUnit.Framework.Internal.TestAssembly)
165-
return true;
166-
167-
var method = test as NUnit.Framework.Internal.TestMethod;
168-
if (method != null)
169-
return Match (method.Parent);
170-
171-
var name = !string.IsNullOrEmpty (test.Name) ? test.Name : test.FullName;
172-
bool rv;
173-
if (string.IsNullOrEmpty (name)) {
174-
rv = true;
175-
} else {
176-
var z = Char.ToUpperInvariant (name [0]);
177-
rv = z >= Char.ToUpperInvariant (FirstChar) && z <= Char.ToUpperInvariant (LastChar);
178-
}
179-
180-
return rv;
181-
}
182-
183-
public override bool Pass (NUnit.Framework.Api.ITest test)
184-
{
185-
return Match (test);
186-
}
187-
}

tests/templates/WatchExtension/InterfaceController.fs

+14-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
namespace monotouchtestWatchKitExtension
22

33
open System
4-
open System.Collections
5-
open System.Linq
4+
open System.Collections.Generic
65
open System.Threading
76

87
open WatchKit
98
open Foundation
109

11-
open NUnit.Framework.Internal.Filters
1210
open MonoTouch.NUnit.UI
1311

1412
[<Register ("InterfaceController")>]
@@ -34,9 +32,20 @@ type InterfaceController (handle: IntPtr) =
3432
member val cmdRun = Unchecked.defaultof<WKInterfaceButton> with get, set
3533

3634
member this.LoadTests () =
35+
let excludeCategories =
36+
[|
37+
"MobileNotWorking"
38+
"NotOnMac"
39+
"NotWorking"
40+
"ValueAdd"
41+
"CAS"
42+
"InetAccess"
43+
"NotWorkingLinqInterpreter"
44+
"RequiresBSDSockets"
45+
"BitcodeNotSupported"
46+
|]
3747
runner <- new WatchOSRunner ()
38-
let ce = new CategoryExpression ("MobileNotWorking,NotOnMac,NotWorking,ValueAdd,CAS,InetAccess,NotWorkingLinqInterpreter,BitcodeNotSupported")
39-
runner.Filter <- new NotFilter (ce.Filter)
48+
runner.ExcludedCategories <- new HashSet<string> (excludeCategories :> IEnumerable<string>)
4049
let tp = this.GetType ()
4150
runner.Add (tp.Assembly)
4251
ThreadPool.QueueUserWorkItem (fun v ->

0 commit comments

Comments
 (0)