Usage() public static method

public static Usage ( ) : string
return string
        public ExitCode Run(string[] arguments)
        {
            ExceptionReporter reporter = new ExceptionReporter(_console);

            Options options = new Options();

            if (!options.ParseArguments(arguments))
            {
                _console.WriteLine(Options.Usage());
                return(ExitCode.Failure);
            }

            var timer     = new TimingRunListener();
            var listeners = new List <ISpecificationRunListener>
            {
                timer
            };

            ISpecificationRunListener mainListener;

            if (options.TeamCityIntegration ||
                (!options.DisableTeamCityAutodetection &&
                 Environment.GetEnvironmentVariable("TEAMCITY_PROJECT_NAME") != null))
            {
                mainListener = new TeamCityReporter(_console.WriteLine, timer);
            }
            else
            {
                mainListener = new RunListener(_console, DetermineOutput(options, _console), timer);
            }

            try
            {
                if (!String.IsNullOrEmpty(options.HtmlPath))
                {
                    if (IsHtmlPathValid(options.HtmlPath))
                    {
                        listeners.Add(GetHtmlReportListener(options));
                    }
                    else
                    {
                        _console.WriteLine("Invalid html path: {0}", options.HtmlPath);
                        _console.WriteLine(Options.Usage());
                        return(ExitCode.Failure);
                    }
                }

                if (!String.IsNullOrEmpty(options.XmlPath))
                {
                    if (IsHtmlPathValid(options.XmlPath))
                    {
                        listeners.Add(GetXmlReportListener(options, timer));
                    }
                    else
                    {
                        _console.WriteLine("Invalid xml path: {0}", options.XmlPath);
                        _console.WriteLine(Options.Usage());
                        return(ExitCode.Failure);
                    }
                }

                listeners.Add(mainListener);

                if (options.AssemblyFiles.Count == 0)
                {
                    _console.WriteLine(Options.Usage());
                    return(ExitCode.Failure);
                }

                var listener = new AggregateRunListener(listeners);

                ISpecificationRunner specificationRunner = new AppDomainRunner(listener, options.GetRunOptions());
                List <Assembly>      assemblies          = new List <Assembly>();
                foreach (string assemblyName in options.AssemblyFiles)
                {
                    if (!File.Exists(assemblyName))
                    {
                        throw NewException.MissingAssembly(assemblyName);
                    }

                    var excludedAssemblies = new[] { "Machine.Specifications.dll", "Machine.Specifications.Clr4.dll" };
                    if (excludedAssemblies.Any(x => Path.GetFileName(assemblyName) == x))
                    {
                        _console.WriteLine("Warning: Excluded {0} from the test run because the file name matches either of these: {1}", assemblyName, String.Join(", ", excludedAssemblies));
                        continue;
                    }

                    Assembly assembly = Assembly.LoadFrom(assemblyName);
                    assemblies.Add(assembly);
                }

                if (options.WaitForDebugger)
                {
                    WaitForDebugger();
                    if (Debugger.IsAttached == false)
                    {
                        _console.WriteLine("Fatal error: Timeout while waiting for debugger to attach");
                        return(ExitCode.Failure);
                    }
                }

                specificationRunner.RunAssemblies(assemblies);
            }
            catch (Exception ex)
            {
                reporter.ReportException(ex);
                return(ExitCode.Error);
            }

            if (mainListener is ISpecificationResultProvider)
            {
                var errorProvider = (ISpecificationResultProvider)mainListener;
                if (errorProvider.FailureOccurred)
                {
                    return(ExitCode.Failure);
                }
            }
            return(ExitCode.Success);
        }
        public ExitCode Run(string[] arguments)
        {
            ExceptionReporter reporter = new ExceptionReporter(_console);

            Options options = new Options();

            if (!options.ParseArguments(arguments))
            {
                _console.WriteLine(Options.Usage());
                return(ExitCode.Failure);
            }

            List <ISpecificationRunListener> listeners = new List <ISpecificationRunListener>();

            var timingListener = new TimingRunListener();

            listeners.Add(timingListener);
            listeners.Add(new AssemblyLocationAwareListener());

            ISpecificationRunListener mainListener;

            if (options.TeamCityIntegration ||
                (!options.DisableTeamCityAutodetection &&
                 Environment.GetEnvironmentVariable("TEAMCITY_PROJECT_NAME") != null))
            {
                mainListener = new TeamCityReporter(_console.WriteLine, timingListener);
            }
            else
            {
                mainListener = new RunListener(_console, options.Silent, timingListener);
            }

            try
            {
                if (!String.IsNullOrEmpty(options.HtmlPath))
                {
                    if (IsHtmlPathValid(options.HtmlPath))
                    {
                        listeners.Add(GetHtmlReportListener(options));
                    }
                    else
                    {
                        _console.WriteLine("Invalid html path:" + options.HtmlPath);
                        _console.WriteLine(Options.Usage());
                        return(ExitCode.Failure);
                    }
                }

                if (!String.IsNullOrEmpty(options.XmlPath))
                {
                    if (IsHtmlPathValid(options.XmlPath))
                    {
                        listeners.Add(GetXmlReportListener(options, timingListener));
                    }
                    else
                    {
                        _console.WriteLine("Invalid xml path:" + options.XmlPath);
                        _console.WriteLine(Options.Usage());
                        return(ExitCode.Failure);
                    }
                }

                listeners.Add(mainListener);

                if (options.AssemblyFiles.Count == 0)
                {
                    _console.WriteLine(Options.Usage());
                    return(ExitCode.Failure);
                }

                var listener = new AggregateRunListener(listeners);

                ISpecificationRunner specificationRunner = new AppDomainRunner(listener, options.GetRunOptions());
                List <Assembly>      assemblies          = new List <Assembly>();
                foreach (string assemblyName in options.AssemblyFiles)
                {
                    if (!File.Exists(assemblyName))
                    {
                        throw NewException.MissingAssembly(assemblyName);
                    }

                    Assembly assembly = Assembly.LoadFrom(assemblyName);
                    assemblies.Add(assembly);
                }

                if (options.WaitForDebugger)
                {
                    WaitForDebugger();
                    if (Debugger.IsAttached == false)
                    {
                        _console.WriteLine("Fatal error: Timeout while waiting for debugger to attach");
                        return(ExitCode.Failure);
                    }
                }

                specificationRunner.RunAssemblies(assemblies);
            }
            catch (Exception ex)
            {
                reporter.ReportException(ex);
                return(ExitCode.Error);
            }

            if (mainListener is ISpecificationResultProvider)
            {
                var errorProvider = (ISpecificationResultProvider)mainListener;
                if (errorProvider.FailureOccurred)
                {
                    return(ExitCode.Failure);
                }
            }
            return(ExitCode.Success);
        }
