/// <summary> /// Writes the runtime environment. /// </summary> /// <param name="writer">The writer.</param> public static void WriteRuntimeEnvironment(ExtendedTextWriter writer) { writer.WriteLine(ColorStyle.SectionHeader, "Runtime Environment -"); writer.WriteLabelLine(" OS Version: ", Environment.OSVersion); writer.WriteLabelLine(" CLR Version: ", Environment.Version); writer.WriteLine(); }
/// <summary> /// Writes the header. /// </summary> /// <param name="writer">The writer.</param> public static void WriteHeader(ExtendedTextWriter writer) { Assembly executingAssembly = Assembly.GetExecutingAssembly(); AssemblyName assemblyName = AssemblyHelper.GetAssemblyName(executingAssembly); Version version = assemblyName.Version; string copyright = "Copyright (C) 2012, Charlie Poole"; string build = ""; object[] attrs = executingAssembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); if (attrs.Length > 0) { var copyrightAttr = (AssemblyCopyrightAttribute)attrs[0]; copyright = copyrightAttr.Copyright; } attrs = executingAssembly.GetCustomAttributes(typeof(AssemblyConfigurationAttribute), false); if (attrs.Length > 0) { var configAttr = (AssemblyConfigurationAttribute)attrs[0]; build = string.Format("({0})", configAttr.Configuration); } writer.WriteLine(ColorStyle.Header, String.Format("NUnitLite {0} {1}", version.ToString(3), build)); writer.WriteLine(ColorStyle.SubHeader, copyright); writer.WriteLine(); }
public void DisplayRequestedOptions() { WriteSectionHeader("Options"); if (_options.DefaultTimeout >= 0) { WriteLabelLine(" Default timeout: ", _options.DefaultTimeout); } WriteLabelLine(" Work Directory: ", _options.WorkDirectory ?? NUnit.Env.DefaultWorkDirectory); WriteLabelLine(" Internal Trace: ", _options.InternalTraceLevel ?? "Off"); if (_options.TeamCity) { _outWriter.WriteLine(ColorStyle.Value, " Display TeamCity Service Messages"); } SkipLine(); if (_options.TestList.Count > 0) { WriteSectionHeader("Selected test(s) -"); foreach (string testName in _options.TestList) { _outWriter.WriteLine(ColorStyle.Value, " " + testName); } SkipLine(); } if (!string.IsNullOrEmpty(_options.Include)) { WriteLabelLine("Included categories: ", _options.Include); SkipLine(); } if (!string.IsNullOrEmpty(_options.Exclude)) { WriteLabelLine("Excluded categories: ", _options.Exclude); SkipLine(); } }
private void DisplayRequestedOptions(ExtendedTextWriter writer) { writer.WriteLine(ColorStyle.SectionHeader, "Options -"); if (_options.DefaultTimeout >= 0) { writer.WriteLabelLine(" Default timeout: ", _options.DefaultTimeout); } writer.WriteLabelLine(" Work Directory: ", _workDirectory); writer.WriteLabelLine(" Internal Trace: ", _options.InternalTraceLevel ?? "Off"); if (_options.TeamCity) { writer.WriteLine(ColorStyle.Value, " Display TeamCity Service Messages"); } writer.WriteLine(); if (_options.TestList.Count > 0) { writer.WriteLine(ColorStyle.SectionHeader, "Selected test(s) -"); foreach (string testName in _options.TestList) { writer.WriteLine(ColorStyle.Value, " " + testName); } writer.WriteLine(); } if (!string.IsNullOrEmpty(_options.Include)) { writer.WriteLabelLine("Included categories: ", _options.Include); writer.WriteLine(); } if (!string.IsNullOrEmpty(_options.Exclude)) { writer.WriteLabelLine("Excluded categories: ", _options.Exclude); writer.WriteLine(); } }
/// <summary> /// Execute a test run based on the aruments passed /// from Main. /// </summary> /// <param name="args">An array of arguments</param> public int Execute(string[] args) { // NOTE: Execute must be directly called from the // test assembly in order for the mechanism to work. _options = new ConsoleOptions(args); _workDirectory = _options.WorkDirectory; if (_workDirectory == null) { _workDirectory = NUnit.Env.DefaultWorkDirectory; } else if (!Directory.Exists(_workDirectory)) { Directory.CreateDirectory(_workDirectory); } #if !SILVERLIGHT #if !NETCF if (_options.TeamCity) { _teamCity = new TeamCityEventListener(); } #endif if (_options.OutFile != null) { _outWriter = new ExtendedTextWriter(new StreamWriter(Path.Combine(_workDirectory, _options.OutFile))); Console.SetOut(_outWriter); ColorConsole.Enabled = false; } if (_options.ErrFile != null) { _errWriter = new StreamWriter(Path.Combine(_workDirectory, _options.ErrFile)); Console.SetError(_errWriter); } #endif if (_options.NoColor) { ColorConsole.Enabled = false; } if (!_options.NoHeader) { WriteHeader(_outWriter); } if (_options.ShowHelp) { WriteHelpText(); return(OK); } if (_options.ErrorMessages.Count > 0) { foreach (string line in _options.ErrorMessages) { _outWriter.WriteLine(line); } _options.WriteOptionDescriptions(_outWriter); return(INVALID_ARG); } Assembly callingAssembly = Assembly.GetCallingAssembly(); // We must call this before creating the runner so that any internal logging is initialized var level = (InternalTraceLevel)Enum.Parse(typeof(InternalTraceLevel), _options.InternalTraceLevel ?? "Off", true); #if NETCF // NETCF: Try to unify InitializeInternalTrace(callingAssembly.GetName().CodeBase, level); #else InitializeInternalTrace(callingAssembly.Location, level); #endif _runner = new NUnitTestAssemblyRunner(new DefaultTestAssemblyBuilder()); _outWriter.WriteLine(ColorStyle.SectionHeader, "Test Files:"); DisplayRequestedOptions(_outWriter); WriteRuntimeEnvironment(_outWriter); if (_options.WaitBeforeExit && _options.OutFile != null) { _outWriter.WriteLine("Ignoring /wait option - only valid for Console"); } var runSettings = MakeRunSettings(_options); TestFilter filter = CreateTestFilter(_options); try { foreach (string name in _options.InputFiles) #if NETCF { _assemblies.Add(name.IndexOf(',') != -1 || (name.IndexOf('\\') == -1 && !Path.HasExtension(name)) ? Assembly.Load(name) : Assembly.LoadFrom(name)); } #else { _assemblies.Add(Assembly.Load(name)); } #endif if (_assemblies.Count == 0) { _assemblies.Add(callingAssembly); } // TODO: For now, ignore all but first assembly Assembly assembly = _assemblies[0]; // Randomizer.InitialSeed = _commandLineOptions.InitialSeed; if (_runner.Load(assembly, runSettings) != null) { return(_options.Explore ? ExploreTests() : RunTests(filter)); } var assemblyName = AssemblyHelper.GetAssemblyName(assembly); Console.WriteLine("No tests found in assembly {0}", assemblyName.Name); return(OK); } catch (FileNotFoundException ex) { _outWriter.WriteLine(ColorStyle.Error, ex.Message); return(FILE_NOT_FOUND); } catch (Exception ex) { _outWriter.WriteLine(ColorStyle.Error, ex.ToString()); return(UNEXPECTED_ERROR); } finally { if (_options.OutFile == null) { if (_options.WaitBeforeExit) { _outWriter.WriteLine(ColorStyle.Label, "Press Enter key to continue . . ."); Console.ReadLine(); } } else { _outWriter.Close(); } if (_options.ErrFile != null) { _errWriter.Close(); } } }
/// <summary> /// Produces the standard output reports. /// </summary> public void ReportResults() { if (Summary.TestCount == 0) { _writer.WriteLine(ColorStyle.Warning, "Warning: No tests found"); } _writer.WriteLine(); WriteSummaryReport(); if (_result.ResultState.Status == TestStatus.Failed) { WriteErrorsAndFailuresReport(); } if (Summary.SkipCount + Summary.IgnoreCount > 0) { WriteNotRunReport(); } #if FULL if (commandLineOptions.Full) { PrintFullReport(result); } #endif }
/// <summary> /// Produces the standard output reports. /// </summary> public void ReportResults() { if (summary.TestCount == 0) { _writer.WriteLine(ColorStyle.Warning, "Warning: No tests found"); } PrintSummaryReport(); if (this.result.ResultState.Status == TestStatus.Failed) { //if (summary.FailureCount > 0 || summary.ErrorCount > 0) PrintErrorReport(); } if (summary.NotRunCount > 0) { PrintNotRunReport(); } //if (commandLineOptions.Full) // PrintFullReport(result); }