Skip to content
Browse files

Added Filter (F) and Clear Filters (H) interactive console options. F…

…ilters are added as part of GilesConfig, passed to the GilesAppDomainManager, and then to the App Domain runner. Only tests matching the full namespace + classname are run. Option H clears the class filters.
  • Loading branch information...
1 parent c47aece commit a14a1c5bfe4296189e79f6c17c78a7b59ddab52f @codereflection committed Jan 18, 2012
View
4 src/Giles.Core/AppDomains/GilesAppDomainManager.cs
@@ -17,15 +17,15 @@ public class GilesAppDomainManager
public Func<IFileSystem> GetFileSystem = () => FileSystem;
- public IEnumerable<SessionResults> Run(string testAssemblyPath)
+ public IEnumerable<SessionResults> Run(string testAssemblyPath, List<string> filters)
{
IEnumerable<SessionResults> results = new List<SessionResults>();
GilesAppDomainRunner runner;
try
{
runner = SetupRunner(testAssemblyPath);
- results = runner.Run(testAssemblyPath);
+ results = runner.Run(testAssemblyPath, filters);
}
catch (InvalidOperationException e)
{
View
6 src/Giles.Core/AppDomains/GilesAppDomainRunner.cs
@@ -12,14 +12,16 @@ namespace Giles.Core.AppDomains
/// </summary>
public class GilesAppDomainRunner : MarshalByRefObject
{
- public IEnumerable<SessionResults> Run(string testAssemblyPath)
+ public IEnumerable<SessionResults> Run(string testAssemblyPath, List<string> filters)
{
var testAssembly = Assembly.LoadFrom(testAssemblyPath);
var testFrameworkRunner = new TestFrameworkResolver().Resolve(testAssembly).ToList();
var result = new List<SessionResults>();
- testFrameworkRunner.ForEach(x => result.Add(x.RunAssembly(testAssembly, new[] { "Teh.Tests.TestTheClassThatDoesReturnsSomething", "Teh.Tests.NUnitTests" })));
+ testFrameworkRunner.ForEach(x =>
+ result.Add(
+ x.RunAssembly(testAssembly, filters)));
return result;
}
}
View
1 src/Giles.Core/Configuration/GilesConfig.cs
@@ -9,6 +9,7 @@ public class GilesConfig : INotifyPropertyChanged
public IDictionary<string, RunnerAssembly> TestRunners = new Dictionary<string, RunnerAssembly>();
public List<IUserDisplay> UserDisplay = new List<IUserDisplay>();
private long buildDelay = 500;
+ public List<string> Filters { get; set; }
public List<string> TestAssemblies { get; set; }
public string SolutionPath { get; set; }
View
1 src/Giles.Core/Configuration/GilesConfigBuilder.cs
@@ -22,6 +22,7 @@ public GilesConfig Build()
config.UserDisplay.Add(new ConsoleUserDisplay());
config.UserDisplay.Add(new GrowlUserDisplay());
+ config.Filters = new List<string>();
return config;
}
}
View
2 src/Giles.Core/Watchers/SourceWatcher.cs
@@ -95,7 +95,7 @@ public void RunNow()
var watch = new Stopwatch();
watch.Start();
- config.TestAssemblies.Each(assm => runResults.AddRange(manager.Run(assm)));
+ config.TestAssemblies.Each(assm => runResults.AddRange(manager.Run(assm, config.Filters)));
watch.Stop();
Console.WriteLine("Test run completed in {0} seconds", watch.Elapsed.TotalSeconds);
View
49 src/Giles/Program.cs
@@ -136,7 +136,9 @@ static InteractiveMenuOption[] GetInteractiveMenuOptions()
new InteractiveMenuOption { HandlesKey = key => key == "b", Task = SetBuildDelay },
new InteractiveMenuOption { HandlesKey = key => key == "q", Task = RequestQuit },
new InteractiveMenuOption { HandlesKey = key => key == "v", Task = DisplayVerboseResults },
- new InteractiveMenuOption { HandlesKey = key => key == "e", Task = DisplayErrors }
+ new InteractiveMenuOption { HandlesKey = key => key == "e", Task = DisplayErrors },
+ new InteractiveMenuOption { HandlesKey = key => key == "f", Task = SetTestFilters },
+ new InteractiveMenuOption { HandlesKey = key => key == "h", Task = ClearTestFilters },
};
}
@@ -159,9 +161,22 @@ static void RequestQuit()
quitRequested = true;
}
+ static void SetTestFilters()
+ {
+ config.Filters = GetUserValues("Filters", config.Filters);
+ Console.WriteLine("Filters set to:");
+ config.Filters.Each(x => Console.WriteLine("\t{0}", x));
+ }
+
+ static void ClearTestFilters()
+ {
+ config.Filters = new List<string>();
+ Console.WriteLine("Test filters cleared");
+ }
+
static void SetBuildDelay()
{
- config.BuildDelay = GetUserValue(config.BuildDelay);
+ config.BuildDelay = GetUserValue("Build Delay", config.BuildDelay);
}
static void DisplayErrors()
@@ -180,9 +195,25 @@ static void DisplayVerboseResults()
Console.WriteLine("Please run some tests first...");
}
- static T GetUserValue<T>(T defaultValue)
+ static List<T> GetUserValues<T>(string description, List<T> defaultValues)
{
- Console.Write("Enter new value ({0}): ", defaultValue);
+ Console.WriteLine("Enter new values, one on each line. Blank line save.");
+ var newValues = new List<T>();
+
+ string newLine;
+ do
+ {
+ newLine = Console.ReadLine();
+ if (!string.IsNullOrWhiteSpace(newLine))
+ newValues.Add((T)Convert.ChangeType(newLine, typeof(T)));
+ }
+ while (!string.IsNullOrWhiteSpace(newLine));
+ return newValues;
+ }
+
+ static T GetUserValue<T>(string description, T defaultValue)
+ {
+ Console.Write("Enter new value for {0} ({1}): ", description, defaultValue);
var newValue = Console.ReadLine();
if (string.IsNullOrWhiteSpace(newValue))
@@ -198,6 +229,7 @@ static void DisplayConfig()
Console.WriteLine(" Solution: {0}", config.SolutionPath);
Console.WriteLine(" Test Assemblies: \n\t{0}", GetTestAssemblyListAsString());
config.TestRunners.Each(r => Console.WriteLine(" {0} Has been enabled", r.Key));
+ Console.WriteLine(" Test Filters: \n\t{0}", GetTestFilterListAsString());
Console.WriteLine();
}
@@ -206,6 +238,13 @@ static string GetTestAssemblyListAsString()
return config.TestAssemblies.Aggregate((next, working) => working = working + Environment.NewLine + "\t" + next);
}
+ static string GetTestFilterListAsString()
+ {
+ return config.Filters.Count == 0
+ ? "<All Classes>"
+ : config.Filters.Aggregate((next, working) => working = working + Environment.NewLine + "\t" + next);
+ }
+
static void DisplayInteractiveMenuOptions()
{
Console.WriteLine("Interactive Console Options:");
@@ -216,6 +255,8 @@ static void DisplayInteractiveMenuOptions()
Console.WriteLine(" V = Display all messages from last test run");
Console.WriteLine(" E = Display errors from last test run");
Console.WriteLine(" B = Set Build Delay");
+ Console.WriteLine(" F = Set Test Filters");
+ Console.WriteLine(" H = Clear Test Filters");
Console.WriteLine(" Q = Quit");
Console.WriteLine();
}
View
11 src/Runners/Giles.Runner.XUnit/XunitTestRunner.cs
@@ -1,18 +1,25 @@
using System.Collections.Generic;
+using System.Linq;
using Giles.Core.Runners;
using System;
+using Giles.Core.Utility;
using XunitFx = Xunit;
using System.Reflection;
namespace Giles.Runner.Xunit {
public class XunitTestRunner : IFrameworkRunner {
public SessionResults RunAssembly(Assembly assembly, IEnumerable<string> filters) {
- var sessionResults = new SessionResults();
+
var logger = new GilesXunitLogger();
+
using (var exWrapper = new XunitFx.ExecutorWrapper(new Uri(assembly.CodeBase).LocalPath, null, false)) {
var runner = new XunitFx.TestRunner(exWrapper, logger);
- var result = runner.RunAssembly();
+ if (filters.Count() == 0)
+ runner.RunAssembly();
+ else
+ filters.Each(x => runner.RunClass(x));
}
+
return logger.SessionResults;
}

0 comments on commit a14a1c5

Please sign in to comment.
Something went wrong with that request. Please try again.