Beispiel #1
0
        /// <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)
        {
            // NOTE: Execute must be directly called from the
            // test assembly in order for the mechanism to work.
            Assembly callingAssembly = Assembly.GetCallingAssembly();

            this.commandLineOptions = new CommandLineOptions();
            commandLineOptions.Parse(args);

            if (commandLineOptions.OutFile != null)
                this.writer = new StreamWriter(commandLineOptions.OutFile);

            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");

                // We only have one commandline option that has to be passed
                // to the runner, so we do it here for convenience.
                var runnerSettings = new Dictionary<string, object>();
                Randomizer.InitialSeed = commandLineOptions.InitialSeed;

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

                try
                {
                    foreach (string name in commandLineOptions.Parameters)
                        assemblies.Add(Assembly.Load(name));

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

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

                    //Randomizer.InitialSeed = commandLineOptions.InitialSeed;

                    if (runner.Load(assembly, runnerSettings) == null)
                    {
                        var 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);
                        }

                        RunTests(filter);
                    }
                }
                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();
                    }
                }
            }
        }
Beispiel #2
0
        /// <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)
        {
            // NOTE: Execute must be directly called from the
            // test assembly in order for the mechanism to work.
            Assembly callingAssembly = Assembly.GetCallingAssembly();

            this.commandLineOptions = new CommandLineOptions();
            commandLineOptions.Parse(args);

            if (commandLineOptions.OutFile != null)
                this.writer = new StreamWriter(commandLineOptions.OutFile);

            if (!commandLineOptions.NoHeader)
                WriteHeader();

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

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

                IDictionary loadOptions = new Hashtable();
                //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
                {
                    foreach (string name in commandLineOptions.Parameters)
                        assemblies.Add(Assembly.Load(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))
                    {
                        Console.WriteLine("No tests found in assembly {0}", assembly.GetName().Name);
                        return;
                    }

                    if (commandLineOptions.Explore)
                        ExploreTests();
                    else
                        RunTests(filter);
                }
                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();
                    }
                }
            }
        }
Beispiel #3
0
        /// <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)
        {
            // NOTE: Execute must be directly called from the
            // test assembly in order for the mechanism to work.
            Assembly callingAssembly = Assembly.GetCallingAssembly();

            this.commandLineOptions = new CommandLineOptions();
            commandLineOptions.Parse(args);

            if (commandLineOptions.OutFile != null)
                this.writer = new StreamWriter(commandLineOptions.OutFile);

            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
                {
                    foreach (string name in commandLineOptions.Parameters)
                        assemblies.Add(Assembly.Load(name));

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

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

                    Randomizer.InitialSeed = commandLineOptions.InitialSeed;

                    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);
                        }

                        RunTests(filter);
                    }
                }
                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();
                    }
                }
            }
        }
Beispiel #4
0
        private CommandLineOptions ProcessArguments(string[] args)
        {
            this.options = new CommandLineOptions();
            options.Parse(args);

            if (!options.Nologo)
                WriteCopyright();

            if (options.Help)
                writer.Write(options.HelpText);
            else if (options.Error)
                writer.WriteLine(options.ErrorMessage);

            return options;
        }
Beispiel #5
0
        private CommandLineOptions ProcessArguments(string[] args)
        {
            this.commandLineOptions = new CommandLineOptions();
            commandLineOptions.Parse(args);

            if (commandLineOptions.OutFile != null)
                this.writer = new StreamWriter(commandLineOptions.OutFile);
            else
                this.writer = ConsoleWriter.Out;

            if (!commandLineOptions.NoHeader)
                WriteCopyright();

            if (commandLineOptions.ShowHelp)
                writer.Write(commandLineOptions.HelpText);
            else if (commandLineOptions.Error)
                writer.WriteLine(commandLineOptions.ErrorMessage);

            return commandLineOptions;
        }
Beispiel #6
0
        /// <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)
        {
            // NOTE: Execute must be directly called from the
            // test assembly in order for the mechanism to work.
            Assembly callingAssembly = Assembly.GetCallingAssembly();

            this.commandLineOptions = new CommandLineOptions();
            commandLineOptions.Parse(args);

            if (commandLineOptions.OutFile != null)
            {
                this.writer = new StreamWriter(commandLineOptions.OutFile);
            }

            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");
                }

                // We only have one commandline option that has to be passed
                // to the runner, so we do it here for convenience.
                var runnerSettings = new Dictionary <string, object>();
                if (commandLineOptions.InitialSeed >= 0)
                {
                    runnerSettings[DriverSettings.RandomSeed] = commandLineOptions.InitialSeed;
                }

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

                try
                {
                    foreach (string name in commandLineOptions.Parameters)
                    {
                        assemblies.Add(Assembly.Load(name));
                    }

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

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

                    //Randomizer.InitialSeed = commandLineOptions.InitialSeed;

                    if (runner.Load(assembly, runnerSettings) == null)
                    {
                        var 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);
                            }
                        }

                        RunTests(filter);
                    }
                }
                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();
                    }
                }
            }
        }
Beispiel #7
0
		/// <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);
		}
        /// <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);
            }

            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
                {
                    foreach (string name in commandLineOptions.Parameters)
                    {
                        try {
                            assemblies.Add(Assembly.LoadFrom(name));
                        }
                        catch (FileNotFoundException /* e*/) {
                            assemblies.Add(Assembly.Load(name));
                        }
                    }

                    if (assemblies.Count == 0)
                    {
                        // NOTE: Execute must be directly called from the
                        // test assembly in order for the mechanism to work.
                        Assembly callingAssembly = Assembly.GetCallingAssembly();
                        assemblies.Add(callingAssembly);
                    }

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

                    Randomizer.InitialSeed = commandLineOptions.InitialSeed;

                    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 MONO
                        filter = Xamarin.BabysitterSupport.AddBabysitterFilter(filter);
#endif
                        RunTests(filter);
                    }
                }
                catch (FileNotFoundException ex)
                {
                    Failure = true;
                    writer.WriteLine(ex.Message);
                }
                catch (Exception ex)
                {
                    Failure = true;
                    writer.WriteLine(ex.ToString());
                }
                finally
                {
                    if (commandLineOptions.OutFile == null)
                    {
                        if (commandLineOptions.Wait)
                        {
                            Console.WriteLine("Press Enter key to continue . . .");
                            Console.ReadLine();
                        }
                    }
                    else
                    {
                        writer.Close();
                    }
                }
            }
        }