3 #if SILICONSTUDIO_PLATFORM_IOS || SILICONSTUDIO_PLATFORM_ANDROID
28 using System.Collections.Generic;
30 using System.Reflection;
31 using NUnit.Framework.Api;
32 using NUnit.Framework.Api;
33 using NUnit.Framework.Internal;
34 using NUnit.Framework.Internal.Filters;
35 using NUnitLite.Runner;
37 namespace SiliconStudio.
Paradox.Graphics.Regression
57 private CommandLineOptions commandLineOptions;
59 private List<Assembly> assemblies =
new List<Assembly>();
63 private ITestAssemblyRunner runner;
70 public TextUI() : this(ConsoleWriter.
Out) { }
80 this.runner =
new NUnitLiteTestAssemblyRunner(
new NamespaceAssemblyBuilder(
new NUnitLiteTestAssemblyBuilder()));
84 #region Public Methods
90 public void Execute(
string[] args)
94 Assembly callingAssembly = Assembly.GetCallingAssembly();
96 this.commandLineOptions =
new CommandLineOptions();
97 commandLineOptions.Parse(args);
99 if (commandLineOptions.OutFile != null)
100 this.writer =
new StreamWriter(commandLineOptions.OutFile);
102 if (!commandLineOptions.NoHeader)
103 WriteHeader(this.writer);
105 if (commandLineOptions.ShowHelp)
106 writer.Write(commandLineOptions.HelpText);
107 else if (commandLineOptions.Error)
109 writer.WriteLine(commandLineOptions.ErrorMessage);
110 writer.WriteLine(commandLineOptions.HelpText);
114 WriteRuntimeEnvironment(this.writer);
116 if (commandLineOptions.Wait && commandLineOptions.OutFile != null)
117 writer.WriteLine(
"Ignoring /wait option - only valid for Console");
121 var runnerSettings =
new Dictionary<string, object>();
122 Randomizer.InitialSeed = commandLineOptions.InitialSeed;
124 TestFilter filter = commandLineOptions.TestCount > 0
125 ?
new SimpleNameFilter(commandLineOptions.Tests)
130 foreach (
string name
in commandLineOptions.Parameters)
131 assemblies.Add(Assembly.Load(name));
133 if (assemblies.Count == 0)
134 assemblies.Add(callingAssembly);
137 Assembly assembly = assemblies[0];
141 if (runner.Load(assembly, runnerSettings) == null)
143 var assemblyName = AssemblyHelper.GetAssemblyName(assembly);
144 Console.WriteLine(
"No tests found in assembly {0}", assemblyName.Name);
148 if (commandLineOptions.Explore)
152 if (commandLineOptions.Include != null && commandLineOptions.Include !=
string.Empty)
154 TestFilter includeFilter =
new SimpleCategoryExpression(commandLineOptions.Include).Filter;
157 filter = includeFilter;
159 filter =
new AndFilter(filter, includeFilter);
162 if (commandLineOptions.Exclude != null && commandLineOptions.Exclude !=
string.Empty)
164 TestFilter excludeFilter =
new NotFilter(
new SimpleCategoryExpression(commandLineOptions.Exclude).Filter);
167 filter = excludeFilter;
168 else if (filter is AndFilter)
169 ((AndFilter)filter).Add(excludeFilter);
171 filter =
new AndFilter(filter, excludeFilter);
177 catch (FileNotFoundException ex)
179 writer.WriteLine(ex.Message);
183 writer.WriteLine(ex.ToString());
187 if (commandLineOptions.OutFile == null)
189 if (commandLineOptions.Wait)
191 Console.WriteLine(
"Press Enter key to continue . . .");
205 #region Helper Methods
207 private void RunTests(ITestFilter filter)
209 DateTime now = DateTime.Now;
210 ITestResult result = runner.Run(
this, filter);
211 new ResultReporter(result, writer).ReportResults();
213 string resultFile = commandLineOptions.ResultFile;
214 string resultFormat = commandLineOptions.ResultFormat;
215 if (resultFile != null || commandLineOptions.ResultFormat != null)
217 if (resultFile == null)
218 resultFile =
"TestResult.xml";
220 if (resultFormat ==
"nunit2")
221 new NUnit2XmlOutputWriter(now).WriteResultFile(result, resultFile);
223 new NUnit3XmlOutputWriter(now).WriteResultFile(result, resultFile);
225 Console.WriteLine(
"Results saved as {0}.", resultFile);
229 private void ExploreTests()
231 XmlNode testNode = runner.LoadedTest.ToXml(
true);
233 string listFile = commandLineOptions.ExploreFile;
234 TextWriter textWriter = listFile != null && listFile.Length > 0
235 ?
new StreamWriter(listFile)
238 System.Xml.XmlWriterSettings settings =
new System.Xml.XmlWriterSettings();
239 settings.Indent =
true;
240 settings.Encoding = System.Text.Encoding.UTF8;
241 System.Xml.XmlWriter testWriter = System.Xml.XmlWriter.Create(textWriter, settings);
243 testNode.WriteTo(testWriter);
247 Console.WriteLine(
"Test info saved as {0}.", listFile);
254 public static void WriteHeader(
TextWriter writer)
256 Assembly executingAssembly = Assembly.GetExecutingAssembly();
257 AssemblyName assemblyName = AssemblyHelper.GetAssemblyName(executingAssembly);
259 string title =
"NUnitLite";
261 string title =
"NUNit Framework";
263 System.Version version = assemblyName.Version;
264 string copyright =
"Copyright (C) 2012, Charlie Poole";
267 object[] attrs = executingAssembly.GetCustomAttributes(typeof(AssemblyTitleAttribute),
false);
268 if (attrs.Length > 0)
270 AssemblyTitleAttribute titleAttr = (AssemblyTitleAttribute)attrs[0];
271 title = titleAttr.Title;
274 attrs = executingAssembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute),
false);
275 if (attrs.Length > 0)
277 AssemblyCopyrightAttribute copyrightAttr = (AssemblyCopyrightAttribute)attrs[0];
278 copyright = copyrightAttr.Copyright;
281 attrs = executingAssembly.GetCustomAttributes(typeof(AssemblyConfigurationAttribute),
false);
282 if (attrs.Length > 0)
284 AssemblyConfigurationAttribute configAttr = (AssemblyConfigurationAttribute)attrs[0];
285 build = string.Format(
"({0})", configAttr.Configuration);
288 writer.WriteLine(String.Format(
"{0} {1} {2}", title, version.ToString(3), build));
289 writer.WriteLine(copyright);
297 public static void WriteRuntimeEnvironment(
TextWriter writer)
299 string clrPlatform = Type.GetType(
"Mono.Runtime",
false) == null ?
".NET" :
"Mono";
300 writer.WriteLine(
"Runtime Environment -");
301 writer.WriteLine(
" OS Version: {0}", Environment.OSVersion);
302 writer.WriteLine(
" {0} Version: {1}", clrPlatform, Environment.Version);
309 #region ITestListener Members
315 public void TestStarted(ITest test)
317 if (commandLineOptions.LabelTestsInOutput)
318 writer.WriteLine(
"***** {0}", test.Name);
325 public void TestFinished(ITestResult result)
333 public void TestOutput(TestOutput testOutput)
Search for out only dependencies.
SiliconStudio.Paradox.Graphics.Regression.TextUI TextUI