コード例 #1
0
ファイル: TestRunner.cs プロジェクト: modulexcite/guiunit
		void ExecuteWithListener (string[] args, TcpWriter tcpWriter)
		{
			// NOTE: Execute must be directly called from the
			// test assembly in order for the mechanism to work.
			Assembly callingAssembly = Assembly.GetCallingAssembly();

			if (!commandLineOptions.NoHeader)
				WriteHeader(this.writer);

			if (commandLineOptions.ShowHelp)
				writer.Write(commandLineOptions.HelpText);
			else if (commandLineOptions.Error)
			{
				writer.WriteLine(commandLineOptions.ErrorMessage);
				writer.WriteLine(commandLineOptions.HelpText);
			}
			else
			{
				WriteRuntimeEnvironment(this.writer);

				if (commandLineOptions.Wait && commandLineOptions.OutFile != null)
					writer.WriteLine("Ignoring /wait option - only valid for Console");

				#if SILVERLIGHT
				IDictionary loadOptions = new System.Collections.Generic.Dictionary<string, string>();
				#else
				IDictionary loadOptions = new Hashtable();
				#endif
				//if (options.Load.Count > 0)
				//    loadOptions["LOAD"] = options.Load;

				//IDictionary runOptions = new Hashtable();
				//if (commandLineOptions.TestCount > 0)
				//    runOptions["RUN"] = commandLineOptions.Tests;

				ITestFilter filter = commandLineOptions.TestCount > 0
					? new SimpleNameFilter(commandLineOptions.Tests)
						: TestFilter.Empty;

				try
				{
					if (TestRunner.LoadFileMethod != null) {
						foreach (string name in commandLineOptions.Parameters)
							assemblies.Add (TestRunner.LoadFileMethod.Invoke (null, new[] { Path.GetFullPath (name) }));
					}

					if (assemblies.Count == 0)
						assemblies.Add(callingAssembly);

					// TODO: For now, ignore all but first assembly
					Assembly assembly = assemblies[0] as Assembly;

					if (!runner.Load(assembly, loadOptions))
					{
						AssemblyName assemblyName = AssemblyHelper.GetAssemblyName(assembly);
						Console.WriteLine("No tests found in assembly {0}", assemblyName.Name);
						return;
					}

					if (commandLineOptions.Explore)
						ExploreTests();
					else
					{
						if (commandLineOptions.Include != null && commandLineOptions.Include != string.Empty)
						{
							TestFilter includeFilter = new SimpleCategoryExpression(commandLineOptions.Include).Filter;

							if (filter.IsEmpty)
								filter = includeFilter;
							else
								filter = new AndFilter(filter, includeFilter);
						}

						if (commandLineOptions.Exclude != null && commandLineOptions.Exclude != string.Empty)
						{
							TestFilter excludeFilter = new NotFilter(new SimpleCategoryExpression(commandLineOptions.Exclude).Filter);

							if (filter.IsEmpty)
								filter = excludeFilter;
							else if (filter is AndFilter)
								((AndFilter)filter).Add(excludeFilter);
							else
								filter = new AndFilter(filter, excludeFilter);
						}

						if (MainLoop == null) {
							RunTests (filter);
						} else {
							MainLoop.InitializeToolkit ();
							System.Threading.ThreadPool.QueueUserWorkItem (d => {
								RunTests (filter);
								Shutdown ();
							});
							MainLoop.RunMainLoop ();
						}
					}
				}
				catch (FileNotFoundException ex)
				{
					writer.WriteLine(ex.Message);
				}
				catch (Exception ex)
				{
					writer.WriteLine(ex.ToString());
				}
				finally
				{
					if (commandLineOptions.OutFile == null)
					{
						if (commandLineOptions.Wait)
						{
							Console.WriteLine("Press Enter key to continue . . .");
							Console.ReadLine();
						}
					}
					else
					{
						writer.Close();
					}
				}
			}
		}
コード例 #2
0
ファイル: TestRunner.cs プロジェクト: modulexcite/guiunit
		/// <summary>
		/// Execute a test run based on the aruments passed
		/// from Main.
		/// </summary>
		/// <param name="args">An array of arguments</param>
		public void Execute(string[] args)
		{
			this.commandLineOptions = new CommandLineOptions();
			commandLineOptions.Parse(args);

			if (commandLineOptions.OutFile != null)
				this.writer = new StreamWriter(commandLineOptions.OutFile);
			
			
			TcpWriter tcpWriter = null;
			if (listener == TestListener.NULL && commandLineOptions.Port != -1) {
				tcpWriter = new TcpWriter (new IPEndPoint (IPAddress.Loopback, commandLineOptions.Port));
				listener = new XmlTestListener (tcpWriter);
			}

			// Ensure we always dispose the socket correctly.
			using (tcpWriter)
				ExecuteWithListener (args, tcpWriter);
		}