private void DisplayRequestedOptions()
        {
            ColorConsole.WriteLine(ColorStyle.SectionHeader, "Options -");
            ColorConsole.WriteLabel("    ProcessModel: ", options.ProcessModel ?? "Default", false);
            ColorConsole.WriteLabel("    DomainUsage: ", options.DomainUsage ?? "Default", true);
            ColorConsole.WriteLabel("    Execution Runtime: ", options.Framework ?? "Not Specified", true);
            if (options.DefaultTimeout >= 0)
            {
                ColorConsole.WriteLabel("    Default timeout: ", options.DefaultTimeout.ToString(), true);
            }
            if (options.NumWorkers > 0)
            {
                ColorConsole.WriteLabel("    Worker Threads: ", options.NumWorkers.ToString(), true);
            }
            ColorConsole.WriteLabel("    Work Directory: ", workDirectory, true);
            ColorConsole.WriteLabel("    Internal Trace: ", options.InternalTraceLevel ?? "Off", true);
            //if (options.DisplayTeamCityServiceMessages)
            //    Console.WriteLine("    Display TeamCity Service Messages");
            Console.WriteLine();

            if (options.TestList.Count > 0)
            {
                ColorConsole.WriteLine(ColorStyle.Label, "Selected test(s):");
                using (new ColorConsole(ColorStyle.Default))
                    foreach (string testName in options.TestList)
                    {
                        Console.WriteLine("    " + testName);
                    }
            }

            if (!string.IsNullOrEmpty(options.Include))
            {
                ColorConsole.WriteLabel("Included categories: ", options.Include, true);
            }

            if (!string.IsNullOrEmpty(options.Exclude))
            {
                ColorConsole.WriteLabel("Excluded categories: ", options.Exclude, true);
            }
        }
Beispiel #2
0
        private static void WriteHeader()
        {
            Assembly executingAssembly = Assembly.GetExecutingAssembly();
            string   versionText       = executingAssembly.GetName().Version.ToString(3);

            string programName   = "NUnit Console Runner";
            string copyrightText = "Copyright (C) 2014 Charlie Poole.\r\nAll Rights Reserved.";
            string configText    = String.Empty;

            object[] attrs = executingAssembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
            if (attrs.Length > 0)
            {
                programName = ((AssemblyTitleAttribute)attrs[0]).Title;
            }

            attrs = executingAssembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
            if (attrs.Length > 0)
            {
                copyrightText = ((AssemblyCopyrightAttribute)attrs[0]).Copyright;
            }

            attrs = executingAssembly.GetCustomAttributes(typeof(AssemblyConfigurationAttribute), false);
            if (attrs.Length > 0)
            {
                string configuration = (( AssemblyConfigurationAttribute )attrs[0]).Configuration;
                if (!String.IsNullOrEmpty(configuration))
                {
                    configText = string.Format("({0})", (( AssemblyConfigurationAttribute )attrs[0]).Configuration);
                }
            }

            ColorConsole.WriteLine(ColorStyle.Header, string.Format("{0} {1} {2}", programName, versionText, configText));
            ColorConsole.WriteLine(ColorStyle.SubHeader, copyrightText);
            Console.WriteLine();
            ColorConsole.WriteLine(ColorStyle.SectionHeader, "Runtime Environment");
            ColorConsole.WriteLabel("   OS Version: ", Environment.OSVersion.ToString(), true);
            ColorConsole.WriteLabel("  CLR Version: ", Environment.Version.ToString(), true);
            Console.WriteLine();
        }
Beispiel #3
0
        /// <summary>
        /// Reports the results to the console
        /// </summary>
        public void ReportResults()
        {
            if (options.StopOnError && summary.ErrorsAndFailures > 0)
            {
                ColorConsole.WriteLine(ColorStyle.Failure, "Execution terminated after first error");
                Console.WriteLine();
            }

            WriteSummaryReport();

            WriteAssemblyErrorsAndWarnings();

            if (testRunResult == "Failed")
            {
                WriteErrorsAndFailuresReport();
            }

            if (summary.TestsNotRun > 0)
            {
                WriteNotRunReport();
            }
        }
Beispiel #4
0
        private void WriteSummaryReport()
        {
            ColorStyle overall = testRunResult == "Passed"
                ? ColorStyle.Pass
                : (testRunResult == "Failed" ? ColorStyle.Failure : ColorStyle.Warning);

            Console.WriteLine();
            ColorConsole.WriteLine(ColorStyle.SectionHeader, "Test Run Summary -");
            ColorConsole.Write(ColorStyle.Label, "   Overall result: ");
            ColorConsole.WriteLine(overall, testRunResult);
            ColorConsole.WriteLine(ColorStyle.Default, String.Format(
                                       "   Tests run: {0}, Errors: {1}, Failures: {2}, Inconclusive: {3}",
                                       summary.TestsRun, summary.Errors, summary.Failures, summary.Inconclusive));
            ColorConsole.WriteLine(ColorStyle.Warning, string.Format(
                                       "     Not run: {0}, Invalid: {1}, Ignored: {2}, Skipped: {3}",
                                       summary.TestsNotRun, summary.NotRunnable, summary.Ignored, summary.Skipped));
            ColorConsole.WriteLine(ColorStyle.Default,
                                   "  Start time: " + summary.StartTime.ToString("u"));
            ColorConsole.WriteLine(ColorStyle.Default,
                                   "    End time: " + summary.EndTime.ToString("u"));
            ColorConsole.WriteLine(ColorStyle.Default, string.Format(
                                       "    Duration: {0} seconds", summary.Duration.ToString("0.000")));
            Console.WriteLine();
        }
