예제 #1
0
        static int Main(string[] args)
        {
            // Handle RemoteExecutor
            if (args.Length > 0 && args[0] == "remote")
            {
                return(RemoteExecutor.Execute(args.Skip(1).ToArray()));
            }

            var commandLine = CommandLine.Parse(args);

            if (commandLine.Debug)
            {
                Debugger.Launch();
            }

            var completionMessages = new ConcurrentDictionary <string, ExecutionSummary>();
            var assembliesElement  = new XElement("assemblies");

            int errorCount = 0;
            int failCount  = 0;

            foreach (var assembly in commandLine.Project.Assemblies)
            {
                if (cancel)
                {
                    break;
                }

                assembly.Configuration.PreEnumerateTheories = false;
                assembly.Configuration.DiagnosticMessages  |= commandLine.DiagnosticMessages;
                assembly.Configuration.AppDomain            = AppDomainSupport.Denied;
                var discoveryOptions = TestFrameworkOptions.ForDiscovery(assembly.Configuration);
                var executionOptions = TestFrameworkOptions.ForExecution(assembly.Configuration);
                executionOptions.SetDisableParallelization(true);

                try
                {
                    using (var xunit = new XunitFrontController(AppDomainSupport.Denied, assembly.AssemblyFilename, assembly.ConfigFilename, assembly.Configuration.ShadowCopyOrDefault))
                        using (var discoveryVisitor = new TestDiscoveryVisitor())
                        {
                            string assemblyName = Path.GetFileNameWithoutExtension(assembly.AssemblyFilename);
                            // Discover & filter the tests
                            Console.WriteLine($"Discovering: {assemblyName}");
                            xunit.Find(false, discoveryVisitor, discoveryOptions);
                            discoveryVisitor.Finished.WaitOne();

                            var testCasesDiscovered = discoveryVisitor.TestCases.Count;
                            var filteredTestCases   = discoveryVisitor.TestCases.Where(commandLine.Project.Filters.Filter).ToList();
                            var testCasesToRun      = filteredTestCases.Count;

                            Console.WriteLine($"Discovered:  {assemblyName}");

                            // Run the filtered tests
                            if (testCasesToRun == 0)
                            {
                                Console.WriteLine($"Info:        {assemblyName} has no tests to run");
                            }
                            else
                            {
                                if (commandLine.Serialize)
                                {
                                    filteredTestCases = filteredTestCases.Select(xunit.Serialize).Select(xunit.Deserialize).ToList();
                                }

                                var assemblyElement = new XElement("assembly");

                                StandardUapVisitor resultsVisitor = new StandardUapVisitor(assemblyElement, () => cancel, completionMessages, commandLine.ShowProgress, commandLine.FailSkips);

                                xunit.RunTests(filteredTestCases, resultsVisitor, executionOptions);

                                resultsVisitor.Finished.WaitOne();

                                assembliesElement.Add(assemblyElement);

                                // Set counters to determine the error code later.
                                errorCount += resultsVisitor.ExecutionSummary.Errors;
                                failCount  += resultsVisitor.ExecutionSummary.Failed;

                                Console.WriteLine($"{Path.GetFileNameWithoutExtension(assembly.AssemblyFilename)}  Total: {resultsVisitor.ExecutionSummary.Total}, Errors: {resultsVisitor.ExecutionSummary.Errors}, Failed: {resultsVisitor.ExecutionSummary.Failed}, Skipped: {resultsVisitor.ExecutionSummary.Skipped}, Time: {resultsVisitor.ExecutionSummary.Time}");
                            }
                        }
                }
                catch (Exception e)
                {
                    assembliesElement = new XElement("error");
                    assembliesElement.Add(e);
                    Console.WriteLine(e);
                }
                finally
                {
                    WriteResults(Path.GetFileName(assembly.AssemblyFilename), assembliesElement).GetAwaiter().GetResult();
                }
            }

            if (errorCount > 0)
            {
                return(2);
            }
            else if (failCount > 0)
            {
                return(1);
            }

            return(0);
        }
