示例#1
0
        public int EntryPoint(string[] args)
        {
            commandLine = CommandLine.Parse(args);

            try
            {
                var reporters = GetAvailableRunnerReporters();

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

                if (commandLine.Project.Assemblies.Count == 0)
                {
                    throw new ArgumentException("must specify at least one assembly");
                }

#if NETFRAMEWORK
                AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
#endif

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

                var defaultDirectory = Directory.GetCurrentDirectory();
                if (!defaultDirectory.EndsWith(new string(new[] { Path.DirectorySeparatorChar }), StringComparison.Ordinal))
                {
                    defaultDirectory += Path.DirectorySeparatorChar;
                }

                var reporter = commandLine.ChooseReporter(reporters);

                if (commandLine.Pause)
                {
                    Console.Write("Press any key to start execution...");
                    Console.ReadKey(true);
                    Console.WriteLine();
                }

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

                logger = new ConsoleRunnerLogger(!commandLine.NoColor, consoleLock);
                reporterMessageHandler = MessageSinkWithTypesAdapter.Wrap(reporter.CreateMessageHandler(logger));

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

                var failCount = RunProject(commandLine.Project, commandLine.Serialize, commandLine.ParallelizeAssemblies,
                                           commandLine.ParallelizeTestCollections, commandLine.MaxParallelThreads,
                                           commandLine.DiagnosticMessages, commandLine.NoColor, commandLine.AppDomains,
                                           commandLine.FailSkips, commandLine.StopOnFail, commandLine.InternalDiagnosticMessages);

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

                return(failCount > 0 ? 1 : 0);
            }
            catch (Exception ex)
            {
                if (!commandLine.NoColor)
                {
                    ConsoleHelper.SetForegroundColor(ConsoleColor.Red);
                }

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

                if (commandLine.InternalDiagnosticMessages)
                {
                    if (!commandLine.NoColor)
                    {
                        ConsoleHelper.SetForegroundColor(ConsoleColor.DarkGray);
                    }

                    Console.WriteLine(ex.StackTrace);
                }

                return(ex is ArgumentException ? 3 : 4);
            }
            finally
            {
                if (!commandLine.NoColor)
                {
                    ConsoleHelper.ResetColor();
                }
            }
        }
示例#2
0
        public static int Main(string[] args)
        {
            try
            {
                var reporters = GetAvailableRunnerReporters();

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

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

                var defaultDirectory = Directory.GetCurrentDirectory();
                if (!defaultDirectory.EndsWith(new string(new[] { Path.DirectorySeparatorChar }), StringComparison.Ordinal))
                {
                    defaultDirectory += Path.DirectorySeparatorChar;
                }

                var commandLine = CommandLine.Parse(reporters, args);

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

                logger = new ConsoleRunnerLogger(!commandLine.NoColor);
                reporterMessageHandler = MessageSinkWithTypesAdapter.Wrap(commandLine.Reporter.CreateMessageHandler(logger));

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

                var failCount = RunProject(commandLine.Project, commandLine.Serialize, commandLine.ParallelizeAssemblies,
                                           commandLine.ParallelizeTestCollections, commandLine.MaxParallelThreads,
                                           commandLine.DiagnosticMessages, commandLine.NoColor, commandLine.NoAppDomain,
                                           commandLine.FailSkips);

                if (commandLine.Wait)
                {
                    Console.WriteLine();
                    Console.Write("Press any key to continue...");
                    Console.ReadKey();
                    Console.WriteLine();
                }

                return(failCount > 0 ? 1 : 0);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine($"error: {ex.Message}");
                return(3);
            }
            catch (BadImageFormatException ex)
            {
                Console.WriteLine(ex.Message);
                return(4);
            }
            finally
            {
                Console.ResetColor();
            }
        }
示例#3
0
        public static int Main(string[] args)
        {
            try
            {
                Console.ForegroundColor = ConsoleColor.White;
#if !NETCORE
                var netVersion = Environment.Version;
#else
                var netVersion = "Core";
#endif
                Console.WriteLine("xUnit.net console test runner ({0}-bit .NET {1})", IntPtr.Size * 8, netVersion);
                Console.WriteLine("Copyright (C) 2014 Outercurve Foundation.");
                Console.WriteLine();
                Console.ForegroundColor = ConsoleColor.Gray;

                if (args.Length == 0 || args[0] == "-?")
                {
                    PrintUsage();
                    return(1);
                }

#if !NETCORE
                AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;
#endif
                try
                {
                    Console.CancelKeyPress += (sender, e) =>
                    {
                        if (!cancel)
                        {
                            Console.WriteLine("Canceling... (Press Ctrl+C again to terminate)");
                            cancel   = true;
                            e.Cancel = true;
                        }
                    };
                }
                catch (PlatformNotSupportedException)
                {
                    Debug.WriteLine("Ignoring PlatformNotSupportedException from Console PAL");
                }

                var defaultDirectory = Directory.GetCurrentDirectory();
                if (!defaultDirectory.EndsWith(new String(new[] { Path.DirectorySeparatorChar })))
                {
                    defaultDirectory += Path.DirectorySeparatorChar;
                }

                var commandLine = CommandLine.Parse(args);

                if (commandLine.RedirectOutput)
                {
                    // Workaround for NetCore50 (UWP) implementations:
                    // When running against a version that will be no-op'ing the
                    // standard output stream, we will just redirect console output to a well known file name.
                    //
                    // This allows the most recent run's output to be logged.  Could allow customization if it's interesting later.
                    StreamWriter textFileOutput = new StreamWriter(new FileStream("Xunit.Console.Output.txt", FileMode.Create))
                    {
                        AutoFlush = true
                    };
                    Console.SetOut(textFileOutput);
                    // Repeat output for consistency.
                    Console.WriteLine("xUnit.net console test runner ({0}-bit .NET {1})", IntPtr.Size * 8, netVersion);
                    Console.WriteLine("Copyright (C) 2014 Outercurve Foundation.");
                    Console.WriteLine();
                }

                var failCount = RunProject(defaultDirectory, commandLine.Project, commandLine.TeamCity, commandLine.AppVeyor, commandLine.ShowProgress,
                                           commandLine.ParallelizeAssemblies, commandLine.ParallelizeTestCollections,
                                           commandLine.MaxParallelThreads);

                if (commandLine.Wait)
                {
                    Console.WriteLine();
                    Console.Write("Press enter key to continue...");
                    Console.ReadLine();
                    Console.WriteLine();
                }

                return(failCount);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine("error: {0}", ex.Message);
                return(1);
            }
            catch (BadImageFormatException ex)
            {
                Console.WriteLine("{0}", ex.Message);
                return(1);
            }
            finally
            {
                Console.ResetColor();
            }
        }