Ejemplo n.º 1
0
        static int Main2(string[] args)
        {
            try
            {
                //
                // Route trace output to stdout
                //
                Trace.Listeners.Add(new TestRunnerTraceListener());

                //
                // Parse arguments
                //
                var argumentParser = new ArgumentParser(args);
                if (!argumentParser.Success)
                {
                    Console.Out.WriteLine();
                    Console.Out.WriteLine(ArgumentParser.Usage);
                    Console.Out.WriteLine();
                    Console.Out.WriteLine();
                    Console.Out.WriteLine(argumentParser.ErrorMessage);
                    return(1);
                }

                //
                // If --inproc <testassembly>, run tests in <testassembly>
                //
                if (argumentParser.InProc)
                {
                    return(RunTestAssembly(argumentParser.AssemblyPaths[0]) ? 0 : 1);
                }

                //
                // Print program banner
                //
                Banner();

                //
                // Reinvoke TestRunner --inproc for each <testassembly> on command line
                //
                bool success = true;
                foreach (var assemblyPath in argumentParser.AssemblyPaths)
                {
                    if (ExecuteInNewProcess(assemblyPath) != 0)
                    {
                        success = false;
                    }
                }
                return(success ? 0 : 1);
            }

            //
            // Handle user-facing errors
            //
            catch (UserException ue)
            {
                Console.Out.WriteLine();
                Console.Out.WriteLine(ue.Message);
                return(1);
            }

            //
            // Handle internal errors
            //
            catch (Exception e)
            {
                Console.Out.WriteLine();
                Console.Out.WriteLine(
                    "An internal error occurred in {0}:",
                    Path.GetFileName(Assembly.GetExecutingAssembly().Location));
                Console.Out.WriteLine(ExceptionExtensions.FormatException(e));
                return(1);
            }
        }