public static int Main(string[] args) { ConsoleOptions options = new ConsoleOptions(); try { options.Parse(args); } catch (OptionException ex) { WriteHeader(); ColorConsole.WriteLine(ColorStyle.Error, string.Format(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(); } }
private void WriteAssemblyMessage(ColorStyle style, string message) { ColorConsole.WriteLine(style, message); Console.WriteLine(); }