예제 #2
0
파일: Program.cs 프로젝트: sharwell/arcade
        static int Main(string[] args)
        {
            // Handle RemoteExecutor
            if (args.Length > 0 && args[0] == "remote")
            {
                return(RemoteExecutor.Execute(args.Skip(1).ToArray()));
            }

            if (args.Length == 0 || args[0] == "-?" || args[0] == "/?" || args[0] == "-h" || args[0] == "--help")
            {
                PrintHeader();
                PrintUsage();
                return(2);
            }

            var commandLine = CommandLine.Parse(args);

            Console.CancelKeyPress += (sender, e) =>
            {
                if (!cancel)
                {
                    Console.WriteLine("Canceling... (Press Ctrl+C again to terminate)");
                    cancel   = true;
                    e.Cancel = true;
                }
            };

            if (commandLine.Debug)
            {
                Debugger.Launch();
            }

            if (!commandLine.NoLogo)
            {
                PrintHeader();
            }

            var completionMessages = new ConcurrentDictionary <string, ExecutionSummary>();
            var assembliesElement  = new XElement("assemblies");

            int errorCount = 0;
            int failCount  = 0;

            foreach (var assembly in commandLine.Project.Assemblies)
            {
                if (cancel)
                {
                    break;
                }

                assembly.Configuration.PreEnumerateTheories = false;
                assembly.Configuration.DiagnosticMessages  |= commandLine.DiagnosticMessages;
                assembly.Configuration.AppDomain            = AppDomainSupport.Denied;
                var discoveryOptions = TestFrameworkOptions.ForDiscovery(assembly.Configuration);
                var executionOptions = TestFrameworkOptions.ForExecution(assembly.Configuration);
                executionOptions.SetDisableParallelization(true);

                try
                {
                    using (var xunit = new XunitFrontController(AppDomainSupport.Denied, assembly.AssemblyFilename, assembly.ConfigFilename, assembly.Configuration.ShadowCopyOrDefault))
                        using (var discoveryVisitor = new TestDiscoveryVisitor())
                        {
                            string assemblyName = Path.GetFileNameWithoutExtension(assembly.AssemblyFilename);
                            // Discover & filter the tests
                            Console.WriteLine($"Discovering: {assemblyName}");
                            xunit.Find(false, discoveryVisitor, discoveryOptions);
                            discoveryVisitor.Finished.WaitOne();

                            var testCasesDiscovered = discoveryVisitor.TestCases.Count;
                            var filteredTestCases   = discoveryVisitor.TestCases.Where(commandLine.Project.Filters.Filter).ToList();
                            var testCasesToRun      = filteredTestCases.Count;

                            Console.WriteLine($"Discovered:  {assemblyName}");

                            // Run the filtered tests
                            if (testCasesToRun == 0)
                            {
                                Console.WriteLine($"Info:        {assemblyName} has no tests to run");
                            }
                            else
                            {
                                if (commandLine.Serialize)
                                {
                                    filteredTestCases = filteredTestCases.Select(xunit.Serialize).Select(xunit.Deserialize).ToList();
                                }

                                var assemblyElement = new XElement("assembly");

                                StandardUapVisitor resultsVisitor = new StandardUapVisitor(assemblyElement, () => cancel, completionMessages, commandLine.Verbose, commandLine.FailSkips);

                                xunit.RunTests(filteredTestCases, resultsVisitor, executionOptions);

                                resultsVisitor.Finished.WaitOne();

                                assembliesElement.Add(assemblyElement);

                                // Set counters to determine the error code later.
                                errorCount += resultsVisitor.ExecutionSummary.Errors;
                                failCount  += resultsVisitor.ExecutionSummary.Failed;

                                Console.WriteLine($"{Path.GetFileNameWithoutExtension(assembly.AssemblyFilename)}  Total: {resultsVisitor.ExecutionSummary.Total}, Errors: {resultsVisitor.ExecutionSummary.Errors}, Failed: {resultsVisitor.ExecutionSummary.Failed}, Skipped: {resultsVisitor.ExecutionSummary.Skipped}, Time: {resultsVisitor.ExecutionSummary.Time}");
                            }
                        }
                }
                catch (Exception ex)
                {
                    assembliesElement = new XElement("error");
                    assembliesElement.Add(ex);

                    if (!commandLine.NoColor)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                    }

                    Console.WriteLine($"error: {ex.Message}");

                    if (commandLine.DiagnosticMessages)
                    {
                        if (!commandLine.NoColor)
                        {
                            Console.ForegroundColor = ConsoleColor.DarkGray;
                        }

                        Console.WriteLine(ex.StackTrace);
                    }
                }
                finally
                {
                    if (!commandLine.NoColor)
                    {
                        Console.ResetColor();
                    }

                    WriteResults(Path.GetFileName(assembly.AssemblyFilename), assembliesElement).GetAwaiter().GetResult();
                }
            }

            if (cancel)
            {
                return(-1073741510);    // 0xC000013A: The application terminated as a result of a CTRL+C
            }
            if (commandLine.Wait)
            {
                Console.WriteLine();
                Console.Write("Press any key to continue...");
                Console.ReadKey();
                Console.WriteLine();
            }

            if (errorCount > 0 || failCount > 0)
            {
                return(1);
            }

            return(0);
        }