Beispiel #3
0
        public ExitCode Run(string[] arguments)
        {
            ExceptionReporter reporter = new ExceptionReporter(_console);

            Options options = new Options();

            if (!options.ParseArguments(arguments))
            {
                _console.WriteLine(Options.Usage());
                return(ExitCode.Failure);
            }

            List <ISpecificationRunListener> listeners = new List <ISpecificationRunListener>();

            var timingListener = new TimingRunListener();

            listeners.Add(timingListener);
            listeners.Add(new AssemblyLocationAwareListener());

            ISpecificationRunListener mainListener;

            if (options.TeamCityIntegration)
            {
                mainListener = new TeamCityReporter(_console.WriteLine, timingListener);
            }
            else
            {
                mainListener = new RunListener(_console, options.Silent, timingListener);
            }

            try
            {
                if (!String.IsNullOrEmpty(options.HtmlPath))
                {
                    if (IsHtmlPathValid(options.HtmlPath))
                    {
                        listeners.Add(GetHtmlReportListener(options));
                    }
                    else
                    {
                        _console.WriteLine("Invalid html path:" + options.HtmlPath);
                        _console.WriteLine(Options.Usage());
                        return(ExitCode.Failure);
                    }
                }

                if (!String.IsNullOrEmpty(options.XmlPath))
                {
                    if (IsHtmlPathValid(options.XmlPath))
                    {
                        listeners.Add(GetXmlReportListener(options, timingListener));
                    }
                    else
                    {
                        _console.WriteLine("Invalid xml path:" + options.XmlPath);
                        _console.WriteLine(Options.Usage());
                        return(ExitCode.Failure);
                    }
                }

                listeners.Add(mainListener);

                if (options.AssemblyFiles.Count == 0)
                {
                    _console.WriteLine(Options.Usage());
                    return(ExitCode.Failure);
                }

                var listener = new AggregateRunListener(listeners);

                ISpecificationRunner specificationRunner = new AppDomainRunner(listener, options.GetRunOptions());
                List <Assembly>      assemblies          = new List <Assembly>();
                foreach (string assemblyName in options.AssemblyFiles)
                {
                    if (!File.Exists(assemblyName))
                    {
                        throw NewException.MissingAssembly(assemblyName);
                    }

                    Assembly assembly = Assembly.LoadFrom(assemblyName);
                    assemblies.Add(assembly);
                }

                specificationRunner.RunAssemblies(assemblies);
            }
            catch (Exception ex)
            {
                reporter.ReportException(ex);
                return(ExitCode.Error);
            }

            if (mainListener is ISpecificationResultProvider)
            {
                var errorProvider = (ISpecificationResultProvider)mainListener;
                if (errorProvider.FailureOccurred)
                {
                    return(ExitCode.Failure);
                }
            }
            return(ExitCode.Success);
        }