Beispiel #5
0
        public static int Main(string[] args)
        {
            ConsoleOptions options = new ConsoleOptions();

            try
            {
                options.Parse(args);
            }
            catch (OptionException ex)
            {
                WriteHeader();
                Console.WriteLine(ex.Message, ex.OptionName);
                return(ConsoleRunner.INVALID_ARG);
            }

            ColorConsole.Options = options;

            // Create SettingsService early so we know the trace level right at the start
            //SettingsService settingsService = new SettingsService();
            //InternalTraceLevel level = (InternalTraceLevel)settingsService.GetSetting("Options.InternalTraceLevel", InternalTraceLevel.Default);
            //if (options.trace != InternalTraceLevel.Default)
            //    level = options.trace;

            //InternalTrace.Initialize("nunit-console_%p.log", level);

            //log.Info("NUnit-console.exe starting");
            try
            {
                if (options.PauseBeforeRun)
                {
                    ColorConsole.WriteLine(ColorStyle.Warning, "Press any key to continue . . .");
                    Console.ReadKey(true);
                }

                if (!options.NoHeader)
                {
                    WriteHeader();
                }

                if (options.ShowHelp)
                {
                    WriteHelpText(options);
                    return(ConsoleRunner.OK);
                }

                if (!options.Validate())
                {
                    using (new ColorConsole(ColorStyle.Error))
                    {
                        foreach (string message in options.ErrorMessages)
                        {
                            Console.Error.WriteLine(message);
                        }
                    }

                    return(ConsoleRunner.INVALID_ARG);
                }

                if (options.InputFiles.Count == 0)
                {
                    using (new ColorConsole(ColorStyle.Error))
                        Console.Error.WriteLine("Error: no inputs specified");
                    return(ConsoleRunner.OK);
                }

                // TODO: Move this to engine
                foreach (string file in options.InputFiles)
                {
                    //if (!Services.ProjectService.CanLoadProject(file) && !PathUtils.IsAssemblyFileType(file))
                    string ext = Path.GetExtension(file);
                    if (ext != ".dll" && ext != ".exe" && ext != ".nunit")
                    {
                        ColorConsole.WriteLine(ColorStyle.Warning, "File type not known: " + file);
                        return(ConsoleRunner.INVALID_ARG);
                    }
                }

                string workDirectory = options.WorkDirectory ?? Environment.CurrentDirectory;
                var    traceLevel    = options.InternalTraceLevel != null
                    ? (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), options.InternalTraceLevel)
                    : InternalTraceLevel.Off;

                using (ITestEngine engine = TestEngineActivator.CreateInstance(workDirectory, traceLevel))
                {
                    try
                    {
                        return(new ConsoleRunner(engine, options).Execute());
                    }
                    catch (NUnitEngineException ex)
                    {
                        ColorConsole.WriteLine(ColorStyle.Error, ex.Message);
                        return(ConsoleRunner.INVALID_ARG);
                    }
                    catch (FileNotFoundException ex)
                    {
                        ColorConsole.WriteLine(ColorStyle.Error, ex.Message);
#if DEBUG
                        ColorConsole.WriteLine(ColorStyle.Error, ex.StackTrace);
#endif
                        return(ConsoleRunner.FILE_NOT_FOUND);
                    }
                    catch (DirectoryNotFoundException ex)
                    {
                        ColorConsole.WriteLine(ColorStyle.Error, ex.Message);
                        return(ConsoleRunner.FILE_NOT_FOUND);
                    }
                    catch (Exception ex)
                    {
                        ColorConsole.WriteLine(ColorStyle.Error, ex.Message);
                        return(ConsoleRunner.UNEXPECTED_ERROR);
                    }
                    finally
                    {
                        if (options.WaitBeforeExit)
                        {
                            using (new ColorConsole(ColorStyle.Warning))
                            {
                                Console.Out.WriteLine("\nPress any key to continue . . .");
                                Console.ReadKey(true);
                            }
                        }

                        //    log.Info( "NUnit-console.exe terminating" );
                    }
                }
            }
            finally
            {
                Console.ResetColor();
            }
        }
Beispiel #6
0
 private void WriteAssemblyMessage(ColorStyle style, string message)
 {
     ColorConsole.WriteLine(style, message);
     Console.WriteLine();
 }